20EE10083 DSP Exp7

You might also like

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

Department of Electrical Engineering

Indian Institute of Technology, Kharagpur

Digital Signal Processing Laboratory(EE39203)


Autumn, 2022-23

Experiment 7: Fast Fourier Transform

Bharat Uday
20EE10083

November 28, 2022


1 Introduction

This section continues the analysis of the DFT done earlier

1.1 Shifting the Frequency Range

First create a Hamming window x of length N = 20, using the Matlab command x = ham-
ming(20). Then use your matlab function DFTsum to compute the 20 point DFT of x. suited
for numerical evaluation on computers
Lab Report:
Hand in the plot of the |X20 [k]|—. Circle the regions of the plot corresponding to low frequency
components.
The matlab plot of magnitude of 20 point hamming window:

Write a Matlab function to compute samples of the DTFT and their corresponding frequencies
in the range - π to π
Use your function DTFTsamples to compute DTFT samples of the Hamming window of length
N = 20. Plot the magnitude of these DTFT samples versus frequency in rad/sample.
Lab Report:
1. Hand in the code for your function DTFTsamples.
2. Hand in the plot of the magnitude of the DTFT samples

code The Matlab code for the function DTFTsamples:


1 function [X , w ] = DTFTsamples ( x )
2 N = length ( x ) ;
3 k =0: N -1;
4 w1 =2* pi * k / N ;
5 w1 ( w1 >= pi ) = w1 ( w1 >= pi ) -2* pi ;

1
6 [ X_dft ]= DFTsum ( x ) ;
7 X = fftshift ( X_dft ) ;
8 w = fftshift ( w1 ) ;
9 end

The Matlab Plot of the magnitude of DTFT samples of the Hamming window:

1.2 Zero Padding

In the following, you will compute the DTFT samples of x[n] using both N = 50 and N = 200
point DFT’s. Notice that when N = 200, most of the samples of x[n] will be zeros because x[n]
= 0 for n 50. This technique is known as “zero padding”, and may be used to produce a finer
sampling of the DTFT.
For N = 50 and N = 200, do the following:
1. Compute the vector x containing the values x[0], . . . , x[n 1].
2. Compute the samples of X[k] using your function DTFTsamples.
3. Plot the magnitude of the DTFT samples versus frequency in rad/sample

Lab Report:
1. Submit your two plots of the DTFT samples for N = 50 and N = 200.
2. Which plot looks more like the true DTFT?
3. Explain why the plots look so different.
The Matlab Plot of the magnitude of DTFT samples for N=50 and N=200:

2
The plot for N=200 is more like DTFT , this is because of the finer sampling due to zero
padding.

2 The Fast Fourier Transform Algorithm

We have seen in the preceding sections that the DFT is a very computationally intensive
operation. In 1965, Cooley and Tukey1 published an algorithm that could be used to compute
the DFT much more efficiently. Various forms of their algorithm, which came to be known as
the fast Fourier transform (FFT).

2.1 Implementation of Divide-and-Conquer DFT

Test your function dcDFT by using it to compute the DFT’s of the following signals.

Lab Report:
Do the following:
1. Submit the code for your function dcDFT.
2. Determine the number of multiplies that are required in this approach to computing an N
point DFT.

code The Matlab codes for dcDFT


1 function [ X ] = dcDFT ( x )
2 N = length ( x ) ;

3
3 j = sqrt ( -1) ;
4 k =0: N /2 -1;
5 x0 = x (1:2: N ) ;
6 x1 = x (2:2: N ) ;
7 [ X0 ]= DFTsum ( x0 ) ;
8 [ X1 ]= DFTsum ( x1 ) ;
9 W_N = exp ( - j *2* pi .* k / N ) ;
10 X_k = X0 + W_N .* X1 ;
11 X_k_2 = X0 - W_N .* X1 ;
12 X =[ X_k X_k_2 ];
13 end

The Plot of DFT of the given functions using dcDFT:

2.2 Recursive Divide and Conquer

Write three Matlab functions to compute the 2, 4, and 8-point FFT’s


The function FFT2 should directly compute the 2-point DFT , but the functions FFT4 and
FFT8 should compute their respective FFT’s using the divide and conquer strategy. This
means that FFT8 should call FFT4, and FFT4 should call FFT2.
Test your function FFT8 by using it to compute the DFT’s of the following signals.
Compare these results to the previous ones.

code The Matlab codes for FFT2

4
1 function [ X ] = FFT2 ( x )
2 X (1) = x (1) + x (2) ;
3 X (2) = x (1) -x (2) ;
4 end

code The Matlab codes for FFT4


1 function [ X ] = FFT4 ( x )
2 N = length ( x ) ;
3 j = sqrt ( -1) ;
4 k =0: N /2 -1;
5 W_N = exp ( - j *2* pi .* k / N ) ;
6 x0 = x (1:2: N ) ;
7 x1 = x (2:2: N ) ;
8

9 [ X0 ]= FFT2 ( x0 ) ;
10 [ X1 ]= FFT2 ( x1 ) ;
11

12 X_k = X0 + W_N .* X1 ;
13 X_k_2 = X0 - W_N .* X1 ;
14

15 X =[ X_k X_k_2 ];
16

17 end

code The Matlab codes for FFT8


1 function [ X ] = FFT8 ( x )
2 N = length ( x ) ;
3 j = sqrt ( -1) ;
4 k =0: N /2 -1;
5 W_N = exp ( - j *2* pi .* k / N ) ;
6 x0 = x (1:2: N ) ;
7 x1 = x (2:2: N ) ;
8

9 [ X0 ]= FFT4 ( x0 ) ;
10 [ X1 ]= FFT4 ( x1 ) ;
11

12 X_k = X0 + W_N .* X1 ;
13 X_k_2 = X0 - W_N .* X1 ;
14

15 X =[ X_k X_k_2 ];
16

17 end

The output of FFT8 for x[n]=1:

The Matlab plot for FFT8 of the mentioned functions:

5
Yes, the results are same as previous results for 8 point dft
Write a recursive function X = ffts tage(x)thatperf ormsonestageof theF F T algorithmf orapower−
of − 2lengthsignal.

code The Matlab codes for fftstage function:


1 function [ X ] = fft_stage ( x )
2 N = length ( x )
3 if ( N ==2)
4 X = FFT2 ( x ) ;
5 return ;
6 elseif (N >2)
7 j = sqrt ( -1) ;
8 k =0: N /2 -1;
9 W_N = exp ( - j *2* pi .* k / N ) ;
10 x0 = x (1:2: N ) ;
11 x1 = x (2:2: N ) ;
12 [ X0 ]= fft_stage ( x0 ) ;
13 [ X1 ]= fft_stage ( x1 ) ;
14

15 X_k = X0 + W_N .* X1 ;
16 X_k_2 = X0 - W_N .* X1 ;
17

18 X =[ X_k X_k_2 ];
19

20 end
21

22 end

You might also like