以下Matlab腳本用於濾波由50 Hz和120 Hz正弦波組成的信號。我正在計算rad/s的頻率爲Fp =(2 * PI * 30)/1000=0.184。 我一直保持fp = 0.184和fst = 0.185,因爲我想過濾出50赫茲和120赫茲。 但是,當我繪製濾波器輸出的FFT時,我得到的是50赫茲的正弦波。爲什麼這個50Hz正弦波即使在濾波後也會出現?低通濾波器無法按預期工作
理想情況下,劇情中不應該有任何高峯。
之前濾波後過濾
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sample time
L = 1000; % Length of signal
t =(0:L-1)*T; % Time vector
x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t); % Sum of a 50 Hz sinusoid and a 120 Hz sinusoid %
y = x + 2*randn(size(t)); % Sinusoids plus noise
y = x ;
plot(Fs*t(1:50),y(1:50));title('Signal');xlabel('time (milliseconds)')
%pause;
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.
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)');xlabel('Frequency(Hz)');ylabel('|Y(f)|')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Now let us see Low Pass Filtering of this signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Fp= (2*pi * 30)/1000; %=0.184 %only frequncies less than 30Hz will be passed
d=fdesign.lowpass('Fp,Fst,Ap,Ast',0.184,0.185,2,60);
designmethods(d);
Hd = design(d,'equiripple'); fvtool(Hd);
Filterd_Output = filter(Hd,y);
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Filtered_Freq = fft(Filterd_Output,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
plot(f,2*abs(Filtered_Freq(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of Low Pass Filtered_Output')
xlabel('Frequency (Hz)');ylabel('|Filtered_Freq_Amplitude|')
更新 作爲建議我比較了filterd一個原始光譜。這解釋了我很多。但是有沒有辦法讓我可以進一步降低50赫茲的峯值功率?
你比較過以前的圖嗎? 「峯值」的大小隻有0.035,也許與原始大小相當,但也可能是小得多,因此被過濾? – Dan 2013-02-27 12:52:58
另外你的代碼很難閱讀,請添加一些換行符,它很難看到什麼是代碼和什麼是評論 – Dan 2013-02-27 12:53:55
@Rasman:感謝您的編輯! – gpuguy 2013-02-27 13:38:59