门函数的傅里叶变换的 MATLAB 代码
时间: 2024-03-27 21:26:34 浏览: 10
function [F, Mag] = rectangular_pulse_fourier_transform(T, N, A)
% T: pulse width
% N: number of samples
% A: amplitude of the pulse
% Time domain
t = linspace(-T/2, T/2, N);
x = A*rectangularPulse(-T/2, T/2, t);
% Fourier Transform
F = linspace(-1/T, 1/T, N);
X = fftshift(fft(x))/N;
Mag = abs(X);
% Plotting
subplot(2,1,1)
plot(t, x)
xlabel('Time (s)')
ylabel('Amplitude')
title('Rectangular Pulse')
subplot(2,1,2)
plot(F, Mag)
xlabel('Frequency (Hz)')
ylabel('Magnitude')
title('Fourier Transform of Rectangular Pulse')
xlim([-1000 1000]) % Optional depending on the range of frequencies you want to see
end
% Rectangular Pulse function
function y = rectangularPulse(a, b, t)
y = (t>=a) & (t<=b);
end