2016-04-30 115 views
1

我嘗試模擬噪聲信號並對其進行濾波。信號混合一些低頻信號和一些隨機噪聲。我的目標是獲得14.8Hz的信號。 我的帶通帶寬是14.7Hz到14.9Hz。matlab帶通濾波器不工作

function filteringTest 

Hd = KaiserFilter; 


Fs = 4000;     % Sampling frequency 
T = 1/Fs;      % Sample time 
L = 40000;      % Length of signal 
t = (0:L-1)*T;    % Time vector 


r1 = 320; 
r2 = 575; 

y = 50*sin(2*pi*14.8*t) + r1*sin(2*pi*14.7*t) + r2*sin(2*pi*15.1*t) + 10.1*rand(size(t)); 
yfilter = filter(Hd.Numerator,1,y); 
plot(yfilter) 



function Hd = KaiserFilter 

Fs = 4000; % Sampling Frequency 

N = 4096;  % Order 
Fc1 = 14.7;  % First Cutoff Frequency 
Fc2 = 14.9;  % Second Cutoff Frequency 
flag = 'scale'; % Sampling Flag 
Beta = 0.5;  % Window Parameter 
% Create the window vector for the design algorithm. 
win = kaiser(N+1, Beta); 

% Calculate the coefficients using the FIR1 function. 
b = fir1(N, [Fc1 Fc2]/(Fs/2), 'bandpass', win, flag); 
Hd = dfilt.dffir(b); 

我的信號圖像: Original Signal

和過濾結果是: Filtered Signal

當我試圖增加濾波器階數從4096到32 * 4096,我得到這樣的結果: Filtered Signal

爲什麼此過濾器無法正常工作?我要過濾我的過濾方法嗎? 我應該怎麼做才能獲得14.8Hz的頻率信號?

謝謝。

回答

1

爲什麼你的採樣率如此之高?降低您的採樣率並使用陷波濾波器取出選擇頻率。我已經重新編寫代碼的某些部分:

Fs = 200; 
desiredFrequency = 14.8; 
[b,a] = NotchFilter(Fs, desiredFrequency) 

在過濾器定義,你可以這樣做:

function [b,a] = NotchFilter(Fs,desiredFrequency) 
w = desiredFrequency/(Fs/2); 
[b,a] = iirnotch(w,w/400); 

現在進行濾波,

y_filter = filtfilt(b,a,y); 
desiredSignal = y-y_filter; 
plot(desiredSignal,'LineWidth',2); hold on; plot(y,'LineWidth',2) 

你會看到像這樣的東西。

enter image description here

+0

非常感謝。這行得通! –