Lab4_Report-2-2-2-2
Lab4_Report-2-2-2-2
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 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
In frequency domain the convolution of the two signals corresponds to multiplication of the Fourier
transforms of the two signals, given by
where X(k) and H(k) are the Fourier transforms of x[n] and h[n] respectively.
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
Due to periodicity of the exponential, we can also simplify the expression for Xk+N/2 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
5 Code
Listing 1: Custom struct defined for handling complex numbers in header file complex.h
Listing 2: Implementation of complex.h
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].
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].
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
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.