先用上述代码生成一个1Hz,1.5s的采样信号。
然后我们加入一个正常的幅值0.7频率120的正弦波信号
- S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
为该信号加入零均值白噪声,方差为4
- X = S + 2*randn(size(t));
画出时域上的噪声信号
- plot(1000*t(1:50),X(1:50))
- title('Signal Corrupted with Zero-Mean Random Noise')
- xlabel('t (milliseconds)')
- ylabel('X(t)')
计算该信号的FFT
计算双边谱P2,然后计算单边谱P1和均值信号长度L
- P2 = abs(Y/L);
- P1 = P2(1:L/2+1);
- P1(2:end-1) = 2*P1(2:end-1);
定义时域f,并画出P1
- f = Fs*(0:(L/2))/L;
- plot(f,P1)
- title('Single-Sided Amplitude Spectrum of X(t)')
- xlabel('f (Hz)')
- ylabel('|P1(f)|')
对原信号进行傅里叶变换
- Y = fft(S);
- P2 = abs(Y/L);
- P1 = P2(1:L/2+1);
- P1(2:end-1) = 2*P1(2:end-1);
- plot(f,P1)
- title('Single-Sided Amplitude Spectrum of S(t)')
- xlabel('f (Hz)')
- ylabel('|P1(f)|')