Fs = 1000; % Sampling frequency 采样频率
T = 1/Fs; % Sample time 采样周期
L = 1000; % Length of signal 信号长度(点的个数)
t = (0:L-1)*T; % Time vector 时间向量(序列)(用来画图)
% Sum of a 50 Hz sinusoid and a 120 Hz sinusoid 一个 50 赫兹正弦加上 120 赫
兹正弦
x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
y = x + 2*randn(size(t)); % Sinusoids plus noise 正弦之和加上正态噪
声
figure(1);
plot(Fs*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')%被零均值噪声祸
害的信号
xlabel('time (milliseconds)')
%It is difficult to identify the frequency components by looking
at the original signal. Converting to the frequency domain, the
discrete Fourier transform of the noisy signal y is found by taking
the fast Fourier transform (FFT):
%从时域上直接看原信号难以确定各频率分量. 通过使用快速傅里叶变换 FFT, 实现了
含噪声信号 Y 的离散傅里叶变换,从而把信号转换到频域上(确定频率分量)
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
figure(2);
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
A=xlsread('SHUJU2.xlsx') ; %这里的 SHUJU1.xlsx 是数据
FS=1000; % FS 是采样率
T=1/FS;
L=length(A)