0% found this document useful (0 votes)
4 views

Lab4_Report-2-2-2-2

Uploaded by

Prisha Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lab4_Report-2-2-2-2

Uploaded by

Prisha Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

ELL319 Digital Signal Processing

Lab Report | Experiment 4


Prisha Jain - 2021EE30330
Sanandh Kataria - 2021EE1

March 19, 2025

DFT, IDFT and FFT


1​ Objectives
Learning to compute N point Discrete Fourier Transform, and Inverse Discrete Fourier Trans- form
for a sequence for a sequence and to plot magnitude and phase spectrum. Using DFT and IDFT,
perform linear and circular convolution of two sequences. Also learning about Fast Fourier Transform
and its usefulness in finding the frequency spectrum of signals.

Part A:​ To write a C program to compute the N point complex valued DFT of an array x[n].

Part B:​ To write a C program to compute IDFT of a complex valued sequence X(k)

Part C:​ To implement the convolution operation in time domain.

Part D:​ To write a C function to compute the FFT of a sample domain signal x[n].

Part E:​ To compare the running time of FFT in Part D with the DFT function in Part A.

2​ Requirements:
1. CCS

3​ Theory
3.1​ Part A: Discrete Fourier Transform
The discrete Fourier Transform is used to find the amplitude and phase spectrum of a discrete time
sequence x[n] of length N as
N−1
X(k) = DFT (x[n]) =​ x[n]e−j2πkn/N​ ∀k ∈ {0, 1, · · · , N − 1}​ (1)
n=0

The real part of X(k) can be seen as the correlation between x and cosine function of frequency k and
the imaginary part as that between x and sine function of frequency k. Correlation between two
signals, by its very definition, can be seen as a metric of the similarity between the two signals. Closer
the frequencies of the two signals, higher the magnitude of correlation X(k) will
be. To get the frequencies in the signal, we require sampling frequency fs used to sample x[n]. The
frequencies in the signal are then given by
(2)
f = fs · k
N

3.2​ Part B: Inverse Discrete Fourier Transform


Given a frequency spectrum X(k), Inverse Discrete Fourier Transform is the inverse of the operation
given in equation (1). It yields the domain signal x[n] back. IDFT is given by

3.3​ Part C: Convolution of two signals using DFT and IDFT


Convolution of two signals x[n] and h[n] in time(or sample) domain is given by
N−1
y[n] =​ x[k]h[n − k]​ (4)
k=0

In frequency domain the convolution of the two signals corresponds to multiplication of the Fourier
transforms of the two signals, given by

Y (k) = X(k)H(k)​ (5)

where X(k) and H(k) are the Fourier transforms of x[n] and h[n] respectively.

3.4​ Part D: Fast Fourier Transform


The time complexity of the DFT computing algorithm is of quadratic in nature, i.e., O(n2) which gets
very inefficient in respect of large signals with a huge number of samples. Therefore we use Fast
Fourier Transforms, which are a class of algorithms that use divide and conquer strategy to compute
Fourier Transforms of smaller segments of the signal, and combine them to compute the overall
Fourier transform of the complete signal.

The most common type of algorithm used for Fast Fourier Transforms is the Radix-2 Dec- imation
In Time FFT. It assumes the signal size N to be a power of 2. Radix-2 DIT first computes the DFTs of
the even-indexed inputs (x2m = x0, x2, · · · xN−2) and of the odd indexed inputs (x2m+1 = x1, x3, · · ·
xN−1) and then combines the two results to produce the DFT of the whole sequence.

If we denote the DFT of the even indexed inputs x2m by Ek and the DFT of the odd indexed inputs x2m+1
by Ok, equation (6) above can be re-written as

X(k) = E(k) + e−2πjk/N O(k)​ (7)

Due to periodicity of the exponential, we can also simplify the expression for Xk+N/2 as

Xk+N/2 = E(k) − e−2πjk/N O(k)​ (8)


4​ Procedure
4.1​ Part A: Discrete Fourier Transform
•​ Equation (1) was modified using Euler’s theorem as:

N−1​ N−1

n=0​ n=0

•​ x[n] was taken in as an array and its complex valued Discrete Fourier Transform was calculated
using the above equation

4.2​ Part B: Inverse Discrete Fourier Transform


•​ Inverse Discrete Fourier Transform of the signal X(k) obtained in Part A is calculated using the
formula given in equation (3).
•​ IDFT yields sample domain signal x[n] back.

