Take the fft of a rectangular pulse

2 views (last 30 days)
Worstcareontario
Worstcareontario on 5 Oct 2015
Edited: Walter Roberson on 5 Oct 2015
I am trying to plot the fft of a rectangular pulse 'x(t)' and I know that the answer should be a sinc function however that is not what my plot looks like. Perhaps I made an error in my code
clear,clc
ts=10e-3;
t=-2:ts:2;
x=heaviside(t+1)-heaviside(t-1);
fmax=1/ts;
fs=1/4;
freq=0:fs:(fmax);
figure(1)
plot(t,x)
axis([-2 2 -1.5 1.5])
grid 'on'
figure(2)
X=fft(x)/length(x);
plot(freq,X)

Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!