Dsp-Lab-5 Soliution (Waheed 3797)
Dsp-Lab-5 Soliution (Waheed 3797)
Dsp-Lab-5 Soliution (Waheed 3797)
5
Discrete-Time Signals in the Frequency Domain -
DTFT
Objective:
Inthepreviouslabwestudiedvariouspropertiesofdiscretetimesignalsandsystems in the time
domain. Further insight into their properties can be obtained in the frequency domain
which we will study in this as well in next lab. This lab deals with
discretetimeFouriertransform(DTFT)computationanditsproperties.
Project5.1 DTFTComputation
TheDTFTX(ejω)ofasequencex[n]oftheformofEq.(5.1)canbecomputedeasilyat a prescribed
set of L discrete frequency points ω = ω₃ using the MATLAB function
freqz.SinceX(ejω)isacontinuousfunctionofω,itisnecessarytomakeLaslargeas possible so that
the plot generated using the command plot provides a reasonable
replicaoftheactualplotoftheDTFT.InMATLAB,freqzcomputestheL-pointDFTof thesequences
{p0p1...PM}and{d0d1...dM},andthenformstheirratiotoarriveatX(ejωl),l=1,
2,...,L.Forfastercomputation,Lshouldbechosenasapowerof2,suchas256or 512.
Program P5_1 can be used to evaluate and plot the DTFT of the form of Eq. (5.1).
% ProgramP5_1
AbasynUniversityIslamabadCampus|DigitalSignalProcessing–LabManual Page 1
% Evaluation of the DTFT
clear all; close all; clc
% Compute the frequency samples of the DTFT
w= -4*pi:8*pi/511:4*pi; num = [2 1];den = [1 -0.6];
h = freqz(num, den, w);
% Plot the DTFT
subplot(2,1,1)
plot(w/pi,real(h));grid
title('Real part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,1,2)
% plot the imaginary part in the same way your self and give it title
pause
subplot(2,1,1)
% In this subplot plot magnitude of FFT yourself
subplot(2,1,2)
% In this subplot plot magnitude of FFT your self
Project5.2 DTFTProperties
Most of the properties of the DTFT can be verified using MATLAB. Since all data in MATLAB
have to be finite-length vectors, the sequences being used to verify the properties are thus
restricted to be of finite length.
Program P5_2 can be used to verify the time-shifting property of the DTFT.
% Program P5_2
% Time-Shifting Properties of DTFT
close all; clear all; clc
w = -pi:2*pi/255:pi; wo = 0.4*pi;D=10; num=[1
2 3 4 5 6 7 8 9];
h1 = freqz(num, 1, w);
h2 = freqz([zeros(1,D) num], 1, w);
subplot(2,2,1) plot(w/pi,abs(h1));grid
title('Magnitude Spectrum of Original Sequence')
subplot(2,2,2)
plot(w/pi,abs(h2));grid
title('Magnitude Spectrum of Time-Shifted Sequence')
subplot(2,2,3)
plot(w/pi,angle(h1));grid
title('Phase Spectrum of Original Sequence')
subplot(2,2,4)
plot(w/pi,angle(h2));grid
title('Phase Spectrum of Time-Shifted Sequence')
MagnitudeSpectrumofOriginalSequencMeagnitudeSpectrumofTime-ShiftedSequence 60 60
40 40
20 20
0
-1 -0.5 0 0.5 1
0
-1 -0.5 0 0.5 1
2 2
0 0
-2 -2
-4
-1 -0.5 0 0.5 1 -4
-1 -0.5 0 0.5 1
Program P5_3 can be used to verify the frequency-shifting property of the DTFT.
% Program P5_3
% Frequency-Shifting Properties of DTFT
clear all; close all; clc
w = -pi:2*pi/255:pi; wo = 0.4*pi;
num1=[13579111315 17];
L = length(num1);
h1 = freqz(num1, 1, w); n
= 0:L-1;
num2 = exp(wo*i*n).*num1;
h2 = freqz(num2, 1, w);
subplot(2,2,1)
plot(w/pi,abs(h1));grid
title('Magnitude Spectrum of Original Sequence')
subplot(2,2,2)
plot(w/pi,abs(h2));grid
title('Magnitude Spectrum of Frequency-Shifted Sequence')
subplot(2,2,3)
plot(w/pi,angle(h1));grid
title('Phase Spectrum of Original Sequence')
subplot(2,2,4)
plot(w/pi,angle(h2));grid
title('Phase Spectrum of Frequency-Shifted Sequence')
10 10
1.3579 x 10 MagnitudeSpectrumofOriginalSequence x10 Magnitude Spectrum of Frequency-ShiftedSequence
1.3579
1.3579
1.3579
1.3579
1.3579
1.3579
1.3579
1.3579 1.3579
1.3579 1.3579
1.3579 1.3579
1.3579 1.3579
1.3579 1.3579
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
-9 -9
x10 PhaseSpectrumofOriginalSequence x10 Phase Spectrum of Frequency-ShiftedSequence
1.5 1.5
1 1
0.5 0.5
0 0
-0.5 -0.5
-1 -1
-1.5
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 -1.5
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
Program P5_4 can be used to verify the convolution property of the DTFT.
% Program P5_4
% Convolution Property of DTFT
close all; clear all; clc
w = -pi:2*pi/255:pi;
x1=[1 3 5 7 9 11 13 15 17];
x2=[1 -23 -21];
% convolve x1 and x2 yourself
h1 = freqz(x1, 1, w);
% compute freqz of x2 at w points and save it in h2 yourself hp =
h1.*h2;
h3 = freqz(y,1,w);
subplot(2,2,1)
plot(w/pi,abs(hp));grid
title('Product of Magnitude Spectra')
subplot(2,2,2) plot(w/pi,abs(h3));grid
title('Magnitude Spectrum of Convolved Sequence')
subplot(2,2,3)
plot(w/pi,angle(hp));grid
title('Sum of Phase Spectra')
subplot(2,2,4)
plot(w/pi,angle(h3));grid
title('Phase Spectrum of Convolved Sequence')
Program P5_5 can be used to verify the modulation property of the DTFT.
% Program P3_5
% Modulation Property of DTFT close all; clear all; clc
w = -pi:2*pi/255:pi;
x1=[1 3 5 7 9 11 13 15 17];
x2=[1 -1 1 -1 1 -1 1 -1 1];
y = x1.*x2;
h1 = freqz(x1, 1, w); h2 = freqz(x2, 1, w);
% similarly compute freqz of y and save it in h3 yourself subplot(3,1,1)
plot(w/pi,abs(h1));grid
title('Magnitude Spectrum of First Sequence') subplot(3,1,2)
plot(w/pi,abs(h2));grid
title('Magnitude Spectrum of Second Sequence') subplot(3,1,3)
plot(w/pi,abs(h3));grid
title('Magnitude Spectrum of Product Sequence')
Program P5_6 can be used to verify the time-reversal property of the DTFT.
% Program P5_6
% Time-Reversal Property of DTFT
close all; clear all; clc
w = -pi:2*pi/255:pi;
num=[1 2 3 4];
L = length(num)-1;
h1 = freqz(num, 1, w);
h2 = freqz(fliplr(num), 1, w); h3
= exp(w*L*1i).*h2;
subplot(2,2,1)
plot(w/pi,abs(h1));grid
title('Magnitude Spectrum of Original Sequence')
subplot(2,2,2)
plot(w/pi,abs(h3));grid
title('Magnitude Spectrum of Time-Reversed Sequence')
subplot(2,2,3)
plot(w/pi,angle(h1));grid
title('Phase Spectrum of Original Sequence')
subplot(2,2,4)
plot(w/pi,angle(h3));grid
title('Phase Spectrum of Time-Reversed Sequence')
Magnitude Spectrum of Original Sequence Magnitude Spectrum of Time-Reversed Sequence 10
10
8 8
6 6
4 4
2
-1 -0.5 0 0.5 1 2
-1 -0.5 0 0.5 1
2 2
0 0
-2 -2
-4
-1 -0.5 0 0.5 1 -4
-1 -0.5 0 0.5 1
Lab Tasks
1. Run Program P5_1 and compute the real and imaginary parts of the DTFT, and the
magnitudeandphasespectra.IstheDTFTaperiodicfunctionofω?Ifitis,whatisthe period?
Explainthetypeofsymmetriesexhibitedbythefourplots.
Ans:-
clear all;
close all;
clc;
% Compute the frequency samples of the DTFT
w=( 0.7-0.5*e^-j*w+0.3*e-j*2*w+e*-j*3*w)/(1+0.3*e^-j*w-
0.5*e^j*2*w+0.7*e^-j*3*w);
num = [2 1];
den = [1 -0.6];
h = freqz(num, den, w);
% Plot the DTFT
subplot(2,1,1)
plot(w/pi,real(h));
grid;
title('Real part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,1,2)
subplot(2,1,1)
2. ModifyProgramP5_1toevaluateintherange0≤ω≤πthefollowingDTFT:
andrepeatQuestion1.Commentonyourresults.Canyouexplainthejumpinthephase spectrum?
ThejumpcanberemovedusingtheMATLABcommand,unwrap.Evaluate
thephasespectrumwiththejumpremoved.
Ans:-
clear all;
close all;
clc;
% Compute the frequency samples of the DTFT
w=( 0.7-0.5*e^-j*w+0.3*e-j*2*w+e*-j*3*w)/(1+0.3*e^-j*w-0.5*e^-
j*2*w+0.7*e^-j*3*w);
num = [2 1];
den = [1 -0.6];
h = freqz(num, den, w);
% Plot the DTFT
subplot(2,1,1)
plot(w/pi,real(h));
grid;
title('Real part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,1,2)
subplot(2,1,1)
3. ModifyProgramP3_1toevaluatetheDTFTofthefollowingfinite-lengthsequence:
g[n]= [1 3 5 7 9 11 13 15 17]
And repeat Question 1. Comment on your results. Can you explain the jumps in the phase spectrum?
How would you modify Program P5_1 to plot the phase in degrees?
Ans:-
close all;
clear all;
clc;
w = -pi:2*pi/255:pi;
wo = 0.4*pi;
D=10;
num=[1 3 5 7 9 11 13 15 17];
h1 = freqz(num, 1, w);
h2 = freqz([zeros(1,D) num], 1, w);
subplot(2,2,1)
plot(w/pi,abs(h1));
grid;
title('Magnitude Spectrum of Original Sequence')
subplot(2,2,2)
plot(w/pi,abs(h2));
grid;
title('Magnitude Spectrum of Time-Shifted Sequence')
subplot(2,2,3)
plot(w/pi,angle(h1));
grid;
title('Phase Spectrum of Original Sequence')
subplot(2,2,4)
plot(w/pi,angle(h2));
grid;
title('Phase Spectrum of Time-Shifted Sequence')
4. Modify program p5_2 by adding appropriate comment statements and program
statementsforlabelingthetwoaxesofeachplotbeinggeneratedbytheprogram.Which
parametercontrolstheamountoftime-shiftRunthemodifiedprogramandcommenton
yourresults?
Ans:-
close all;
clear all;
clc;
w = -pi:2*pi/255:pi;
wo = 0.4*pi;
D=10;
num=[1 2 3 4 5 6 7 8 9];
h1 = freqz(num, 1, w);
h2 = freqz([zeros(1,D) num], 1, w);
subplot(2,2,1)
plot(w/pi,abs(h1));
grid;
title('Magnitude Spectrum of Original Sequence')
subplot(2,2,2)
plot(w/pi,abs(h2));
grid;
title('Magnitude Spectrum of Time-Shifted Sequence')
subplot(2,2,3)
plot(w/pi,angle(h1));
grid;
title('Phase Spectrum of Original Sequence')
subplot(2,2,4)
plot(w/pi,angle(h2));
grid;
title('Phase Spectrum of Time-Shifted Sequence')
Ans:-
The frequency increase in the time domain.
6. Modify Program P5_4 by adding appropriate comment statements and program
statementsforlabelingthetwoaxesofeachplotbeinggeneratedbytheprogramRunthe
modifiedprogramandcommentonyourresults.
Ans;-
close all;
clear all;
clc;
w = -pi:2*pi/255:pi;
wo = 0.4*pi;
D=10;
num=[1 3 5 7 9 11 13 15 17];
h1 = freqz(num, 1, w);
h2 = freqz([zeros(1,D) num], 1, w);
subplot(2,2,1)
plot(w/pi,abs(h1));
grid;
title('Magnitude Spectrum of Original Sequence')
subplot(2,2,2)
plot(w/pi,abs(h2));
grid;
title('Magnitude Spectrum of Time-Shifted Sequence')
subplot(2,2,3)
plot(w/pi,angle(h1));
grid;
title('Phase Spectrum of Original Sequence')
subplot(2,2,4)
plot(w/pi,angle(h2));
grid;
title('Phase Spectrum of Time-Shifted Sequence')
7. Modify Program P5_5 by adding appropriate comment statements and program
statementsforlabelingthetwoaxesofeachplotbeinggeneratedbytheprogram.
Ans:-
Ans:-
CheckedBy: Date: