t=0:0.002:0.25;
x=sin(2pi50t)+sin(2pi120t);
y=x+2*rand(size(t));
subplot(2,1,1);
plot(y(1:50));
title(' Noisy time domain signal');
Y=fft(y,256);
pyy=Y.conj(y)/256;%计算y的模的长度
f=1000/256(0:127);
subplot(2,1,2);
plot(f(1:50),pyy(1:50));
title(' power spectral density');
乘除法符号前面加个点