# Basic signals DFT: Matlab Tutorial

|In previous posts, we have explained the theory behind the FFT and we already have practiced with the main properties of the DFT in Matlab.

In this post we will obtain the DFTs of the most common signals (pulses, sinusoidal, sinc signals…). Thanks to

**Matlab**, we can easily represent graphically the signals and their Fourier transforms; therefore, we will visualize a number of FFTs and we will pay attention to their characteristics.As you may now from our previous posts, the DFT is computed using the

**function fft in Matlab**. All the signals to work with the DFT are discreet so we will represent them in Matlab using the function stem; the DFT of these signals will be discreet too, so we will also use the function stem. As in many cases**the DFT can be complex**, we will need to represent the real and imaginary part separately and use the function subplot before running*stem*if we want to see them together.Now the

**first thing you need to do**is to download the code available in**Mathworks**and we will go through each exercise analyzing the output. You can find the code here: https://uk.mathworks.com/matlabcentral/fileexchange/57167-basic-signals-dft–matlab-tutorialYou may also want to use this DFT Pairs table to check the results that we will obtain.

## EXERCISE 1: PULSE SIGNALS

These signals contain just ones and zeros. Their DFT are complex numbers, so we will represent the absolute value which provide clearer information.

The first part of the code represent an impulse with amplitude equal 1. If you check the DFT of this signal (an impulse), you will find that the DFT is 1:

Figure 1. DFT of the impulse signal

Now, we are going to see the DFT of the previous signal:

Figure 2. DFT of the unit signal

As you can check, the

**duality property of the DFT**is met here, where we obtained that the DFT of the signal in Figure 2 is the signal in Figure 1 and the DFT of the signal in Figure 1, is the signal in the Figure 2.The next section of the code represents a shifted impulse. In this case, as you can check in the DFT properties, a delay in the time domain corresponds with the multiplication by a complex exponential in the frequency domain. Therefore, the DFT is complex and we represent the absolute value, which is the same unit signal displayed in Figure 1.

In the following bit of code, we will represent a rectangular signal of 3 points. If we represent the absolute value of the DFT, we will obtain a

**sinc signal**:Figure 3. DFT of the 3 points rectangle

Now, you have the code available to shift the previous rectangle and plot its DFT: what observation can you make from it? Leave a comment below and we will tell you our perspective! 😉

The first thing we do in this exercise is to represent one cycle of a cosine signal of 21 points:

Figure 4. Cosine cycle

then we calculate its DFT and represent its absolute value which, as you know, corresponds with 2 impulses:

Figure 5. DFT of the cosine cycle

What do you think is the frequency of the cosine?

Now, you have the code available to represent a sinusoidal of 3 cycles and its DFT with 21 points. By observing the DFT, can you tell what is the new frequency? What happens if you represent 3.1 cycles? Hint: have a look to our post about the FT properties and see what happen when the sampling is not accurate.

The complex exponential is defined as

*c[n]=e*for n=0,1,2 … N-1. Depending on the value that we choose for w^{ j}^{w0n}_{0},we will see different DFTs.In the first example provided in the code, we take w

_{0}= 6p/*N*and calculate the DFT for N=16 points. As you can observe, the absolute value of the DFT is an impulse signal:Figure 6. DFT of complex exponential with w

_{0}= 6p/*N*Now, try w

_{0}= 5p/*N*, why in this case you don’t see zeros in the DFT? Hint: have a look to our post about the FT properties and see what happen when the sampling is not accurate.As you now,

**by the duality property**, the an overlapping**sinc signal and the rectangular pulse form a FT pair**.In the code, you can see that we have created a rectangular pulse of 7 points using the function rectwin. Then, we have obtain its DFT with 16 points and we have obtained the following sinc signal:

Figure 7. DFT of a rectangular pulse: sinc signal

The last part in the code shows you what would happen if you calculate the DFT by using 21 points. What can you observe?

We hope you like this tutorial and in case of questions, leave a comment below or send an email tocontact@behindthesciences.com We will be glad to help you! Also, if you would like us to write a post/tutorial about an specific topic, let us know!