0% found this document useful (0 votes)
34 views7 pages

Exp 1

This document describes an experiment using MATLAB to determine the frequency response of discrete linear time-invariant (LTI) systems, including finite impulse response (FIR) and infinite impulse response (IIR) filters. It provides the theory behind using freqz() to calculate frequency response, examples of FIR and IIR transfer functions, and MATLAB code that plots the magnitude and phase responses of sample FIR and IIR filters. The results and observations section describes the frequency and magnitude response plots obtained.

Uploaded by

abdo abdok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views7 pages

Exp 1

This document describes an experiment using MATLAB to determine the frequency response of discrete linear time-invariant (LTI) systems, including finite impulse response (FIR) and infinite impulse response (IIR) filters. It provides the theory behind using freqz() to calculate frequency response, examples of FIR and IIR transfer functions, and MATLAB code that plots the magnitude and phase responses of sample FIR and IIR filters. The results and observations section describes the frequency and magnitude response plots obtained.

Uploaded by

abdo abdok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Abdelrahman Abdelsalam

2k20/EC/04

Experiment-1

AIM : To determine frequency response of discrete LTI systems:


a) FIR .
b) IIR.

SOFTWARE IN USE : MATLAB.

THEORY:
[h,w] = freqz(b,a,w) returns the frequency response vector h and the corresponding angular
frequency vector w for the digital filter whose transfer function is determined by the (real or
complex) numerator and denumerator polynomials represented in the vectors b and a
respectively.

E.g for general FIR filter :

𝐻(𝑧) = 1 + 2𝑧 2 + 3𝑧 3

b=[1 2 3 2 1]
a=[1]
eg. For IIR filter

1
𝐻(𝑧) =
1 + 2𝑧 2 + 3𝑧 3

The vectors h and w are both of length 𝑙 , The angular frequency vector w has values ranging
between 0 to 𝜋 radians per sample . when you don’t specify the integer 𝑙 , or you specify it as the
empty vector [] , the frequency response is calculated using the default value of 512 samples .
Abdelrahman Abdelsalam
2k20/EC/04

freqz(b,a,…) plots the magnitude and unwrapped phase of the frequency response of the filter .
The plot is displayed in the current figure windows.

PROGRAM :
1. For FIR :
%FIR frequency response
pi = 3.14;
b = [1 2 3 4];
a = [1];
w = -pi : pi;
[h,w] = freqz(b,a,w);
freqz(b,a,w);
%FIR Magnitude response response
sf1 = 0.1;
pf1 = 0.35;
pf2 = 0.8;
sf2 = 0.9;
pb = linspace(pf1,pf2,1e3)*pi;

bp = designfilt('bandpassfir', ...
'StopbandAttenuation1',40, 'StopbandFrequency1',sf1,...
'PassbandFrequency1',pf1,'PassbandRipple',3,'PassbandFrequency2',pf2, ...
'StopbandFrequency2',sf2,'StopbandAttenuation2',30);

[h,w] = freqz(bp,1024);
hpb = freqz(bp,pb);
Abdelrahman Abdelsalam
2k20/EC/04

subplot(2,1,1)
plot(w/pi,abs(h),pb/pi,abs(hpb),'.-')
axis([0 1 -1 2])
legend('Response','Passband','Location','South')
ylabel('Magnitude')

subplot(2,1,2)
plot(w/pi,db(h),pb/pi,db(hpb),'.-')
axis([0 1 -60 10])
xlabel('Normalized Frequency (\times\pi rad/sample)')
ylabel('Magnitude (dB)')

2-For IIR :
%IIR frequency response
b=[1];
a=[1 2 2 2];
w=-pi:pi;
freqz(b,a,w);

%IIR magnitude response


b0 = 0.05634;
b1 = [1 1];
b2 = [1 -1.0166 1];
a1 = [1 -0.683];
a2 = [1 -1.4461 0.7957];

b = b0*conv(b1,b2);
a = conv(a1,a2);
Abdelrahman Abdelsalam
2k20/EC/04

[h,w] = freqz(b,a,'whole',2001);

plot(w/pi,20*log10(abs(h)))
ax = gca;
ax.YLim = [-100 20];
ax.XTick = 0:.5:2;
xlabel('Normalized Frequency (\times\pi rad/sample)')
ylabel('Magnitude (dB)')

RESULTS/OBSERAVTIONS:

For FIR FILTER:


Frequency response
Abdelrahman Abdelsalam
2k20/EC/04

Magnitude response
Abdelrahman Abdelsalam
2k20/EC/04

For IIR filter :

Frequency respons

Magnitude response in (dB)


Abdelrahman Abdelsalam
2k20/EC/04

CONCLUSION :
The frequency response of the FIR and IIR filters has been plotted successfully.

You might also like