Simulation exercises using MATLAB/SIMULINK
DFT
15. Run the following demo
DFT of simple sequences
cd d:\dsp_lab\demo\dft
gui
16. Compute and plot the DFT of the following sequences and observe their properties
a) Unit impulse signal; xi = {1 0 0 0 0 0 0 0}
b) All ones; x1 = {1 1 1 1 1 1 1 1}
c) Three point boxcar; xb = {1 1 1 0 0 0 0 0}
d) Symmetric boxcar; xbsy = {1 1 0 0 0 0 0 1}
e) Sinusoid; s[n]= A cos(2πf0n + φ) Try for different lengths of sequence.
f) Real exponential; x[n] = (0.9)n U[n] 0≤ n ≤ 31. Compare it with samples of ⎜Y(ejw)⎜
= ⎜(1-0.9 e -jw)-1⎜, the DTFT of the infinitely long exponential and explain the
difference in terms of windowing.
Sample Solution (d) x(n) Real part of DFT
1
% ex2_8d.m 3
2
0.5
N = 8; nn = 0:(N-1); kk = nn; 1
xb = [1 1 1 0 0 0 0 0]; 0
0 -1
Xb = fft(xb,N); 0 2 4 6 0 2 4 6
Index (n) Index (k)
Imag part of DFT
2
subplot(221), stem(nn,xb); 1
title(' x(n) '); xlabel(' Index (n) '); 0
axis([0 7 0 1]); -1
subplot(222), stem(kk,real(Xb)); -2
title(' Real part of DFT '); 0 2 4
Index (k)
6
xlabel(' Index (k) ');
axis([0 7 -1 4]);
subplot(224), stem(kk,imag(Xb));
title(' Imag part of DFT ');
xlabel(' Index (k) ');
axis([0 7 -2 2]);
17. a) Generate the sequence,
x(n)= 0.5(1-cos(2π/L)) 0 ≤ n ≤ 19
0 otherwise
Compute its DFT and plot the magnitude spectrum.
b) Pad zeroes at the end and extend the sequence and compute the DFT for N=40, 50,
1024 and comment on the effect of zero padding.
c) Pad the 2N zeroes in the middle of the sequence instead of at the end and observe
the difference in the spectrum.
18. Compare the characteristics of the following window functions from their frequency
spectrum plots. (use wvtool)
a) Rectangular window w_rect[n] = 1 0≤ n ≤ M-1
b) Hanning window w_hann[n] = 0.5-0.5cos(2πn/M-1) 0≤ n ≤ M-1
c) Hamming window w_hamm[n] = 0.54-0.46cos(2πn/M-1) 0≤ n ≤ M-1
d) Blackmann window w_blk[n] = 0.42-0.5cos(2πn/M-1)+0.08cos(4πn/M-1)
0≤ n ≤ M-1
Dept. of E&C, NITK Surathkal 12
Simulation exercises using MATLAB/SIMULINK
19. Generate a signal s[n] with three sinusoidal components at 50, 120 and 240Hz
corrupted by AWGN. Plot the spectrum and identify the signal components.
Sample Solution:
% ex21.m
% identification of sinusoids in noise
fs=2000;
t = (0:199)/fs;
s = sin(2*pi*50.*t) + sin(2*pi*120.*t) +sin(2*pi*240.*t);
awgn = (0.5*randn(1,200)+.25); % N(0.25, 0.25)
sn = s+awgn;
subplot(211), plot(t,sn);
title(' Sinusoid with noise'); grid;
Sn = fft(sn,200);
f = 0:10:990;
sfmag = abs(Sn);
subplot(212), plot(f,sfmag(1:100));
title(' Spectral estimation'); grid;
Repeat using Simulink
20. During recording an ECG signal sampled at 300Hz gets contaminated by 60Hz hum.
Two beats of the original and contaminated signal (600 samples each) are provided as
ecgo and ecg. Load these signals and plot them. Compute the 600point DFT of the
contaminated signal and zero out the DFT components corresponding to 60Hz signal.
Take the IDFT to obtain filtered ECG signal. Display the filtered and original signals.
21. a) Generate 600 samples of the signal x(n) = cos(0.1nπ) + cos(0.4nπ) + cos(0.7nπ).
Plot its DFT magnitude.
(b) Generate 200 samples each of the three signals x1(n) = cos(0.1nπ), x2(n)=
cos(0.4nπ), and x3(n) = cos(0.7nπ). Concatenate them {x1(n), x2(n), x3(n)} to form
a 600 sample signal. Plot its DFT magnitude.
(c) Obtain a time-frequency plot using spectrogram
Dept. of E&C, NITK Surathkal 13