clc;clear all;close all;
fs=1000;%采样率1000,即1秒采集1000次
Tcycle==1/fs;%采样周期为0.001s
num=1000;%采样1001次
t=(0:num)*Tcycle;%时间序列
y1=0.7sin(50t2pi);
y2=sin(120t2*pi);
y=y1+y2;%+randn(size(t));
subplot(121);
plot(t,y);grid on;
Y=abs(fft(y)/num);Y=Y(1:floor(num/2)+1);
freq=fs*(0:0.001:0.5);
subplot(122);
plot(freq,Y);grid on;