matlab怎么做fft频谱图

如题所述

clf;

fs=3800;N=38;   %采样频率和数据点数

n=0:N-1;t=n/fs;   %时间序列

x1=sin(2*pi*100*t); 

x2=sin(2*pi*200*t); 

x3=sin(2*pi*3800*t); 

y1=fft(x1,N);    %对信号进行快速Fourier变换

mag1=abs(y1);     %求得Fourier变换后的振幅

y2=fft(x2,N);    %对信号进行快速Fourier变换

mag2=abs(y2);     %求得Fourier变换后的振幅

y3=fft(x3,N);    %对信号进行快速Fourier变换

mag3=abs(y3);     %求得Fourier变换后的振幅

f=n*fs/N;    %频率序列

subplot(3,1,1),plot(f(1:N/2),mag1(1:N/2)); %绘出Nyquist频率之前随频率变化的振幅

xlabel('频率/Hz');

ylabel('振幅');title('f=100Hz');grid on;

subplot(3,1,2),plot(f(1:N/2),mag2(1:N/2)); %绘出Nyquist频率之前随频率变化的振幅

xlabel('频率/Hz');

ylabel('振幅');title('f=200Hz');grid on;

subplot(3,1,3),plot(f(1:N/2),mag3(1:N/2)); %绘出Nyquist频率之前随频率变化的振幅

xlabel('频率/Hz');

ylabel('振幅');title('f=3800Hz');grid on;

fft频谱图如下:

温馨提示:答案为网友推荐,仅供参考
相似回答