% Example of IIR filter design by impulse-invariant method.
% Example 7.4 on page 385 of Ifeachor and Jervis text.
% Rich Kozick, Spring 1997

a=2*pi*150;	% Desired analog cutoff frequency, in rad/sec
Fs = 1.28e3;	% Sampling frequency
f = linspace(0, Fs/2, 201);	% Frequencies for plots, in Hz
w = 2*pi*f;

% Get analog filter frequency response
[Ha, Wa] = freqs(a*a, [1, sqrt(2)*a, a*a], w);
HadB = 20*log10(abs(Ha));

% Get digital filter frequency response
Hd = freqz([0, 393.9264]/Fs, [1, -1.0308, 0.3530], f, Fs);
HddB = 20*log10(abs(Hd));

% Plot analog and digital responses on same axis for comparison
figure(1)
plot(f, HadB, '-', f, HddB, '--')
legend('Analog Filter', 'Digital Filter')
xlabel('Frequency (Hz)')
ylabel('dB')
title('Magnitude response, impulse-invariant method')
axis([0 Fs/2 -25 0])
