I am trying to compute the Fourier transform of a square pulse with MATLAB's FFT.(adsbygoogle = window.adsbygoogle || []).push({});

Code:

Fs=1000; %Sampling rate (Hz)

T=1/Fs; %Sampling time interval

P=10; %Period of pulse

t=0:1/Fs:P/2; %Time axis

N=length(t);

x=rectpuls(t,P); %Pulse amplitude

n=pow2(nextpow2(N)); %Number of frequency components

Y=fft(x,n);

freq=Fs/2*linspace(0,1,n/2+1);

subplot(1,2,1)

plot(t,x)

subplot(1,2,2)

plot(freq, 2/N *abs((Y(1 : n/2+1))));

xlim([0 2])

Magnitude at the first frequency component should be 10, but is giving a result of 2. Why is this occurring?

Thanks

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# FFT of square pulse in MATLAB problem

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**