0% found this document useful (0 votes)
40 views19 pages

Lab No2

This document discusses analyzing the frequency response of linear time-invariant systems using MATLAB. It includes 9 questions: 1) Plotting the magnitude and phase spectra of moving average filters with different lengths. 2) Computing the frequency response of a bandpass filter. 3) Comparing two similar bandpass filters and determining which is more suitable. 4) Plotting the group delay of another filter. 5) Plotting the impulse responses of the two filters from question 3. 6) Developing pole-zero plots of the two filters to analyze stability. 7) Computing the impulse response of an FIR lowpass filter approximation. 8) Modifying the lowpass filter to have a longer

Uploaded by

Ali Mohsin
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)
40 views19 pages

Lab No2

This document discusses analyzing the frequency response of linear time-invariant systems using MATLAB. It includes 9 questions: 1) Plotting the magnitude and phase spectra of moving average filters with different lengths. 2) Computing the frequency response of a bandpass filter. 3) Comparing two similar bandpass filters and determining which is more suitable. 4) Plotting the group delay of another filter. 5) Plotting the impulse responses of the two filters from question 3. 6) Developing pole-zero plots of the two filters to analyze stability. 7) Computing the impulse response of an FIR lowpass filter approximation. 8) Modifying the lowpass filter to have a longer

Uploaded by

Ali Mohsin
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/ 19

Lab No: 8

Transform Analysis of Linear Time-Invariant Systems


Lab Tasks:
Q8.1:
Compute and plot the magnitude and phase spectra of a moving average filter for three different
values of length M and for 0 ≤ ω ≤ 2π. Justify the type of symmetries exhibited by the magnitude
and phase spectra. What type of filter does it represent?

Code:
% Program P8_1

% Frequency response of the causal M-point averager clear;

% User specifies filter length

M = input('Enter the filter length M: ');

% Compute the frequency samples of the DTFT

w = 0:2*pi/1023:2*pi;

num = (1/M)*ones(1,M);

den = [1];

% Compute and plot the DTFT

h = freqz(num, den, w);

subplot(2,1,1)

plot(w/pi,abs(h));

grid

title('Magnitude Spectrum |H(e^{j\omega})|')

xlabel('\omega /\pi');

ylabel('Amplitude');

subplot(2,1,2)

plot(w/pi,angle(h));

grid
title('Phase Spectrum arg[H(e^{j\omega})]')

xlabel('\omega /\pi');

ylabel('Phase in radians');

Graph:

For M=3

For M=7:

For M=10:
The types of symmetries exhibited by the magnitude and phase spectra are due to - The impulse
response is real. Therefore, the frequency response is periodically conjugate symmetric, the
magnitude response is periodically even symmetric, and the phase response is periodically odd
symmetric. The type of filter represented by the moving average filter is – This is a lowpass filter.
The results of Question Q10.1 can now be explained as follows – It is a lowpass filter. The input
was a sum of two sinusoids, one high frequency and one low frequency. The particular results
depend on the filter length M, but the general result is that the higher frequency sinusoidal
input component is attenuated more than the lower frequency sinusoidal input component.

Q8.2:
Using the Program P8_1 compute and plot the frequency response of a causal LTI discrete-time
system with a transfer function given by

for 0 ≤ ω ≤ π. What type of filter does it represent?

Code:
% Program P8_2

% Frequency response of the causal M-point averager clear;

% User specifies filter length

M = input('Enter the filter length M: ');

% Compute the frequency samples of the DTFT

w = 0:pi/1023:pi;

num = [0.15 0 -0.15];

den = [1 -0.5 0.7];

% Compute and plot the DTFT

h = freqz(num, den, w);

subplot(2,1,1)

plot(w/pi,abs(h));
grid

title('Magnitude Spectrum |H(e^{j\omega})|')

xlabel('\omega /\pi');

ylabel('Amplitude');

subplot(2,1,2)

plot(w/pi,angle(h));

grid

