function plot_fft(x,fs)
%x:待处理信号
%fs:采样率
%N:N点FFT
N = length(x);
y = fft(x);
y = abs(y);
f = (0:N-1)*fs/N;
figure,plot(f(1:N/2),y(1:N/2)*2/N),grid on,xlabel('f/Hz'),ylabel('|fft(x)|'),title('信号幅频特性'),grid on;
end
%% 测试代码
clc;
clear;
close all;
N=2048;%采样点数
fs=2048;%采样时间
t=(0:N-1)/fs;%时间采样序列
x=sin(2*pi*100*t);
plot_fft(x,fs)