IIR DESIGN
IIR DESIGN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Input Signal
% input signal generation
n = 0:1:100;
1
% plot magnitude response
figure(2);
w_k = (-128:128-1) * (2*pi/256);
subplot(1,1,1);
plot(w_k/pi, X_dft_mag, '-r','LineWidth',2);
grid on,
xlabel('frequency in pi units');
ylabel('Magnitude')
title('Magnitude Response of the Input Signal');
2
LowPass Digital IIR Filter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% In this task, we wish to pass only the first frequency w1 through
the
% filter and block rest of the two frequencies using a Lowpass
Digital IIR Filter.
%
% LOW PASS FILTER DESIGN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Chose Ts
Ts = 2; % sec
3
Omega_s = (2/Ts)*tan(w_s/2); % pre_warp stop band edge frequency
% find magnitude
Y_dft_mag = abs(fftshift(y_dft));
4
title('Magnitude Response of the Filtered Signal');
5
6
High Digital IIR Filter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% In this task, we wish to pass only the last frequency w3 through
the
% filter and block rest of the two frequencies w1 and w2 using a
Highpass Digital IIR Filter.
%
%
% HIGH PASS FILTER
DESIGN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Chose Ts
Ts = 2; % sec
7
plot (w/pi,20*log10(abs(H_HP)),'-b','linewidth',2);
axis([0 1 -80 5]);
grid on;
xlabel('frequency(Hz)'); ylabel('Gain, dB');
title('IIR Butterworth HighPass Filter');
subplot(2,1,2);
plot (w/pi, angle(H_HP)/pi,'-r','linewidth',2);
axis([0 1 -1.25 1.25]);
grid on;
xlabel('frequency(Hz)');
ylabel('Normalized phase (wrt pi)');
title('IIR Butterworth HighPass Filter');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% filer x[n] using the designed filter
yn = filter(bz_HP, az_HP, xn);
% find magnitude
Y_dft_mag = abs(fftshift(y_dft));
8
9
BandPass Digital IIR Filter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% In this task, we wish to pass only the middle frequency w2 through
the
% filter and block rest of the two frequencies w1 and w3 using a
Bandpass Digital IIR Filter.
%
%
% BAND PASS FILTER
DESIGN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
% Chose Ts
Ts = 2; % sec
if (Omega_s1_BP*Omega_s2_BP ~= Omega_p1_BP*Omega_p2_BP)
11
xlabel('frequency(Hz)'); ylabel('Gain, dB');
title('IIR Butterworth BandPass Filter');
subplot(2,1,2);
plot (w/pi, angle(H_BP)/pi,'-r','linewidth',2);
axis([0 1 -1.25 1.25]);
grid on;
xlabel('frequency(Hz)');
ylabel('Normalized phase (wrt pi)');
title('IIR Butterworth BandPass Filter');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% filter x[n] using the designed filter
yn = filter(bz_BP, az_BP, xn);
% find magnitude
Y_dft_mag = abs(fftshift(y_dft));
12
13
BandStop Digital IIR Filter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% In this task, we wish to block only the middle frequency w2
through the
% filter and pass rest of the two frequencies w1 and w3 using a
Bandstop Digital IIR Filter.
%
%
% BAND STOP DIGITAL IIR
FILTER DESIGN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
% Chose Ts
Ts = 2 ; % sec
if (Omega_s1_BS*Omega_s2_BS ~= Omega_p1_BS*Omega_p2_BS)
15
xlabel('frequency(Hz)'); ylabel('Gain, dB');
title('IIR Butterworth BandStop Filter');
subplot(2,1,2);
plot (w/pi, angle(H_BS)/pi,'linewidth',2);
axis([0 1 -1.25 1.25]);
grid on;
xlabel('frequency(Hz)');
ylabel('Normalized phase (wrt pi)');
title('IIR Butterworth BandStop Filter');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% filer x[n] using the designed filter
yn = filter(bz_BS, az_BS, xn);
% find magnitude
Y_dft_mag = abs(fftshift(y_dft));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
17
Published with MATLAB® R2021a
18