clf;
fs=20;N=29; %采样频率和数据点数
n=0:N-1;
t=n/fs; %时间序列
x=[412,485,554,564,539,599,621,547,448,375,330,293,271,233,207,190,183,157,164,134,144,144,198,219,290,372,370,354,360];
y=fft(x,N);%对信号进行快速Fourier变换
mag=abs(y); %求得Fourier变换后的振幅
f=n*fs/N; %频率序列
subplot(2,2,1),plot(f,mag); %绘出随频率变化的振幅
xlabel('频率/Hz');
ylabel('振幅');
title('N=29');
grid on;
subplot(2,2,2),plot(f(1:N/2),mag(1:N/2));%绘出Nyquist频率之前随频率变化的振幅
xlabel('频率/Hz');
ylabel('振幅');
title('N=29');
grid on;
fs=20;N=29; %采样频率和数据点数
n=0:N-1;
t=n/fs; %时间序列
x=[412,485,554,564,539,599,621,547,448,375,330,293,271,233,207,190,183,157,164,134,144,144,198,219,290,372,370,354,360];
y=fft(x,N);%对信号进行快速Fourier变换
mag=abs(y); %求得Fourier变换后的振幅
f=n*fs/N; %频率序列
subplot(2,2,1),plot(f,mag); %绘出随频率变化的振幅
xlabel('频率/Hz');
ylabel('振幅');
title('N=29');
grid on;
subplot(2,2,2),plot(f(1:N/2),mag(1:N/2));%绘出Nyquist频率之前随频率变化的振幅
xlabel('频率/Hz');
ylabel('振幅');
title('N=29');
grid on;