Using fft with rectangularPulse

28 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by