Fourier Transform in MATLAB

Hey fellows, Welcome to another lecture in the signal and systems series in which we are moving towards another transform. Till now, we have studied the Laplace and z transform and we, therefore, know the basic purpose of transforms, that is, to convert the signal from one domain to another. In today's lecture, we will be discussing the Fourier Transform, and you will enjoy its information because now we have a clearer idea of what we are doing and what the purpose of this transformation of a signal is. Here are the key points that we are going to consider:

  1. What is the Fourier transform?

  2. What is the journey Fourier transforms from start to end?

  3. How do you define the types of Fourier transform?

  4. Why is the Discrete Fourier transform important?

  5. Why is the fast Fourier transforms named so?

  6. How can you implement a fast Fourier transform in MATLAB?

What is the Fourier Transform?

Just like the Laplace transform, the Fourier transform is also named so because of the name of its inventor. It is a 200 years old transform that is still in use in mathematical subjects in which there are minute calculations and the user wants to have accurate results in a simple way. The name of this transformation is taken from the French mathematician Jean-Baptiste Joseph Fourier. From 1807 to the current age, people found this transform useful, and when we talk about subjects like signals and systems, it becomes necessary to learn this because it is majorly used in the field of practical work. We define the Fourier transform as:

“The Fourier transform is a mathematical tool or model that is used to generalize the Fourier series in a simple way and is used to represent the calculator in the frequency domain.”

The definition must be clear in your mind because we have read about the transform before, but for a clear discussion, let me say that this transform is used to convert complex calculations into a simpler way by changing the domain of the values so that we may get the best results accurately in less time.

Mathematical Form of Fourier Transform

The complex Fourier series is converted into the one with the limit from minus infinity to plus infinity. The mathematical formula for this transform is given below:

At first, this formula may be confusing for you. But do not worry, when we discuss the details, you will get a clear idea. For now, keep in mind. This is also called the forward Fourier transform. We will also learn about the inverse FFT in the coming session. 

What is the Fourier Series?

You can see that we have taken the name of the Fourier series in the introduction given above. If you are new to this, let us recall.

“A Fourier series is the one in which the decomposition of periodic functions occurs and we get the sinusoidal components that have an infinite sum of sinusoidal functions.”

 It is important to introduce the Fourier series when solving the Fourier transform. Whereas a periodic function is the one that follows the formula given below:

f(t+T) = f(t)

It means that a periodic function has the same value before and after a certain period, and no change occurs after that period. 

The Story Behind the Fourier Transform

The story of Fourier's transform starts in 1807 when Jean-Baptiste Joseph Fourier found that he could represent the summation of sinusoidal functions that are sine and cosine. He worked hard on the same topic, and his work was published under the title "Analytic Theory of Heat" because he used his work to find the calculations of heat. Moreover, after this publication, scientists found that this theory can also work in other ways. It is possible to use the Fourier series of the amplitude of a sinusoidal function when the integer is used in this work. Hence, other studies were also used with the Fourier series and, as a result, many useful invasions and calculations occurred. 

Types of Fourier Transform

In computer-based applications, you will hear a lot about two types of Fourier Transforms:

  1. Discrete Fourier Transform or DFT

  2. Fast Fourier Transform or FFT

We will discuss both of them in detail.

Discrete Fourier Transform or DFT

We all know that discrete quantities are those with a non-continuous sequence. These are different ways to deal with signals, but when we talk about DFT, one must know that it is one of the most accurate and powerful tools to find the spectrum when dealing with finite duration signals. 

For instance, take the case in your mind, when we get the output of the LC oscillator, we get a sinusoidal wave, and we want to know the amount of noise in the output to find an accurate result, then we use the Discrete Fourier Transform. Just like digital filters, DFT is also a powerful tool to analyze the signals in the best way. 

Mathematically,

To make a clear difference between DFT and DTFT (you will learn more details soon), we have shown this equation with the variable X(k). Here, 

N =Total number of samples

j, k = variables

Pay heed to the formula and you will see that it consists of some finite numbers. Therefore, we can say that DFT is used to determine the spectrum of the sequence with a finite number of samples. 

Fast Fourier Transform

Here is another type of Fourier transform that, as the name implies, is a fast method of performing Fourier transforms. Have a look at the simplest definition of this simple Fourier transform:

“FFT is the type of Fourier transform that converts the signal into a single spectrum and, therefore, it provides the information about the frequency of that signal easily."

