% ----------------------------------------------------------------------------
% Example output from hpeq.m
%
% Elliptic highpass shelving filter, 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 = 5; fs = 40; f0 = fs/2; 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

[w1,w2] = bandedge(w0,Dw); f1 = fs * w1/2/pi; f2 = fs * w2/2/pi;

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

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

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, HP Shelf, {\it N} = 5');
xlabel('{\it f}  (kHz)'); ylabel('dB');
grid;
B =

    2.6134    1.5356         0         0         0
    0.7748    1.3358    0.6916         0         0
    0.5888    0.8448    0.3542         0         0


A =

    1.0000    0.7293         0         0         0
    1.0000    1.7741    0.9046         0         0
    1.0000    1.5845    0.6828         0         0


Bh =

    2.6134   -1.5356         0
    0.7748   -1.3358    0.6916
    0.5888   -0.8448    0.3542


Ah =

    1.0000   -0.7293         0
    1.0000   -1.7741    0.9046
    1.0000   -1.5845    0.6828