A. Computation of The DFT
A. Computation of The DFT
ISIP
A. Computation of the DFT ....................................................................................................................... 1
B. Time shift property of the DFT.............................................................................................................. 9
Time-shifting property ............................................................................................................................ 10
C. Frequency-Shift Property of the DFT .................................................................................................. 10
Which parameter controls the amount of shift? .................................................................................... 11
D. Convolution Property of the DFT ........................................................................................................ 11
Explain the convolution property and how it is demonstrated by the figures. ...................................... 12
E. Modulation Property........................................................................................................................... 13
Explain the modulation property and how it is demonstrated by the figures. ...................................... 13
F. Time Reversal Property ....................................................................................................................... 14
Explain the time-reversal property and how it is demonstrated by the figures. ................................... 15
Tutorial Questions................................................................................................................................... 15
Resolving two signals that are close in frequency .................................................................................. 15
1.) ............................................................................................................................................................ 15
2.) ............................................................................................................................................................ 17
As answered: ........................................................................................................................................... 19
B. Effects of zero padding and signal length on the DFT ........................................................................ 19
1.) ............................................................................................................................................................ 19
2.) ............................................................................................................................................................ 20
A. Computation of the DFT
% Program P3_1
% Evaluation of the DTFT
clf;
% 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
figure(1)
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');
figure(2)
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');
figure(3)
freqz(num,den)
1. Compare the output of the code above with the output of >> figure;
freqz(num,den).
What is the basic difference between the two?
The output of freqz(num,den) is just aperiodic signal while the
output of the code is a periodic signal.
2. What can you say about the symmetries in real and imaginary parts of the
DFT?
The real part is an even signal while the imaginary part is an odd
signal.
3. Modify the above program to evaluate in the range 0 ≤ ≤ the following
DFT using
freqz.
% Program P3_3
% Evaluation of the DTFT
clf;
% Compute the frequency samples of the DTFT
w1 = 0:8*pi/511:pi;
num1 = [0.7 -0.5 0.3 1];den1 = [1 0.3 -0.5 0.7];
h1 = freqz(num1, den1, w1);
% Plot the DTFT
figure(1)
subplot(2,1,1)
plot(w1/pi,real(h1));grid
title('Real part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,1,2)
plot(w1/pi,imag(h1));grid
title('Imaginary part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
figure(2)
subplot(2,1,1)
plot(w1/pi,abs(h1));grid
title('Magnitude Spectrum |H(e^{j\omega})|')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,1,2)
plot(w1/pi,angle(h1));grid
title('Phase Spectrum arg[H(e^{j\omega})]')
xlabel('\omega /\pi');
ylabel('Phase in radians');
4. Again modify the given code to evaluate the DFT of the following finite
point sequence,
g[n] = {1 3 5 7 9 11 13 15 17}. Use two functions freqz() and fft() to
compute the DFT.
You should get the same magnitude and phase response. Compare the two methods
of
computing for the DFT.
% Program P3_1
% Evaluation of the DTFT
clf;
% Compute the frequency samples of the DTFT
w = 0:8*pi/511:2*pi;
g = [1 3 5 7 9 11 13 15 17];
h = freqz(g, 1, w);
h1 = fft(g,length(w));
% Plot the DTFT
figure(1)
subplot(2,2,1)
plot(w/pi,real(h));grid
title('Real part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,2,2)
plot(w/pi,imag(h));grid
title('Imaginary part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,2,3)
plot(w/pi,abs(h));grid
title('Magnitude Spectrum |H(e^{j\omega})|')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,2,4)
plot(w/pi,angle(h));grid
title('Phase Spectrum arg[H(e^{j\omega})]')
xlabel('\omega /\pi');
ylabel('Phase in radians');
figure(2)
subplot(2,2,1)
plot(w/pi,real(h1));grid
title('Real part of H1(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,2,2)
plot(w/pi,imag(h1));grid
title('Imaginary part of H1(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,2,3)
plot(w/pi,abs(h1));grid
title('Magnitude Spectrum |H1(e^{j\omega})|')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,2,4)
plot(w/pi,angle(h1));grid
title('Phase Spectrum arg[H1(e^{j\omega})]')
xlabel('\omega /\pi');
ylabel('Phase in radians');
B. Time shift property of the DFT
Program P3_2 Time-Shifting Properties of DTFT
clf;
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')
Time-shifting property
When a given a discrete time signal is shifted to the right or left by a
factor
of n0, time-shifting property can be used to evaluate the DTS. In the
example, the zero-padding is the representation of the time shift. The DTS
was
shifted 10 indexes to the right of the graph. Since we will multiply
e^jwn0 to the frequency-domain signal, its magnitude is only just equal
to one. The phase response will be the ones affected that's why in the
plots, the phase response changed.
Tutorial Questions
Resolving two signals that are close in frequency
clf;
1.)
Generate two sinusoids at f1 = 100 Hz with an amplitude of 1.2 and at f2 =
150 Hz with an
amplitude of 0.8. The length of the sinusoids should be five periods of the
lowest frequency
which is 100 Hz) and the sampling rate is 4000 Hz. Plot the sum of the
sinusoids in time.
clf;
fs = 4000;
freq = [100 150];
amp = [1.2 0.8];
ph = [0 0];
t = [0:1/fs:5/min(freq)];
% generate the sinusoid
y =((amp'*ones(1,length(t))).*sin((2*pi*freq'*t)+ph'*ones(1,length(t))))';
figure(6); plot(sum(y'));
2.)
Calculate the DFT of the first 100 samples of the signal using fft. Use stem
instead of plot to
show the magnitude and phase response. Use the axis to zoom in the frequency
range: 0 to 200
Hz
clf;
ty_sum = sum(y');
y_sum = ty_sum(1:100);
Nfft = 100;
y_fft = fft(y_sum, Nfft);
% generate the frequency axis
w = linspace(0,fs,Nfft);
% Plot the magnitude and the phase response
mag = abs(y_fft);
ph1 = angle(y_fft);
figure(7); subplot(2,1,1), stem(w, mag, '^');
axis ([0, 200, 0, 140]);
% use axis to zoom into plot to determine frequencies of sinusoids
title('The magnitude response from 0 to fs');
axis; % turn autoscaling back on
subplot(2,1,2), stem(w,ph1, '^');
title('The phase response from 0 to fs');
As answered:
a) What is the frequency resolution of our DFT?
f = 4000/100 = 40 Hz
b) Can you tell from the plot of the magnitude response the number of
sinusoids in the signal?
Yes.
c) From the plot, can you determine the frequency of the sinusoids?
No.
fs = 4000;
freq = 1000;
amp = 1;
ph = 0;
t = [0:1/fs:2/freq];
% generate the sinusoid
y = amp*sin((2*pi*freq*t)+ph)';
y_sum = y;
Nfft = 10000;
y_fft = fft(y_sum, Nfft);
% generate the frequency axis
w = linspace(0, fs/2, Nfft/2);
y_fft = y_fft(1:length(y_fft)/2);
% Plot the magnitude response,
mag = abs(y_fft);
figure(11); plot(w, mag, '^');
title('The magnitude response from 0 to fs/2');
a) Why is the plot of the frequency response similar to a sinc function?
The sinusoid was multiplied with a train of impulse similar to
frequency spectrum that is convolved with a train of impulse.
b) What is the effect of varying the number of frequency samples on the
magnitude response?
The magnitude response loses its resemblance to the sinc function.
c) What is the effect on the magnitude response by increasing the number of
samples (also increasing the length of the signal) from 2 periods to 5
periods?
The samples will become thicker.
d) What is the effect of increasing the signal length on the width of the
main
lobe of the magnitude response?
The magnitude response will be distributed even more.
2.)
In computing for the fft of the signal, compute for the DFT without
specifying the number of
FFT points. Plot the magnitude of the DFT without specifying the frequency
axis.
a) What is the effect on the magnitude response when N is not specified?
The fft will only output a specific number of elements.
b) To increase the number of signal samples, the easiest way is to pad the
signal with 100 zeros at the end. Plot the magnitude response. What is
the effect on the DFT when the signal is padded with zeros?
y_1 = zeros(1,100);
y_1 = [y' y_1];
y_2 = fft(y_1, 109)
plot([1:109],abs(y_2))