% ----------------------------------------------------------------------------
% Example output from hpeq.m
%
% Elliptic equalizer - boost
% ----------------------------------------------------------------------------
% Sophocles J. Orfanidis
% ECE Department, Rutgers University
% 94 Brett Road, Piscataway, NJ 08854-8058
%
% Email:   orfanidi@ece.rutgers.edu
% Date:    June 15, 2005
%
% Reference: Sophocles J. Orfanidis, "High-Order Digital Parametric Equalizer
%            Design," J. Audio Eng. Soc., vol.53, pp. 1026-1046, November 2005.
%
% Web Page: http://www.ece.rutgers.edu/~orfanidi/hpeq
%
% tested with MATLAB R11.1 and R14
% ----------------------------------------------------------------------------

clear all;

N = 4; fs = 40; f0 = 5; Df = 2; w0 = 2*pi*f0/fs; Dw = 2*pi*Df/fs;
G0 = 0; G = 12; GB = 11.99; type = 3; Gs = 0.01; tol=eps;

[B,A,Bh,Ah] = hpeq(N, G0, G, GB, w0, Dw, type, Gs, tol)

f = linspace(0,20,1001); w = 2*pi*f/fs;

H = 20*log10(abs(fresp(B,A,w)));

% H = 20*log10(abs(fresp(Bh,Ah,w,w0)));  % alternative computation of frequency response

% calculate edge frequencies at level GB
[w1,w2] = bandedge(w0,Dw); f1 = fs * w1/2/pi; f2 = fs * w2/2/pi;

% calculate 3-dB width and 3-dB edge frequencies
Gb = G-3;
Dwb = bandwidth(N, G0, G, GB, Gb, Dw, type, Gs);
[w1b,w2b] = bandedge(w0,Dwb); f1b = fs * w1b/2/pi; f2b = fs * w2b/2/pi;

% calculate width and edge frequencies at stopband level Gs
Dws = bandwidth(N, G0, G, GB, Gs, Dw, type, Gs);
[w1s,w2s] = bandedge(w0,Dws); f1s = fs * w1s/2/pi; f2s = fs * w2s/2/pi;

figure;
plot(f,H,'r-', [f1,f2,f1b,f2b,f1s,f2s], [GB,GB,Gb,Gb,Gs,Gs], 'b.');
ylim([-8 14]); ytick(-6:3:12);
xlim([0,20]); xtick(0:2:20);
title('Elliptic, boost, {\it N} = 4');
xlabel('{\it f}  (kHz)'); ylabel('dB');
grid;
B =

    3.9765         0         0         0         0
    0.6530   -1.6319    2.0848   -1.4311    0.5110
    0.4760   -1.0537    1.1314   -0.6243    0.1724


A =

    1.0000         0         0         0         0
    1.0000   -2.5865    3.3969   -2.3320    0.8200
    1.0000   -2.4129    2.8797   -1.7376    0.5225


Bh =

    3.9765         0         0
    0.6530   -1.0019    0.5110
    0.4760   -0.5381    0.1724


Ah =

    1.0000         0         0
    1.0000   -1.6579    0.8200
    1.0000   -1.4123    0.5225