我想先生成一个噪声波,然后傅里叶级数逐渐提高谐波次数最终还原出噪声波,但是我生成的图像是分开的,想知道哪里错了
Um=2;%幅值
T=2;%周期
w=2*pi/T;
num_points=1000;
t=linspace(-T/2,T/2,num_points);%-T/2和T/2之间生成1000个等间距点的行向量
y=Um*abs(sin(2*w*t)).*(t>0)%在t>0的范围内产生干净信号
subplot(421),plot(t,y),grid on
n=randn(38,1)%产生38*1正态分布随机数的随机矩阵
n=[0;n;0];
n=interp1([0:39],n,linspace(0,39,num_points),'linear');%插值函数 linear——线性回归
y=y+0.4*n;
subplot(422),plot(t,y),grid on
a0=1/T*trapz(t,y)
n_max=[1,5,10,20];
N=length(n_max);
for k=1:N;
n=1:n_max(k)
y1=y.*cos(n'*pi*t);
y2=y.*sin(n'*pi*t);
an=2/T*trapz(t,y1,2);
bn=2/T*trapz(t,y2,2);
ft=a0+an.*cos(n'*pi*t)+bn.*sin(n'*pi*t);
subplot(4,2,k+2);
plot(t,ft),grid on;
title(['最大谐波次数=',num2str(n_max(k))]);
end