Let’s hear the story of the simple signal when it is fed into different procedures of FFT. 

  • First of all, the signal is decomposed into a complex N time domain signal that is a complex signal. This signal has two parts:

  1. Real part

  2. Imaginary part

  • Then different procedures occur at these parts. They are multiplied, and we get different chunks of information. 

  • After all the information from the N-1 number of samples is collected, the procedure to merge all the information into a specific pattern starts. 

  • Once we get the information in that particular sequence in the frequency domain, we use the calculations to get the final result. 

You might be wondering why this method is named "fast transform." Well, FFT is the form of DFT that skips some procedures, and in this way, we get a short form of the Fourier transform that is fast to perform. 

It is a fast algorithm that works on the rule of divide and conquers. It takes the signal and divides it into two smaller signals. In this way, it becomes easy to solve the signal. 

FFT in MATLAB

Code:

t=0:0.01:1;

x=sin(2*pi*15*t);

subplot(211)

plot(t,x)

xlabel('Time /The Engineering Projects.com')

ylabel('Amplitude')


FFT=fft(x,1024);

xabs=abs(FFT);

subplot (212)

plot(xabs)

ylabel('Amplitude')


Output:

The FFT Function in MATLAB

As you can guess, it is the pre-defined function to perform the Fourier Transform, and we just have to provide the parameters, and all the tasks and calculations are here in front of you in seconds. The syntax of the FFT function is given as

  1. fft(x)

  2. fft(x,y)

  3. fft(x,y, dim)

Where

x is the equation that we want to use to perform the FFT.

y represents the number of points for the DFT.

Dim is the dimension of the Fourier transform. If you have any, you can write them here. 

In our code, we have used the second form. It is up to you which kind of syntax you want to use. The more details you provide to MATLAB, the better results you will get. 

Abs function in MATLAB

Another function that we have used in MATLAB is the abs function called the absolute function. This function is used to have the absolute values in the MATLAB codes. The result we obtain from the fft function may have real and imaginary parts or it may also have some negative values in it that are complex to deal with. For our convenience and the accuracy of the result, the abs function converts it into the absolute value that has the positive integers and we get the accuracy in our answer. 

Explaining FFT in MATLAB

While looking deeply into the code given above, we can understand the concepts of the fast Fourier transform. Here is the flow of code through which we are performing it:

  • First of all, t specifies the time period at which the Fourier transform will be shown on the graph. Here, we have provided the starting point as 0 and the ending point as 1. The value between them is the period on the basis of which the shape of the wave will be shown. 

  • To store the equation of the Fourier transform, we have used the variable x. This is the basic question and as we all know, there is a compulsion to write the signs of arithmetic operations and brackets all the time. 

  • The result is then fed into the plot command where we specify the time on the x-axis and the value of the question that we have saved in the x variable is specified on the y-axis.

  • The whole work is done by the single function of fft. You just have to input the values and you will get the result. 

  • To improve the work of this transform, we are using the abs function. 

You can also use the same function without the plot and subplot commands if you do not want any graph. Take it as your homework and find what value you get when you simply put the value of x in the fft function. The results will be shown on the right side of the screen and each value can also be examined separately as we have specified in our code. 

Discrete-Time Fourier Transform

In addition to the two types, we also experience another type of mathematical tool named the Discrete Time Fourier Transform. At first, you may think it is DFT, as we have discussed before, but in reality, it is a slightly different form of Fourier Transform, and it is important to know about it so that you may clear some concepts. 

The Mathematical Form of DTFT

Once you get an idea of its application, you can understand the mathematical form of DTFT. If for a given spectrum of signals, we have the sequence named x(n) then the DFT of that particular sequence can be found with the help of this general formula given below:

Note that x(n) is in the form of time domain signals. whereas the resultant  X(ω) is in the form of a frequency domain with the complex variable ω that is omega.

There is a different notation on the same formula on the internet with different types of variables. So, do not be confused and get the core concept and apply it in your own way. 

The Difference Between DFT and DTFT



DFT

DTFT

Full Form

Discrete Fourier Transforms

Discrete-Time Fourier Transform

Continuity

Non-continuous Sequence

Continuous Sequence

Periodicity

Non-periodic

Periodic

Variable

It does not have any variables like omega.

It comes with a continuous variable called Omega.

Type of frequencies

It has only positive frequencies.

It contains both positive and negative frequencies.

Accuracy

Less accurate

More accurate

Today we have learned a lot about the Fourier transform and also seen some practical implementation of some types of Fourier transform. We have introduced the Fourier transform, learned about the type of this transform, and also saw the DTFT with the comparison of DFT. The code on the FFT was explained deeply where we had the details of its function and also saw the graph as a result. We have a lot of information about the Fourier transform, and we are going to discuss it in detail in our next session.

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir