Of DSP 5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

LAB # 5

Title:
Discrete Time Signals and Systems in Frequency Domain.
In the previous two labs we dealt with the time-domain representation of discrete-time signals and
systems, and investigated their properties. Further insight into the properties of such signals and systems
is obtained by their representation in the frequency-domain.

Code of task 1:
% Program P4_1
% Evaluation of the DTFT
clf;
% Compute the frequency samples of the DTFT
w = -6*pi:8*pi/511:6*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(w/pi,imag(h));
grid
title('Imaginary part of H(e^{j\omega})')
xlabel('\omega /\pi'); ylabel('Amplitude');
pause
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');

Result:
Q 4.1 What is the expression of the DTFT being evaluated in Program P4_1?
ANS:IN THIS PART dtft being evaluated by taking its value
w = -6*pi:8*pi/511:6*pi;
num = [2 1];den = [1 -0.6];
h = freqz(num, den, w);

Q 4.2 What is the function of the MATLAB command pause?


ANS: the ‘pause’ command in matlab is used to temporarily pause the excuation of aprogramme or a
script for a specified amount of time during the pause programe does not excute any further command
until the specified time has elapased or user manualy resume execution.
Q 4.3 Run Program P4_1 and plot the real and imaginary parts of the DTFT, and the magnitude and phase
spectra. Is the DTFT a periodic function of ω? If it is, what is the period?
ANS: the real and imaginary parts are given in figure above.
The dtft is not always a peridioc function of w but it can be peripodic under certain conditions. Its period
is
2pi.
Q 4.4 Modify Program P4_1 to evaluate in the range 0 ≤ ω ≤ π the following DTFT:

and repeat Question Q4.3. Comment on your results. Can you explain the jump in the phase spectrum?
The jump can be removed using the MATLAB command unwrap. Evaluate the phase spectrum with the
jump removed.

Task 2 CODE:
% Program P4_2
% Time-Shifting Properties of DTFT clf;
w = -pi:2*pi/255:pi; % frequency vector for evaluating DTFT
D = 10; % Amount of time shift in samples
num = [1 2 3 6 5 6 7 8 9];
% h1 is the DTFT of original sequence
% h2 is the DTFT of the time shifted sequence
h1 = freqz(num, 1, w);
h2 = freqz([zeros(1,D) num], 1, w); subplot(2,2,1)
% plot the DTFT magnitude of the original sequence
plot(w/pi,abs(h1));grid
title('Magnitude Spectrum of Original Sequence','FontSize',8)

xlabel('\omega /\pi'); ylabel('Amplitude');


