Docsity

Laboratory Exercise 4, Cheat Sheet of Digital Signal Processing

Toggle sidebar
bg1
1
Name: SOLUTION (Havlicek)
Section:
Laboratory Exercise 4
LINEAR, TIME-INVARIANT DISCRETE-TIME SYSTEMS:
FREQUENCY-DOMAIN REPRESENTATIONS
4.1 TRANSFER FUNCTION AND FREQUENCY RESPONSE
Project 4.1 Transfer Function Analysis
Answers:
Q4.1 The modified Program P3_1 to compute and plot the magnitude and phase spectra of a moving
average filter of Eq. (2.13) for 0 2 is shown below:
% Program Q4_1
% Frequency response of the causal M-point averager of Eq. (2.13)
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');
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25

Partial preview of the text

Download Laboratory Exercise 4 and more Cheat Sheet Digital Signal Processing in PDF only on Docsity!

Name: SOLUTION (Havlicek)

Section:

Laboratory Exercise 4

LINEAR, TIME-INVARIANT DISCRETE-TIME SYSTEMS: FREQUENCY-DOMAIN REPRESENTATIONS

4.1 TRANSFER FUNCTION AND FREQUENCY RESPONSE

Project 4.1 Transfer Function Analysis

Answers:

Q4.1 The modified Program P3_1 to compute and plot the magnitude and phase spectra of a moving

average filter of Eq. (2.13) for 0    2  is shown below:

% Program Q4_

% Frequency response of the causal M-point averager of Eq. (2.13)

clear;

% User specifies filter length

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

% Compute the frequency samples of the DTFT

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

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');

This program was run for the following three different values of M and the plots of the corresponding

frequency responses are shown below:

M=

1 Magnitude Spectrum |H(e

j)|

Amplitude

Phase Spectrum arg[H(ej)]

Phase in radians

M=

1 Magnitude Spectrum |H(e

j)|

Amplitude

4 Phase Spectrum arg[H(e

j)]

Phase in radians

Q4.2 The plot of the frequency response of the causal LTI discrete-time system of Question Q4.

obtained using the modified program is given below:

1 Magnitude Spectrum |H(e

j)|

Amplitude

Phase Spectrum arg[H(ej)]

Phase in radians

The type of filter represented by this transfer function is - Bandpass

Q4.3 The plot of the frequency response of the causal LTI discrete-time system of Question Q4.

obtained using the modified program is given below:

1 Magnitude Spectrum |H(e

j)|

Amplitude

4 Phase Spectrum arg[H(e

j)]

Phase in radians

The type of filter represented by this transfer function is - Bandpass

The difference between the two filters of Questions 4.2 and 4.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 Question Q4.36_ for the following reason - It can be both causal

and BIBO stable, whereas the filter of Q4.37 cannot be both because the two poles are

both outside of the unit circle.

Q4.4 The group delay of the filter specified in Question Q4.4 and obtained using the function

grpdelay is shown below:

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.

Q4.5 The plots of the first 100 samples of the impulse responses of the two filters of Questions 4.

and 4.3 obtained using the program developed in Question Q3.50 are shown below:

Real Part

Imaginary Part

Real Part

Imaginary Part

From these plots we make the following observations: As we have said repeatedly by this

time, the upper figure shows that the filter in (4.36) has poles inside the unit circle and

therefore it’s causal realization is stable. The lower figure shows that the filter in

(4.37) has poles outside the unit circle; its causal realization is unstable.

4.2 TYPES OF TRANSFER FUNCTIONS

Project 4.2 Filters

A copy of Program P4_1 is given below:

% Program P4_

% Impulse Response of Truncated Ideal Lowpass Filter

clf;

fc = 0.25;

n = [-6.5:1:6.5];

y = 2fcsinc(2fcn);k = n+6.5;

stem(k,y);title('N = 13');axis([0 13 -0.2 0.6]);

xlabel('Time index n');ylabel('Amplitude');grid;

Answers:

Q4.7 The plot of the impulse response of the approximation to the ideal lowpass filter obtained using

Program P4_1 is shown below:

N = 13

Time index n

Amplitude

The length of the FIR lowpass filter is - 14

The statement in Program P4_1 determining the filter length is -

n = [-6.5:1:6.5];

The parameter controlling the cutoff frequency is - fc = 0.25;

Q4.8 The required modifications to Program P4_1 to compute and plot the impulse response of the

FIR lowpass filter of Project 4.2 with a length of 20 and a cutoff frequency of c = 0.45 are

as indicated below:

% Program Q4_

% Impulse Response of Truncated Ideal Lowpass Filter

clf;

1.4 N = 14

Time index n

Amplitude

Q4.10 The MATLAB program to compute and plot the amplitude response of the FIR lowpass filter of

Project 4.2 is given below:

% Program Q4_

% 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 = 2fcsinc(2fcn);

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');

Plots of the amplitude response of the lowpass filter for several values of N are shown below:

1.4 |H(e

j)|, N=

Amplitude

1.4 |H(e

j)|, N=

Amplitude

A copy of Program P4_2 is given below:

% Program P4_

% 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)])

Answers:

Q4.11 A plot of the gain response of a length-2 moving average filter obtained using Program P4_2 is

shown below:

Gain in dB

M = 2

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

Q4.12 The required modifications to Program P4_2 to compute and plot the gain response of a

cascade of K length-2 moving average filters are given below:

% Program Q4_

% 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 = 2acos((0.5)^(1/(2K)))*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))]);

The plot of the gain response for a cascade of 3 sections obtained using the modified program

is shown below:

Gain in dB

K = 3; Theoretical c = 0.

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

Q4.13 The required modifications to Program P4_2 to compute and plot the gain response of the

highpass filter of Eq. (4.42) are given below:

Gain in dB

Lowpass; c = 0.45

Gain in dB

Highpass; c = 0.45

From these plots we observe that the designed filters DO_ meet the specifications.

A plot of the magnitude response of the sum HLP (z) + HHP (z) obtained using MATLAB is

given below:

Amplitude

|HLP(z) + HHP(z)|

From this plot we observe that the two filters are – Allpass Complementary

A plot of the sum of the square-magnitude responses of HLP (z) and HHP (z) obtained using

MATLAB is given below:

Amplitude

|HLP(z)|^2 + |HHP(z)|^2

From this plot we observe that the two filters are – Power Complementary

Q4.15 From Eq. (4.24), we get substituting K = 10, B = 1.

Gain in dB

HLP,1(z); c = 0.3

From these plots we make the following observation – The series connection of 10 1 st^ order

IIR lowpass sections achieves a sharper transition band than the single first order filter

designed for the same 3 dB cutoff frequency.

Q4.16 Substituting o = 0.61 in Eq. (4.19) we get   cos(0.61)  -0.

Substituting 3dB = 0.15 in Eq. (4.20) we get (1  ^2 )cos(0.15)  2   0, whose

solution yields  = 1.6319 and  = 0.6128..

Substituting the value of  and the first value of  in Eq. (4.18) we arrive at the transfer

function of the IIR bandpass transfer function

HBP,1 (z) =

z

z z

Substituting the value of  and the second value of  in Eq. (4.18) we arrive at the transfer

function of the IIR bandpass transfer function

HBP,2 (z) =

z

z z

Next using the zplane command we find the pole locations of HBP,1 (z) and HBP,2 (z) from

which we conclude that the stable transfer function HBP (z) is given by – HBP,2 (z).

P-Z plot for HBP,1 (z)

Real Part

Imaginary Part

P-Z plot for HBP,2 (z)

Real Part

Imaginary Part