MATLAB Inverse Fast Fourier Transform

This tutorial will discuss finding the inverse fast Fourier transform using MATLAB’s ifft() function.

MATLAB Inverse Fast Fourier Transform

We can use the ifft() function of Matlab to find the inverse fast Fourier transform of a vector, matrix, or multidimensional array. The ifft() function has four syntaxes shown below.

Find the Inverse of a Function - P...
Find the Inverse of a Function - Part I
Out = ifft(X)
Out = ifft(X,n)
Out = ifft(X,n,dim)
Out = ifft(___,symflag)

The first syntax will return the inverse fast Fourier transform of input X using the fast Fourier transform algorithm. The ifft() function checks for the conjugate symmetric vectors present in the input X; if the vectors are conjugate symmetric, the output will be fast and real.

A vector is conjugate symmetric if the product of its anti-diagonal exchange matrix and its complex conjugate is equal to the original vector. In the case of a time-domain signal, its fast Fourier transform contains half positive frequencies spectrum and half negative frequency spectrum.

The input X can be a vector, matrix, or multidimensional array. The first syntax will return a vector containing the inverse fast Fourier transform of a vector in case the input is a vector, and the output vector will have the same length as the input vector.

If the input is a matrix, the syntax will return a matrix containing the inverse fast Fourier transform of the matrix’s columns, and the output matrix’s size will be the input matrix. If the input is a multidimensional array, the function will return the inverse fast Fourier transform of values along the first dimension, treating them as vectors.

The second syntax is used to add points on which we want to find the inverse fast Fourier transform as the second argument n. If we don’t add points, the function will use the element indices as points.

If the argument n is zero, the function’s output will be an empty matrix. If the argument length n is less than the length of the input vector or matrix, the ifft() function will ignore the remaining values.

If the argument length n is greater than the length of the vector or matrix, the function will add zeros between the input values, improving the function’s performance. The argument length n is typically the product of small prime numbers or a power of 2.

The third syntax is used to set the dimension as the third argument, dim, which is used to find the inverse fast Fourier transform in the case of a matrix and multidimensional array. For example, in the case of matrix input, the function will find the inverse fast Fourier transform of each column, but if we add 2 as the third argument, the function will return the inverse fast Fourier transform of each row.

The fourth argument is used to set the symmetry of the input as symmetric or nonsymmetric. If the input is not exactly symmetric, we can use this argument to set it to symmetric so that the function will treat the input as symmetric.

For example, let’s create a vector and find its fast Fourier transform using the fft() function, and then we will find the inverse fast Fourier transform using the ifft() function. See the code below.

clc
clear

n = [1 6 2]
fourier = fft(n)
inverse_fourier = ifft(fourier)

Output:

n =

     1     6     2


fourier =

   9.0000 + 0.0000i  -3.0000 - 3.4641i  -3.0000 + 3.4641i


inverse_fourier =

    1.0000    6.0000    2.0000

In the above code, we used a vector of three elements to find the Fourier and inverse Fourier transforms to check the result of the ifft() function. We can see in the output that the input vector n and the output of the ifft() function is the same, which means the function is working perfectly.

We can see in the output that the Fourier transform of the input vector n contains magnitude and phase, both of which are used to reconstruct the original signal. If we take out one part of the Fourier transform, like magnitude or phase, we will not be able to reconstruct the original signal.

We have to make sure the signal contains the magnitude and the phase before using the ifft() function to reconstruct the original signal. We also must ensure the signal is not shifted from its original position.

For example, we can use the fftshift() function to find the Fourier transform and shift the zero-frequency component to the center of the spectrum. We cannot reconstruct the original single properly if we use the ifft() function to find its inverse Fourier transform.

In this case, we can use the ifftshift() function instead of the ifft() function, and the ifftshift() function will find the inverse Fourier transform and shift the signal back to its original position.

The output will also change if we set the points using the second syntax shown above. For example, in the case of points length greater than the length of the input vector, the reconstructed signal will contain more elements than the original vector or matrix elements.

If we change the dimension of the ifft() function, the output will also change, and it might not match the original vector or matrix. For example, let’s repeat the above example and change the number of points used to take the inverse Fourier transform of the input vector.

See the code below.

clc
clear

n = [1 6 2]
fourier = fft(n)
inverse_fourier = ifft(fourier,4)

Output:

n =

     1     6     2


fourier =

   9.0000 + 0.0000i  -3.0000 - 3.4641i  -3.0000 + 3.4641i


inverse_fourier =

   0.7500 + 0.0000i   3.8660 - 1.6160i   2.2500 + 1.7321i   2.1340 - 0.1160i

We can see that the output of the ifft() function does not match with the input vector n because we have changed the number of points to 4, which was 3 by default. Check this link for more details about the ifft() function.