Using fft with rectangularPulse

22 ビュー (過去 30 日間)
Taylor Artunian
Taylor Artunian 2020 年 3 月 5 日
回答済み: Samra Shazadi 2022 年 2 月 10 日
I have created the following script to plot a rectangular pulse, the magnitude of the Fourier transform and the phase of the transform.
% Plot Fourier Transform
f=@(t) rectangularPulse(-1,1,t);
time=-6:0.01:6;
pulse=f(time);
fourier=fft(pulse);
figure()
subplot(3,1,1)
plot(time,pulse) % Pulse
subplot(3,1,2)
plot(time,real(fourier)); % Magnitude of Fourier
subplot(3,1,3)
plot(time,imag(fourier)); % Phase of Fourier
I know that the Fourier transform of a rectangular pulse is a sinc function but the output I get is not.

採用された回答

Star Strider
Star Strider 2020 年 3 月 5 日
It is now:
f=@(t) rectangularPulse(-1,1,t);
time=-6:0.01:6;
Fs = 1/0.01;
Fn = Fs/2;
Freq = linspace(-Fn, Fn, numel(time));
pulse=f(time);
fourier=fft(pulse);
figure()
subplot(3,1,1)
plot(time,pulse) % Pulse
subplot(3,1,2)
plot(Freq,fftshift(real(fourier))); % Magnitude of Fourier
xlim([-10 10]) % (Optional)
subplot(3,1,3)
plot(Freq,fftshift(unwrap(angle(fourier)))); % Phase of Fourier
xlim([-10 10]) % (Optional)
Use fftshift to centre the amplitude and phase plots.
I also calculated the frequency vector for the ‘fourier’ plots.

その他の回答 (1 件)

Samra Shazadi
Samra Shazadi 2022 年 2 月 10 日
a = 0.3;
t=[-2:0.01:2];
x = rectpuls(t, a); %rectangle waves
subplot(2,1,1); %subplot for rectangle waves
plot(t,x);
axis([-1 2 0 2]);
title("Rectangle waves");
xlabel('time');
ylabel('Value');
X=fft(x);
subplot(2, 1, 2); %subplot for Frequency signal
plot(t, fftshift(abs(X)));
title("Frequency Signal");
xlabel('freq (Hz)');
ylabel('|Y(freq)|');

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by