matlab fft demo

clf;
fs=32;N=1024;   %采样频率和数据点数
n=0:N-1;
t=n/fs;   %时间序列
x=1*sin(t); %信号
y=fft(x,N);    %对信号进行快速Fourier变换
mag=abs(y);     %求得Fourier变换后的振幅
f=n*fs/N;    %频率序列
subplot(2,1,1),plot(t, x);   %绘出随频率变化的振幅
xlabel('频率/Hz');
ylabel('振幅');title('N=128');grid on;
subplot(2,1,2),plot(f(1:N/2),mag(1:N/2)); %绘出Nyquist频率之前随频率变化的振幅
xlabel('频率/Hz');
ylabel('振幅');title('N=128');grid on;

原文地址:https://www.cnblogs.com/zhang-pengcheng/p/4489349.html