Updated March 13, 2023
Introduction to Fourier Transform in Matlab
Matlab is a programming environment that is interactive and is used in scientific computing. It is extensively used in a lot of technical fields where problem-solving, data analysis, algorithm development, and experimentation are required. Software that is discipline-specific is extensively written using MATLAB.
In this article, we will study the Matlab function used to calculate the Fourier transform. Before we get into details of how Fourier function works in Matlab, let us refresh our understanding of the Fourier transform.
The Fourier Transform uses a time-based pattern and measures every probable cycle of a signal. It then returns amplitude, rotation speed, and offset for each cycle that it found. In simpler terms, it returns significant features of signals called frequency components.
Let us understand the syntax of the Fourier function in Matlab.
Fourier (f)
Description of Fourier function in Matlab:
Fourier (f) returns the Fourier transform of input signal ‘f’.
Examples
Let us now understand the Fourier function in MATLAB with the help of a few examples
Example #1
In the first example, we will compute Fourier transform of a sine function using Fourier (f):
Lets us take a sine signal defined as:
3 * sin (4 * t)
Mathematically, the output of this signal using Fourier transform will be :
-pi * (dirac (w - 4) – dirac (w + 4)) * 3i
considering that transform is taken with ‘w’ as transformation variable.
Syntax:
syms t [Initializing the variable]
f = 3*sin (4*t); [Input sine function]
Ft = fourier (f) [Using the fourier function to get the fourier transform]
This is how our input and output will look like in the Matlab console:
Input:
Output:
As we can see, the transform is in terms of variable ‘w’ and the output is as expected by us.
Example #2
Here is an example where we compute Fourier transform of a cosine signal using Fourier (f):
Lets us take cosine signal defined as:
Cos (4*t) + cos (t);
Mathematically, our output should be:
pi* (dirac (w - 1) + dirac (w + 1)) + pi* (dirac (w - 4) + dirac (w + 4))
Syntax:
syms t[Initializing the variable]
f = cos (4*t) + cos (t); [Input cos function]
Ft = fourier (f)[Using the fourier function to get the fourier transform]
This is how our input and output will look like in the Matlab console:
Input:
Output:
As we can see, the Fourier transform is calculated w.r.t ‘w’ and the output is as expected by us.
Example #3
In the next example we will compute Fourier transform of an exponential function using Fourier (f):
Lets us take an exponential function defined as:
exp (-a ^ 2);
Mathematically, our output should be:
pi^(1/2) * exp (-w^2/4)
Syntax:
syms a [Initializing the variable]
f = exp (-a^2);[Input exponential function]
fourier (f)[Using the fourier function to get the fourier transform]
This is how our input and output will look like in the MATLAB console:
Input:
Output:
As we can see, the Fourier transform is calculated w.r.t ‘w’ and the output is as expected by us.
Example #4
Now, what if we have a matrix of input signals. In such cases, the Fourier function will calculate the transform of each element of the array individually.
Below is the example where we calculate Fourier transform of a matrix containing 4 elements using Fourier (f):
Lets us define our matrix as:
Z = [sin (a) cos (b); 1 exp (-a^2)]
Now for each element in the matrix, we need to pass transformation & independent variables.
Let us define our independent variable as: Variables = [w a; b c];
And Transform variables as: Transfrom_Variables = [p q; r s];
Mathematically, our output should be:
[ 2*pi*sin (a)*dirac (p), 2*pi*cos (b)*dirac (q)]
[ 2*pi*dirac (r),pi^ (1/2)*exp (-s^2/4)]
Syntax:
syms a b c w p q r s [Initializing the variables]
Z = [sin(a) cos(b); 1 exp(-a^2)];[Input matrix with different signals]
Variables = [w a; b c]; [Independent variables]
Transfrom_Variables = [p q; r s]; [Transformation variables]
Fourier (Z, Variables, Transfrom_Variables)
This is how our input and output will look like in the Matlab console:
Input:
Output:
As we can see, we have got the Fourier transform of every element in the matrix Z.
Conclusion – Fourier Transform Matlab
Fourier function is used in MATLAB to calculate the Fourier transform of a signal. We can calculate the Fourier transform w.r.t to the default transformation variable ‘w’ or the variable we define as the transformation variable.
Recommended Articles
This is a guide to Fourier Transform Matlab. Here we discuss the Introduction, examples with code implementation respectively. You may also have a look at the following articles to learn more –