clcfs=input('请输入信号的频率:fs=');fc=5;%抽样平率5Hzx=(0:1/fs:2);n=(fs*2)+1;y1=sin(2*pi*fc*x);%原正弦信号,频率为10a=0;b=0.5;%均值为a,方差为b^2subplot(2,2,1);plot(x,y1,'m');title('y=sin(20pi*x)');ylabel('y轴');xlabel('x轴');grid;y2=a+b*randn(1,n);%高斯白噪声subplot(2,2,2);plot(x,y2,'g');title('N(0,0.25)的高斯白噪声');ylabel('y轴');xlabel('x轴');grid;y=y1+y2;%加入噪声之后的信号subplot(2,2,3);plot(x,y,'r');title('叠加了高斯白噪声的sinx');ylabel('y轴');xlabel('x轴');grid;FY=fft(y);%傅里叶变换得出频谱函数FY1=fftshift(FY);%频谱校正f=(1:n)*fs/n-fs/2;subplot(2,2,4);plot(f,abs(FY1),'b');title('函数频谱图');ylabel('F(jw)');xlabel('w');grid;d;