title('Phase Spectrum arg[H(e^{j\omega})]')

xlabel('\omega /\pi');

ylabel('Phase in radians');

Graph: The type of filter represented by this transfer function is – Bandpass.

Q8.3:
Repeat Question Q8.2 for the following transfer function:

What is the difference between the two filters of Eqs. (10.36) and (10.37), respectively? Which
one will you choose for filtering and why?
Code:
% Program P8_3

% Frequency response of the causal M-point averager clear;

% User specifies filter length

M = input('Enter the filter length M: ');

% Compute the frequency samples of the DTFT

w = 0:pi/1023:pi;

num = [0.15 0 -0.15];

den = [0.7 -0.5 1];

% Compute and plot the DTFT

h = freqz(num, den, w);

subplot(2,1,1)

plot(w/pi,abs(h));

grid

title('Magnitude Spectrum |H(e^{j\omega})|')

xlabel('\omega /\pi');

ylabel('Amplitude');

subplot(2,1,2)

plot(w/pi,angle(h));

grid

title('Phase Spectrum arg[H(e^{j\omega})]')

xlabel('\omega /\pi');

ylabel('Phase in radians');

Graph:
The type of filter represented by this transfer function is - Bandpass. The difference between the
two filters of Questions 8.2 and 8.3 is - The magnitude responses are the same. The phase
responses might look very different to you at first, but they are actually similar. The phase
response of the second filter exhibits a branch cut of the arctangent function at normalized
frequency 0.4, which is right in the middle of the passband. However, the unwrapped phase
would not show this discontinuity. Both filters have an approximately linear phase in the
passband and their group delays are approximately the negatives of one another. However, the
two filters have different poles. The poles of the first filter are INSIDE the unit circle, whereas
those of the second filer are OUTSIDE the unit circle. Thus, in a causal implementation, the first
filter would be BIBO STABLE, whereas the second filter would be UNSTABLE. Therefore, in most
applications the second filter would be preferable. I shall choose the filter of Eq. 10.36 for the
following reason - It can be both causal and BIBO stable, whereas the filter of Eq. 10.37 cannot
be both because the two poles are both outside of the unit circle.

Q8.4:
Using MATLAB compute and plot the group delay of the causal LTI discrete-time system with a
transfer function given by

for 0 ≤ ω ≤ π.

Code:
% Program P10_4

w = 0:pi/1023:pi;

num = [0 1 -1.2 1];

den = [1 -1.3 1.04 -0.222];

% Compute and plot the DTFT

h = grpdelay (num, den, w);

plot(w/pi,abs(h));

grid

title('Group Delay of |H(e^{j\omega})|')

xlabel('\omega /\pi');

ylabel('Group Delay');
Graph:

From this plot we make the following observations: Usually, it is desirable for a filer to have an
approximately linear phase in the passband, which is the same thing as an approximately
constant group delay in the passband. This filter is notch filter; it is a bandstop filter with a narrow
stopband centered at a normalized frequency just below 0.3. From the graph above, we see that
the group delay is approximately constant over much of the passband.

Q8.5:
Using the program, compute and plot the first 100 samples of the impulse responses of the two
filters of Eqs. (8.36) and (8.37), respectively.
Comment on your results.

Code: (a)
% Program q8_5a

% Given numerator and denominator coefficient vectors for G(z),

% find and plot the first L samples of the impulse response, where

% the parameter L is input by the user.

clf;

% initialize

num = [0.15 0 -0.15];

den = [1 -0.5 0.7];

% Query user for parameter L

L = input('Enter the number of samples L: ');

% find impulse response

[g t] = impz(num,den,L);
%plot the impulse response

stem(t,g);

title(['First ',num2str(L),' samples of impulse response']);

xlabel('Time Index n');

ylabel('h[n]');

Graph:

Code: (b)
% Program Q8_5b

% Given numerator and denominator coefficient vectors for G(z),

% find and plot the first L samples of the impulse response, where

% the parameter L is input by the user.

clf;

