Skip to main content

How to Plot a FFT Plot of a Signal in MATLAB

 

MATLAB Code 

clc;
clear all;
close all;
fs = 1000; % Sampling frequency
dt = 1/fs; % Sampling period
L = 1500; % Length of signal

t=( (0:L-1)-ceil((L-1)/2) )*dt ; % Time vector

x = 0.7*sin(2*pi*400*t);

[X,freq]=continuousFTsamples(x,dt);

tiledlayout(1,2)
nexttile
plot(t,x); axis square; xlabel 'Time (sec)'; ylabel 'x(t)'
nexttile
plot(freq,abs(X)); axis square; xlabel 'Freq. (Hz)'; ylabel 'X(f)')

function [X,freq]=continuousFTsamples(x,dt,varargin)

X=fftshift( fft( ifftshift(x), varargin{:} ) )*dt;

L=numel(X);

df=1/L/dt;

freq=( (0:L-1)-ceil((L-1)/2) )*df;

end
 

Output

 


How long will the above process will work properly

 Restrictions

As here sampling frequency is equal to 1000. So the highest frequency available in the message signal must be equal or below half of the sampling frequency.
 

 If the frequency of the message signal is equal to 499 (half of sampling frequency = 500 Hz)

 
If the frequency of the message signal is equal to 500 (half of the sampling frequency = 500 Hz)
 

If the frequency of the message signal is equal to 1000 (when half of the sampling frequency = 500 Hz)


 Copy the above MATLAB Code from Here

 

People are good at skipping over material they already know!

View Related Topics to







Contact Us

Name

Email *

Message *