% ----------------------------------------------------------------------------
% Example output from hpeq.m
%
% Elliptic lowpass filter
% ----------------------------------------------------------------------------
% 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;

fs=40; f2=4; f2s=4.5; w0=0; Dw=2*pi*f2/fs; Dws=2*pi*f2s/fs;
G0 = -Inf; G = 0; GB = -0.10; type = 3; Gs = -30; tol=eps;

Nexact = hpeqord(G0, G, GB, Gs, Dw, Dws, type),
N=ceil(Nexact)

[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 = abs(fresp(B,A,w)).^2;

Gb = -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-', [0,0,0,f2,f2b,f2s], 10.^([GB,Gb,Gs,GB,Gb,Gs]/10), 'b.');
ylim([0,1.05]); ytick(0:0.25:1);
xlim([0,20]); xtick(0:2:20);
title('Elliptic, Lowpass');
xlabel('{\it f}  (kHz)'); ylabel('magnitude squared')
grid;
Nexact =

    5.6418


N =

     6


B =

    0.9886         0         0         0         0
    0.8410   -1.2899    0.8410         0         0
    0.5252   -0.7263    0.5252         0         0
    0.0930   -0.0054    0.0930         0         0


A =

    1.0000         0         0         0         0
    1.0000   -1.5650    0.9570         0         0
    1.0000   -1.4683    0.7923         0         0
    1.0000   -1.2851    0.4656         0         0


Bh =

    0.9886         0         0
    0.8410   -1.2899    0.8410
    0.5252   -0.7263    0.5252
    0.0930   -0.0054    0.0930


Ah =

    1.0000         0         0
    1.0000   -1.5650    0.9570
    1.0000   -1.4683    0.7923
    1.0000   -1.2851    0.4656