1,核心代码
Mm y;//采样信号
Mm t;//时间序列
Mm n;//采样序列
Mm f;//频率序列
int N;//采样点数
double fo;//信号频率
double fs;//采样频率
fo=3;//3Hz
fs=2.56*fo;
N=1024;
n=linspace(0,N-1,N);
f=n*fs/N;
t=n/fs;
y=sin(2*pi*fo*t)+0.5*cos(2*pi*fo/3*t); //两种信号频率分别为fo,fo/3
Mm m_line=plot((CL(f),abs(fft(y))*2.0/N));//FFT变换并绘图
title((CL(TM("fft"))));
xlabel((CL(TM("f(Hz)"))));
ylabel((CL(TM("y(A)"))));
set(h,(CL(TM("Box")),TM("on")));
set(h,(CL(TM("Color")),TM("white")));
set(m_line,(CL(TM("Color")),TM("red")));
grid();
drawnow();
2,运行结果