![]() |
![]() |
|
|
| <<Home | Lab 6 | |||
|
Discrete Time Fourier Transform (DFT) is a Fourier representation of finite length signals, provides frequency domain samples of the discrete time Fourier transform. The key functions in MATLAB and MATLAB Signal Processing toolbox for performing one-dimensional DFT and FFT are fft and ifft respectively. DFT
Example 1 Find the DFT of the sequence x[n]=[1 0 0 1]. Solution x= [1, 0, 0, 1]; X=fft(x) Result 2.0000 1.0000+1.0000i 0 1.0000-1.0000i Inverse DFT
Example 2 X= [2,1+i,0,1-i]; x=ifft(X) Result 1.0000 0.0000+0.0000i 0 1.0000-0.0000i DFT
Exercise 1 Find the DFT of the following sequences: (i) [1 2 3 1] (ii) [3 2 1 0 1 2] Verify the results manually. Solution % (i) [1,2,3,1] x= [1, 2, 3, 1]; X=fft(x) Result 7.0000 -2.0000-1.0000i 1.0000 -2.0000+1.0000i These results are verified when we take ifft and get the original result. Solution % (ii) [3,2,1,0,1,2] x= [3, 2, 1,0,1,2]; X=fft(x) Result 9.0000 4.0000 0.0000-0.0000i 1.0000 0.0000+0.0000i 4.0000+0.0000i These results are verified when we take ifft and get the original result. Magnitude response
Example 3 Consider h[n] = 0.9ncos л n, n>=0 Compute the magnitude response of h[n]. Use (i) 4- point DFT (ii) 16- point DFT (iii) 32- point DFT (iv) 64- point DFT (v) 128- point DFT. Plot all responses on the same graph paper and comment. Solution n = 0:1:1000; h = (0.9).^n.*cos( pi * n ); H1 = fft(h,4); f1 = (0:3)/4; % generate 4 equally spaced frequencies mag4 = abs(H1); H2 = fft(h,16); f2 = (0:15)/16; mag16 = abs(H2); H3 = fft(h,32); f3 = (0:31)/32; mag32 = abs(H3); H4 = fft(h,64); f4 = (0:63)/64; mag64 = abs(H4); H5 = fft(h,128); f5 = (0:127)/128; % generate 128 equally spaced frequencies mag128 = abs (H5) plot(f1,mag4,'b',f2,mag16,'c',f3,mag32,'k',f4,mag64,'y',f5,mag128,'m') Result
Comments: From figure we can see that blue color response and the maroon color response. We observed that blue color response is very rough and maroon color response is smoother than blue and other color responses. Magnitude spectra of signal
Exercise 2 Consider h[n] = sin(0.6 л n). What is the frequency of this signal? Compute the magnitude spectra of the signal using N=64, 128, 256 and 512. Plot all these graphs on the same graph paper. Solution n = 0:1:1000; h = sin(0.6* pi * n ); H1 = fft(h,64); f1 = (0:63)/64; % generate 64 equally spaced frequencies mag4 = abs(H1); H2 = fft(h,128); f2 = (0:127)/128; mag16 = abs(H2); H3 = fft(h,256); f3 = (0:255)/256; mag32 = abs(H3); H4 = fft(h,512); f4 = (0:511)/512; mag64 = abs(H4); plot(f1,mag4,'b',f2,mag16,'c',f3,mag32,'k',f4,mag64,'y') Result
Magnitude response using 128 DFT
Exercise 3 Consider x[n] = sin(0.6 л n) + 0.8sin(0.64л n + 1.6). Plot the sequence from n=0 to n=100. Also plot the magnitude response using 128 point DFT. Solution n = 0:1:100; h = sin( 0.6 * pi * n ) + 0.8 * sin( 0.64 * pi * n + 1.6 ); H2 = fft(h,128); f2 = (0:127)/128; mag128 = abs ( H2 ) H3 = fft(h,256); f3 = (0:255)/256; mag256 = abs ( H3 ) plot(f2,mag128, 'm',f3,mag256,'b')Result
Magnitude and Phase spectra (DFT)
Exercise 4a Sketch the magnitude and phase spectra of the following sequence using the 50-point and 100-point DFT. Also plot the sequence x[n]. 1, 0<=n<=9 x[n] = 0, otherwise Solution n = 0:1:50; h = ones(1,9); H2 = fft(h,50); f2 = (0:49)/50; mag128 = abs ( H2 ) pha128 = angle( H2 ) H3 = fft(h,100); f3 = (0:99)/100; mag256 = abs ( H3 ) pha256 = angle( H3) plot(f2,mag128, 'm',f3,mag256,'b')figure, plot(f2,pha128, 'm',f3,pha256,'b')Result
Magnitude and Phase spectra (Inverse DFT)
Exercise 4b Compute the magnitude response of the 50 point and 100 point inverse DFT of the above sequence. Solution H1 = ifft(h,50); f1 = (0:49)/50; ma128 = abs ( H1 ) phas128 = angle( H1 ); H4 = ifft(h,100); f4 = (0:99)/100; ma256 = abs ( H4 ) phas256 = angle( H4 ); figure, plot(f1,ma128, 'm',f4,ma256,'b')figure, plot(f2,phas128, 'm',f3,phas256,'b')Result
Magnitude and Phase of transfer function
Exercise 5a The exponential signal x(t) = e-t, t >= 0 0, otherwise is sampled at the rate Fs = 20 samples per second, and a block of 100 samples is used to estimate its spectrum. Use 200 point DFT to find the magnitude and phase response of the system. Solution n = 0:1:50; h = exp(-n./20); % since t=n/FsH2 = fft(h,200); f2 = (0:199)/200; mag128 = abs ( H2 ) pha128 = angle( H2 ) H3 = fft(h,100); f3 = (0:99)/100; mag256 = abs ( H3 ) pha256 = angle( H3) plot(f2,mag128, 'm',f3,mag256,'b')figure, plot(f2,pha128, 'm',f3,pha256,'b')Result
Magnitude and Phase of transfer function
Exercise 5b Find the pulse transfer function of the above sequence and hence find the magnitude and phase response of the transfer function. (Hint: you may use the MATLAB built in function freqz(num,den,N,'whole') here). Compute these responses with those obtained in problem 2(a). Solution n=0:1:50; h=exp(-n/20); H1=fft(h,50); f1=(0:49)/50; mag1=abs(H1); c=freqz(1,[1-exp(-n/20)],50, 'whole');plot(mag1,c); figure plot(f1,mag1, 'b')Result
Convolution using DFT and IDFT
Exercise 6a Find the convolution of the following sequences using DFT and IDFT. x[n]=[6 7 6 5], y[n]=[2 6 5 5 4 1 1]; Use the following steps: Find the length L of the convolution sum. Compute the L-point DFT of x[n] and y[n] seperately. Multiply the sequences found in step 2. Find the IDFT of the product. Solution n=0:1:9; x = [6 7 6 5]; y = [2 6 5 5 4 1 1]; l = 10; H1 = fft(x,10) f1 = (0:9)/10; mag1 = abs ( H1 ) H2 = fft(y,10) f2 = (0:9)/10; mag2 = abs(H2) H3 = conv( mag1, mag2); H4 = ifft(H3,10); f3 = (0:9)/10; mag3 = abs ( H4 ) plot(n,mag3) Result
Convolution using DFT and IDFT
Exercise 6b Use the built in function "conv" to verify the result of Exercise 6(a). Solution n=0:1:9; x = [6 7 6 5]; y = [2 6 5 5 4 1 1]; H5 = conv(x,y) figure, plot(n,H5) Result
DSP Lab 1 DSP Lab2 DSP Lab 3 DSP Lab4 DSP Lab 5 DSP Lab 6 DSP Lab7 DSP Lab8 DSP Lab9 DSP Lab10 Other material |
||||
| <<Home | ||||
|
||||||