How can I do the FFT of a rectpuls?

5 次查看(过去 30 天)
I know that the Fourier transform of a rectpuls is a sinc function. I'm able to plot a rectpuls using the command A*rectpuls(t,B), in witch "t" represent the time on x axis, "B" represent the a length of the base of the rectangle and "A" represent the amplitude. So, a possible MATLAB code to plot it could be:
t=-5:.01:5;
x=2*rectpuls(t,2);
plot(t,x)
Now, i would like to compute the FFT, obtaining a sinc function... How can I do this, using the command fft?
Thank you!

回答(1 个)

Star Strider
Star Strider 2016-3-14
This is how I would do it:
t=-5:.01:5;
x=2*rectpuls(t,2);
figure(1)
plot(t,x)
grid
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyuquist Frequency
L = length(x);
ftx = fft(x)/L; % Fourier Transform
ftxs = fftshift(ftx); % Shift To Centre
Fv = linspace(-Fn, Fn, L); % Frequency Vector
figure(2)
subplot(2,1,1)
plot(Fv, abs(ftxs)) % Plot Amplitude
grid
subplot(2,1,2)
plot(Fv, angle(ftxs)) % Plot Phase
grid
  5 个评论
Riccardo Barbero
Riccardo Barbero 2016-3-14
Ok, I understand! ;)
I don't know if you read my P.S...
Why, using your code, I obtain that the maximum amplitude of sinc is 0.4 (in f=0), instead of 4 (as the area of the rectangle)?
Thank you for your patience
Star Strider
Star Strider 2016-3-14
I overlooked your P.S. before, probably because you posted it while I was writing my previous Comment.
The amplitude of the sinc function calculated with the Fourier transform is correct. The power of the Fourier transformed signal is equal to the power of the time-domain signal, as stated in Parseval’s theorem. I invite you to explore that on your own.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by