FFT of a square pulse in MATLAB problem

Click For Summary

Discussion Overview

The discussion revolves around computing the Fourier transform of a square pulse using MATLAB's FFT function. Participants explore issues related to amplitude discrepancies in the output and provide alternative code examples to address the original poster's concerns.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • The original poster notes that the magnitude at the first frequency component of their FFT result is 2, while they expected it to be 10.
  • One participant suggests that the Nyquist frequency limitation may be a common source of confusion for users of the FFT function.
  • Another participant provides an alternative MATLAB code example for a non-periodic square pulse, claiming it will yield the correct amplitude and includes plots for the magnitude and phase spectrum.
  • There is a mention of the original question being several years old, but recent activity in the thread is acknowledged.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the cause of the amplitude discrepancy, and multiple approaches and perspectives are presented without resolution.

Contextual Notes

Some assumptions regarding the periodicity of the pulse and the implications of the Nyquist frequency are not fully explored, leaving potential gaps in understanding the results.

fysiikka111
Messages
41
Reaction score
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
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.[CODE lang="matlab" title="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)')[/CODE]
 
  • Like
Likes   Reactions: jedishrfu
Yes, we were doing spring cleaning on some old threads trying to provide meaningful content so your post is welcome.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 16 ·
Replies
16
Views
15K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K