% plot the DTFT magnitude of the shifted sequence
subplot(2,2,2)
plot(w/pi,abs(h2));grid
title('Magnitude Spectrum of Time-Shifted Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the DTFT phase of the original sequence
subplot(2,2,3)
plot(w/pi,angle(h1));grid
title('Phase Spectrum of Original Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
% plot the DTFT phase of the shifted sequence
subplot(2,2,4)
plot(w/pi,angle(h2));grid
title('Phase Spectrum of Time-Shifted Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');

Result:

Q. 4.4 Run the program P4_2 and comment on your results.


the DTFT magnitude and phase spectra of an original sequence and a time-shifted sequence. The original
sequence is [1 2 3 6 5 6 7 8 9], and the amount of time shift is set to D = 10 samples. The resulting plots
show that the magnitude spectra of the original and time-shifted sequences are identical, but the phase
spectra are different. The phase of the time-shifted sequence is shifted by a linear phase factor e^(-jwD),
which is evident from the linear change in phase with frequency
Q. 4.5 Repeat Question Q4.4 for a different value of the time-shift.
repeat the same experiment with a different value of time-shift (e.g., D = 20), the resulting magnitude
spectra of the original and time-shifted sequences will still be identical, but the phase spectra will differ
by a larger linear phase factor e^(-jwD). Specifically, the phase of the time-shifted sequence will have a
larger slope with frequency than the original sequence.
task 3 code:

% Frequency-Shifting Properties of DTFT


clf;
w = -pi:2*pi/255:pi; % freqency vector for evaluating DTFT
wo = 0.6*pi; % Amount of frequency shift in radians
% h1 is the DTFT of the original sequence
% h2 is the DTFT of the frequency shifted sequence
num1 = [1 3 5 7 9 11 13 15 17];
L = length(num1);
h1 = freqz(num1, 1, w); n = 0:L-1;
num2 = exp(wo*i*n).*num1; h2 = freqz(num2, 1, w);
% plot the DTFT magnitude of the original sequence
subplot(2,2,1)
plot(w/pi,abs(h1));grid
title('Magnitude Spectrum of Original Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the DTFT magnitude of the freq shifted sequence
subplot(2,2,2)
plot(w/pi,abs(h2));grid
title('Magnitude Spectrum of Frequency-Shifted Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the DTFT phase of the original sequence
subplot(2,2,3)
plot(w/pi,angle(h1));grid
title('Phase Spectrum of Original Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
% plot the DTFT phase of the shifted sequence
subplot(2,2,4)
plot(w/pi,angle(h2));grid
title('Phase Spectrum of Frequency-Shifted Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');

Result:
Q 4.6 Run the program P4_3 and comment on your results.
The program P4_3 generates four plots of the magnitude and phase spectra of the original and frequency-shifted
sequences. The magnitude spectrum of the original sequence has a peak at the frequency corresponding to the center
of the sequence. The magnitude spectrum of the shifted sequence shows the same peak, but shifted in frequency by
the amount specified in the program. The phase spectra show a linear trend for the original sequence, and a linear
shift for the shifted sequence

Q 4.7 Which parameter controls the amount of frequency-shift?


The parameter that controls the amount of frequency-shift is wo, which is specified in radians.
Q 4.8 Repeat Question Q4.8 for a different value of the frequency-shift.
To repeat for a different frequency-shift, a new value should be assigned to wo in the program, and the program
should be run again. For example, setting wo = 0.8*pi would shift the spectrum by a different amount.
Q 4.9 Modify P4_3 to run for length of 4 & 14 i.e.
num=[1:2:7] (Length=4)
num=[1:2:31] (Length=16)
Comment on effect of varying length on Magnitude Spectrum & Phase spectrum.
Varying the length of the sequence affects the spacing of the peaks in the magnitude spectrum, with shorter
sequences having wider spacing and longer sequences having narrower spacing. The phase spectra also show more
fluctuations for shorter sequences due to aliasing effects, while longer sequences show more smooth and continuous
phase changes.
Task4 code:
% Program P4_4
clf;
w = -pi:2*pi/255:pi; % freqency vector for evaluating DTFT
x1 = [1 3 5 7 9 11 13 15 17]; % first sequence
x2 = [1 -2 3 -2 1]; % second sequence
y = conv(x1,x2); % time domain convolution of x1 and x2
h1 = freqz(x1, 1, w); % DTFT of sequence x1
h2 = freqz(x2, 1, w); % DTFT of sequence x2
% hp is the pointwise product of the two DTFT's
hp = h1.*h2;
% h3 is the DTFT of the time domain convolution;
% it should be the same as hp
h3 = freqz(y,1,w);
% plot the magnitude of the product of the two original spectra
subplot(2,2,1)
plot(w/pi,abs(hp));grid
title('Product of Magnitude Spectra','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the magnitude spectrum of the time domain convolution
subplot(2,2,2)
plot(w/pi,abs(h3));grid
title('Magnitude Spectrum of Convolved Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the phase of the product of the two original spectra
subplot(2,2,3)
plot(w/pi,angle(hp));grid
title('Sum of Phase Spectra','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
% plot the phase spectrum of the time domain convolution
subplot(2,2,4)plot(w/pi,angle(h3));gridtitle
('Phase Spectrum of Convolved Sequence','FontSize',8)xlabe
l('\omega /\pi');ylabel('Phase in radians');
Result:

Q 4.10 Run the program P4_4 and comment on your results


ANS: this programme demonstrates the convolution property of the DTFT (Discrete Time Fourier
Transform). The program convolves two discrete-time sequences, x1 and x2, computes their DTFTs, and
then compares the pointwise product of the DTFTs with the DTFT of the convolved sequence. The
program plots the magnitude and phase spectra of both the pointwise product and the convolution result.

The results show that the magnitude spectrum of the pointwise product of the DTFTs is identical to the
magnitude spectrum of the DTFT of the convolved sequence. The phase spectra of the pointwise product
and the convolved sequence are also identical. These results confirm the convolution property of the
DTFT, which states that the DTFT of the convolution of two sequences is equal to the pointwise product
of their DTFTs.

Task 5 Code:
clf;
w = -pi:2*pi/255:pi; % frequency vector for evaluating DTFT
% original ramp sequence
% note: num is nonzero for 0 <= n <= 3.
num = [1 2 3 4];
L = length(num)-1;
h1 = freqz(num, 1, w)
% Program P4_5 1, w); % DTFT of original ramp sequence
h2 = freqz(fliplr(num), 1, w);

h3 = exp(w*L*i).*h2;
% plot the magnitude spectrum of the original ramp sequence
subplot(2,2,1)
plot(w/pi,abs(h1));grid
title('Magnitude Spectrum of Original Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the magnitude spectrum of the time reversed ramp sequence
subplot(2,2,2)
plot(w/pi,abs(h3));grid
title('Magnitude Spectrum of Time-Reversed Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the phase spectrum of the original ramp sequence
subplot(2,2,3)
plot(w/pi,angle(h1));grid
title('Phase Spectrum of Original Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
% plot the phase spectrum of the time reversed ramp sequence
subplot(2,2,4)
plot(w/pi,angle(h3));grid
title('Phase Spectrum of Time-Reversed Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');

RESULT:

Q 4.11 Run the program P4_5 and comment on your results


The program P4_5 verifies the time reversal property of the DTFT by generating the DTFT of a
ramp sequence and its time-reversed version using the freqz function, and then plotting the
magnitude and phase spectra of both sequences. The magnitude spectrum of the time-reversed
sequence is found to be identical to that of the original sequence, while the phase spectrum of the
time-reversed sequence is the negation of that of the original sequence, as expected from the time
reversal property of the DTFT.

Q 4.12 Explain how the program implements the time-reversal operation.

The program implements the time-reversal operation by using the flipl r function to reverse the order of
the original sequence, and then multiplying the resulting frequency response by the complex exponential
exp(wLi), where L is the length of the original sequence minus one, and w is the frequency vector used to
evaluate the DTFT. This multiplication by exp(wLi) introduces a phase shift that corresponds to a time
reversal operation in the time domain

You might also like