% initialize

num = [0.15 0 -0.15];

den = [0.7 -0.5 1];

% Query user for parameter L

L = input('Enter the number of samples L: ');


% find impulse response

[g t] = impz(num,den,L);

%plot the impulse response

stem(t,g);

title(['First ',num2str(L),' samples of impulse response']);

xlabel('Time Index n');

Graph:

From these plots we make the following observations: These plots generated by impz give the
impulse response for a causal realization of H(z). As we observed in Q8.3, the causal filter with
H(z) given in (8.36) is BIBO stable, implying that h[n] is absolutely summable, and we see
alternation and exponential decay in the impulse response. On the other hand, the causal filer
with H(z) given in (8.37) has poles outside the unit circle and is unstable. Not surprisingly,
corresponding h[n] shown above displays exponential growth with n.

Q8.6:
Using zplane develop the pole-zero plots of the two filters of Eqs. (10.36) and (10.37), respectively.
Comment on your results.

Code: (a)
% Program Q8 _6a

%Compute the frequency samples of the DTFT


w=0:pi/1023:pi;

num=[0.15 0 -0.15];

den=[1 -0.5 0.7];

%Compute and plot the DTFT

h=zplane(num, den, w);

xlabel('Real Part');

ylabel('Imaginary Part');

Graph:

Code: (b)
% Program Q8_6b

%Compute the frequency samples of the DTFT

w=0:pi/1023:pi;

num=[0.15 0 -0.15];

den=[0.7 -0.5 1];

%Compute and plot the DTFT

h=zplane(num, den, w);

xlabel('Real Part');

ylabel('Imaginary Part');
Graph:

From these plots we make the following observations: As we have said repeatedly by this time,
the upper figure shows that the filter in (10.36) has poles inside the unit circle and therefore it’s
causal realization is stable. The lower figure shows that the filter in (10.37) has poles outside the
unit circle; its causal realization is unstable.

Q8.7:
Compute and plot the impulse response of the approximation to the ideal low-pass filter using
Program P8_2. What is the length of the FIR low-pass filter? Which statement in Program P8_2
determines the filter length? Which parameter controls the cutoff frequency?

Code:
% Program P8_7

% Impulse Response of Truncated Ideal Low-pass Filter clf;

fc = 0.25;

n = [-6.5:1:6.5];

y = 2*fc*sinc(2*fc*n);

k = n+6.5;

stem(k,y);

title('N = 13');

axis([0 13 -0.2 0.6]);


xlabel('Time index n');

ylabel('Amplitude');

grid

Graph:

The length of the FIR lowpass filter is - 14


The statement in Program P8_1 determining the filter length is - n = [-6.5:1:6.5];
The parameter controlling the cutoff frequency is - fc = 0.25;

Q8.8:
Modify Program P8_2 to compute and plot the impulse response of the FIR low-pass filter of Eq.
(8.39) with a length of 20 and an angular cutoff frequency of ωc = 0.45.

Code:
% Program P10_8

% Impulse Response of Truncated Ideal Lowpass Filter

clf;

fc = 0.45;
n = [-9.5:1:9.5];

y = 2*fc*sinc(2*fc*n);

k = n+9.5;

stem(k,y);

title('N = 19');

axis([0 19 -0.2 0.7]);

xlabel('Time index n');

ylabel('Amplitude');

grid;

Graph:

Q8.9:
Modify Program P8_2 to compute and plot the impulse response of the FIR low-pass filter of Eq.
(8.39) with a length of 15 and an angular cutoff frequency of ωc = 0.65.

Code:
% Program P8_9

% Impulse Response of Truncated Ideal Lowpass Filter


clf;

fc = 0.65;

n = [-7.0:1:7.0];

y = 2*fc*sinc(2*fc*n);

k = n+7.0;

stem(k,y);

title('N = 14');

axis([0 14 -0.4 1.4]);

xlabel('Time index n');

ylabel('Amplitude');

grid

Graph:

Q8.10:
Write a MATLAB program to compute and plot the amplitude response of the FIR low-pass filter
of Eq. (8.39). Using this program, plot the amplitude response for several values of N and
comment on your results.

Code:
% Program P8_10

% Compute and plot the amplitude response of Truncated Ideal Lowpass Filter
clear;

% Get "N" from the user command line

N = input('Enter the filter time shift N: ');

% compute the magnitude spectrum

No2 = N/2;

fc = 0.25;

n = [-No2:1:No2];

y = 2*fc*sinc(2*fc*n);

w = 0:pi/511:pi;

h = freqz(y, [1], w);

plot(w/pi,abs(h));

grid;

title(strcat('|H(e^{j\omega})|, N=',num2str(N)));

xlabel('\omega /\pi');

ylabel('Amplitude');

Graph:
From these plots we can make the following observations – As the filter length increases, the
transition from passband to stopband becomes steeper; i.e., the transition band becomes more
narrow. We also see the Gibb’s phenomena: as the filter order increases, the amplitude response
converges towards the ideal lowpass characteristic. However, the convergence is only in weak
sense – pointwise convergence. The peak ripple at the transition band edges does not decrease
despite the increases in order.

Q8.11:
Run Program P8_3 to compute and plot the gain response of a length-2 moving average filter.
From the plot verify that the 3-dB cutoff frequency is at π/2.

Code:
% Program P8_11

% Gain Response of a Moving Average Lowpass Filter

clf;

M = 2;

num = ones(1,M)/M;

[g,w] = gain(num,1);

plot(w/pi,g);grid

axis([0 1 -50 0.5])

xlabel('\omega /\pi');ylabel('Gain in dB');

title(['M = ', num2str(M)])

Graph:
From the plot it can be seen that the 3-dB cutoff frequency is at - /2 rad/sample.

Q8.12:
Modify Program P8_3 to compute and plot the gain response of a cascade of K length-2 moving-
average filters. Using the modified program plot the gain response for a cascade of 3 sections
and verify that the 3-dB cutoff frequency of the cascade is as given by Eq. (8.41).

Code:
% Program P8_12

% Gain Response of a cascade connection of K

% two-point Moving Average Lowpass Filters

clear;

K = input('Enter the number of sections K: ');

Hz = [1];

% find the numerator for H(z) = cascade of K sections

for i=1:K;

Hz = conv(Hz,[1 1]);

end;

Hz = (0.5)^K * Hz;

% Convert numerator to dB

[g,w] = gain(Hz,1);

% make a horizontal line on the plot at -3 dB

ThreedB = -3*ones(1,length(g));

% make a vertical line on the plot at the

% theoretical 3dB frequency

t1 = 2*acos((0.5)^(1/(2*K)))*ones(1,512)/pi;

t2 = -50:50.5/511:0.5;

plot(w/pi,g,w/pi,ThreedB,t1,t2);grid;

axis([0 1 -50 0.5])


xlabel('\omega /\pi');ylabel('Gain in dB');

title(['K = ',num2str(K),'; Theoretical \omega_{c} = ',num2str(t1(1))]);

Graph:

From the plot it can be seen that the 3-dB cutoff frequency of the cascade is at - 0.30015

Q8.13:
Modify Program P8_3 to compute and plot the gain response of the high-pass filter of Eq. (8.42).
Run the modified program to plot the gain response for M = 5 and determine its 3-dB cutoff
frequency from the plot.

Code:
% Program P8_13

% Gain Response of Highpass Filter

clear;

M = input('Enter the filter length M: ');

n = 0:M-1;

num = (-1).^n .* ones(1,M)/M;

[g,w] = gain(num,1);

plot(w/pi,g);grid;

axis([0 1 -50 0.5]);


xlabel('\omega /\pi');

ylabel('Gain in dB');

title(['M = ', num2str(M)]);

Graph:

From the plot we can see that the 3-dB cutoff frequency is at – approximately 0.8196

You might also like