FFT of a square pulse in MATLAB problem

In summary, the code is trying to compute the Fourier transform of a square pulse, but is giving a result of 2. The algorithm might be limited by the Nyquist frequency.
  • #1
fysiikka111
41
0
I am trying to compute the Fourier transform of a square pulse with MATLAB's FFT.
Code:
Matlab:
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
 
Last edited by a moderator:
Physics news on Phys.org
  • #3
It looks like the original question is several years old, but there is a recent reply.

Here is some Matlab code to demonstrate the FFT of a non-periodic square pulse. This will give you the correct amplitude. It will also plot the mag and phase spectrum.
FFT of Square Pulse:
ts=50;
t=-ts:.1:ts;
x=zeros(size(t));
x(450:550)=ones(1,101);
subplot(4,1,1)
plot(t,x)
axis([-ts,ts,-.1,1.1])
title('CONTINUOUS-TIME NON-PERIODIC PULSE SIGNAL x(t)  [duration 10 sec]')
xlabel('Time  t (sec)')
Tw=10;
fs=2;
f=[-fs:.005:-.005,1,.005:.005:fs];
X=(1./(pi*f)).*sin(pi*f*Tw);
X((length(f)-1)/2+1)=Tw;
f((length(f)-1)/2+1)=0;
subplot(4,1,2)
plot(f,X)
axis([-fs,fs,-3,12])
ylabel('Fourier Transform X(f)')
xlabel('Frequency f (Hz)')
subplot(4,1,3)
plot(f,abs(X))
axis([-fs,fs,-3,12])
ylabel('Magnitude Spectrum |X(f)|')
xlabel('Frequency f (Hz)')
subplot(4,1,4)
plot(f,angle(X))
axis([-fs,fs,-4,4])
ylabel('Phase Spectrum arg{X(f)} (rads)')
xlabel('Frequency f (Hz)')
 
  • Like
Likes jedishrfu
  • #4
Yes, we were doing spring cleaning on some old threads trying to provide meaningful content so your post is welcome.
 

Related to FFT of a square pulse in MATLAB problem

What is FFT and how does it work?

FFT stands for Fast Fourier Transform, and it is a mathematical algorithm used to convert a signal from its original domain (such as time) to a representation in the frequency domain. This allows us to analyze the frequency components of a signal and identify patterns or features that may not be easily visible in the time domain.

Why is FFT used for analyzing square pulses?

FFT is commonly used for analyzing square pulses because it allows us to break down the signal into its individual frequency components. This can help us identify any distortions or noise present in the signal and also allows us to accurately measure the amplitude and phase of the pulse.

How can I use MATLAB to perform FFT on a square pulse?

To perform FFT on a square pulse in MATLAB, you can use the built-in function fft(). This function takes in the pulse signal as an input and outputs a vector containing the frequencies and corresponding amplitudes of the signal in the frequency domain.

What are some common mistakes when performing FFT on a square pulse in MATLAB?

One common mistake is not properly preparing the signal before applying the FFT function. This can include not using the correct time interval or not properly zero-padding the signal. Another mistake is not understanding the output of the FFT function, which can lead to misinterpretation of the results.

What can I learn from analyzing the FFT of a square pulse in MATLAB?

Analyzing the FFT of a square pulse can provide insight into the frequency components present in the signal. This can help identify any noise or distortions in the signal and also aid in understanding the overall shape and characteristics of the pulse. FFT analysis can also be used for filtering, noise reduction, and other signal processing techniques.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
395
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
470
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
392
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
861
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
16
Views
14K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top