4.3​ Part C: Convolution


•​ In order to calculate the convolution of two signals x[n] and h[n], we first calculate the N -point
DFT of each of the signals in frequency domain, multiply the two as Y (k) = X(k)H(k) and
calculate the inverse DFT of Y(k) to obtain y[n].
•​ Both the signals x[n] of length L and h[n] of length K are made of length N = L + K − 1 and their
N -point DFT Y (k) is calculated.
•​ N -point IDFT of Y (k) is calculated to get back the convoluted signal y[n]

4.4​ Part D: Fast Fourier Transform


•​ Fast Fourier Transform is calculated using a recursive algorithm based on the equations (6), (7),
and (8).

4.5​ Part E: Execution Time for Part A and Part D


•​ The running times for each of the algorithms are analytically calculated with exceptions of
constants and henceforth compared.

5​ Code

Listing 1: Custom struct defined for handling complex numbers in header file complex.h
Listing 2: Implementation of complex.h

Listing 3: Code for Part A


Listing 4: Code for Part B
Listing 5: Code for Part C

Listing 6: Code for Part D


Listing 7: main function calling the other functions
6​ Graphs
6.1​ Part A

The graphs in Figure 1a show the Magnitude Response and Figure 1b shows the Phase Response of
the DFT X[k] of the signal input signal x[n].

(a)​ Magnitude Response

(b)​ Phase Response

Figure 1: DFT X[k] of input signal x[n]


6.2​ Part D

The graph in Figure 2a shows the Magnitude Response and Figure 2b shows the Phase Response of
the FFT X2[k] of the signal input signal x[n].

(a)​ Magnitude Response

(b)​ Phase Response

Figure 2: FFT X2[k] of input signal x[n]


7​ Observations
1.​ The result of IDFT x2[n] matches with the input signal x[n] within domain of floating- point
error.

Figure 3: Input signal x[n]


Figure 4: IDFT x2[n] of X[k]
2.​ The discrete Fourier transform calculated using DFT formula and FFT match within
floating-point error bounds. Their magnitude and phase responses have been plotted above in
Figure 1 and Figure 2. (PS: The phase responses don’t match at k=8 due to floating point error
around 0. The value is a very small positive float in one and negative in other. Hence, the
phases come as −π and π.)
3.​ For Part C, the first signal taken is x[n] (same as shown above, used in Part A). The second
signal h[n] taken is shown below (Figure 8). The value of convolution of x[n] and h[n] is
computed and as shown below in Figure 11:
Figure 5: DFT X[k] of x[n]
Figure 6: FFT X2[k] of x[n]
Figure 8: Signal h[n]
ΣN−1
Figure 11: y[n] = x[i]h[n − i] = IDFT(X[k]H[k])[n]

4.​ DFT algorithm requires a nested loop with two stages, each of length n. In each iteration of the
outer loop, there are n iterations of the inner loop. If we consider the time taken for each
innermost loop’s iteration to be c, then the total time taken for the nested loop to run is cn2.
Other operations in the algorithm are of constant running time.
Therefore the running time of the algorithm is of the order of n2

5.​ For the FFT algorithm, of the time taken for the algorithm to run for a signal of length
n is given by T (n), then the recursive equation for the running time is given by

T (n) = c1(n/2) + 2T (n/2) + 2c2n/2 + c3(n/2) (10)


= 2T (n/2) + C(n)

From the equation we obtain T (n) to be of the form pnlogn where p is a constant.
8​ Result
1.​ The Discrete Fourier Transform (DFT) has been computed for the sequence \( x[n] \), with its
magnitude and phase response shown in the Graphs section (Figure 1).

2.​ The Inverse Discrete Fourier Transform (IDFT) has been calculated, and the results are
presented in the observations (Figure 4). The reconstructed signal closely matches the original
input within acceptable error bounds.

3.​ Time-domain convolution has been successfully performed using DFT and IDFT, as
demonstrated in the observations (Figure 11).

4.​ The Fast Fourier Transform (FFT) algorithm has been implemented correctly, as explained in
previous sections. The DFT obtained using FFT aligns with the one derived from the standard
DFT formula in Part A. The corresponding magnitude and phase response are displayed in the
Graphs section (Figure 2).

5.​ A comparison of execution times between DFT and FFT reveals that FFT is more efficient,
achieving a lower computational time than DFT.

You might also like