Discrete Fourier Transform and its Inverse using MATLAB


Discrete Fourier transform and Inverse discrete Fourier transform are two mathematical operations used to analyze functions and signals in the frequency domain. Both DFT and IDFT are widely used in the field of digital signal processing to synthesize and analyze the digital signals. Let's discuss a bit more about the Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT) individually.

What is Discrete Fourier Transform (DFT)?

In mathematics, the discrete Fourier transformation (DFT) is a transformation technique that is used to convert a sequence of discrete datapoints from time domain to frequency domain.

DFT basically converts a sequence of discrete data points represented in the time domain into a sequence of complex numbers represented in the frequency domain. Therefore, the discrete Fourier transform is a mathematical technique used to represent a digital signal as a sum of sinusoidal components at different frequencies.

The standard equation to calculate the discrete Fourier transform of a sequence in time domain is given by,

$$\mathrm{X(k)=\displaystyle\sum\limits_{n=0}^{N−1} x(n).e^{−j^\frac{2{\pi}nk}{N}}}$$

Where, x(n) is the input sequence in time domain, X(k) is the output sequence in the frequency domain, and N is the length of the input sequence.

Now, let us get a brief overview of Inverse Discrete Fourier Transform (IDFT).

What is Inverse Discrete Fourier Transform (IDFT)?

The inverse discrete Fourier transform (IDFT) is a mathematical operation that is used to convert a digital signal represented in the frequency domain into the time domain. Therefore, the inverse discrete Fourier transform is simply a reverse operation of the discrete Fourier transform (DFT).

The inverse discrete Fourier transform is mainly used to recover the original signal from the frequency domain signal.

Mathematically, the inverse discrete Fourier transform is calculated by using the following standard equation,

$$\mathrm{X(n)=\frac{1}{N}\displaystyle\sum\limits_{k=0}^{N−1} x(k).e^{j^\frac{2{\pi}nk}{N}}}$$

Hence, the Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT) are two correlated mathematical operations widely used in the field of engineering and technology for signal processing, image processing, filtering, noise reduction, and to perform many other tasks.

Now, let us discuss how to calculate discrete Fourier transform and inverse discrete Fourier transform using MATLAB.

How to Find Discrete Fourier Transform using MATLAB?

In MATLAB, it is very easy to find the discrete Fourier transform (DFT) of a given digital signal. We can use MATLAB's built-in function 'fft' to find the discrete Fourier transform of a given signal.

The step-by-step process to find the discrete Fourier transform (DFT) of a given signal is explained below −

  • Step (1) − Define or create or import the input signal.

  • Step (2) − Use the 'fft' function to calculate the discrete Fourier transform of the signal.

  • Step (3) − Create a frequency axis to plot the magnitude and phase spectrums.

  • Step (4) − Plot the magnitude spectrum of the DFT.

  • Step (5) − Plot the phase spectrum of the DFT.

Example (1)

Now, let us consider some examples to calculate the discrete Fourier transform of a given input signal using MATLAB.

% MATLAB program to calculate the DFT of a signal
% Create a sample signal
fs = 500;	% Sampling frequency of the signal in Hz
T = 1/fs;	% Sampling period of the signal in seconds
N = 500;	% Length of the signal
t = (0:N-1)*T;	% Time vector
f = 50;		% Frequency of the input signal in Hz
x = cos(2*pi*f*t);	% A cosine signal wave

% Calculate the discrete Fourier transform of x
X = fft(x);

% Create a frequency axis
F = fs*(0:(N/2))/N;

% Plot the magnitude spectrum of DFT
MS = 2*abs(X(1:N/2 + 1))/N;  % Calculating the magnitude spectrum
figure;
plot(F, MS);
title('Magnitude Spectrum of DFT');
xlabel('Frequency (in Hz)');
ylabel('Magnitude');

% Plot the Phase Spectrum of DFT
PS = angle(X(1:N/2 + 1));	% Calculating the phase spectrum
figure;
plot(F, PS);
title('Phase Spectrum of DFT');
xlabel('Frequency (in Hz)');
ylabel('Phase');

Output

(1). Magnitude Spectrum of DFT −

(2). Phase Spectrum of DFT −

Example (2)

Let us consider another example program to calculate the discrete Fourier transform of a randomly generated input signal.

% MATLAB program to calculate the DFT of a random sequence
% Create a random input sequence
N = 200;	% Length of the input sequence
x = randn(1, N); 

% Calculate the DFT of the sequence x
X = fft(x);

% Create the frequency
F = (0:N-1) / N;

% Plot the magnitude spectrum of the DFT
MS = abs(X);	% Calculating the magnitude spectrum
figure;
stem(F, MS);
title('Magnitude Spectrum of DFT');
xlabel('Frequency');
ylabel('Magnitude');

% Plot the phase spectrum of DFT
PS = angle(X);	% Calculating the phase spectrum
figure;
stem(F, PS);
title('Phase Spectrum of DFT');
xlabel('Frequency');
ylabel('Phase');

Output

(1). Magnitude Spectrum of DFT −

(2). Phase Spectrum of DFT −

Let us now explore how to find the Inverse Discrete Fourier Transform (IDFT) using MATLAB.

How to Find Inverse Discrete Fourier Transform?

In MATLAB, there is a built-in function 'ifft' that is used to calculate the inverse discrete Fourier transform of a given sequence in frequency domain.

The step-by-step process to calculate the inverse discrete Fourier transform of a frequency domain sequency is explained as follows −

  • Step (1) − Create or import a sequence in frequency domain.

  • Step (2) − Calculate the inverse discrete Fourier transform using the 'ifft' function.

  • Step (3) − Plot the real and imaginary parts of the reconstructed signals.

Hence, the process of finding inverse discrete Fourier transform using MATLAB is a straightforward process.

Example (3)

Now, let us consider some examples to understand how to calculate the inverse discrete Fourier transform of a given sequence in the frequency domain.

% MATLAB program to find the IDFT of a random sequence
% Create a sample random sequence in frequency domain 
N = 200;	% Length of the sequence
X = randn(1, N) + 1i * randn(1, N); % Random sequence in frequency domain

% Calculate the inverse discrete Fourier transform
x = ifft(X);	% Reconstructing the original sequence

% Creating a time axis
t = 0 : N-1;

% Plot the real part of the reconstructed sequence in time domain
subplot(2, 1, 1);
stem(t, real(x));	% Plotting the real part of sequence
title('Real Part of Reconstructed Signal');
xlabel('Time');
ylabel('Amplitude');

% Plot the imaginary part of the reconstructed sequence in time domain
subplot(2, 1, 2);
stem(t, imag(x));	% Plotting the imaginary part of sequence
title('Imaginary Part of Reconstructed Signal');
xlabel('Time');
ylabel('Amplitude');

Output

Conclusion

This is all about Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT), and their computation using MATLAB. Both DFT and IDFT are powerful mathematical tools used in digital signal processing. DFT allows us to convert a time-domain sequence into a frequency domain sequence, whereas the IDFT allows us to convert a frequency-domain sequence into a time-domain sequence.

In MATLAB, we can perform DFT and IDFT by using the built-in functions 'fft' and 'ifft' respectively. Overall, MATLAB provides a straightforward way of finding the DFT and IDFT of given sequences by using simple built-in functions. In the above sections of this article, we have described how to calculate the DFT and IDFT using MATLAB.

Updated on: 06-Sep-2023

692 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements