Lab4_Report-2-2-2-2-2-1-9
Lab4_Report-2-2-2-2-2-1-9
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].