I'm working on signal filtering in MATLAB. i wrote sample code that generate 50 Hz signal with some noisy frequency and use Kaiser bandpass filter to get only 50Hz frequency. this code work great! but there is a big problem!
Sample Rate is 2000 Hz and Filter Order is about 39000 , and my signal length is 50000 samples! in other hand i have to wait about 25 seconds to gathering my signal! that is too long time!, if i decrease signal length ( to about 6000 samples ) filter result is so noisy because of filter order. if i decrease filter order , filter signal result is too noisy too! the best time that i cloud wait for gathering data is about 3 seconds.
is there any way to get same result with 6000 samples of signal and high order filter? ( 39000 )
Fs = 2000; % Sampling frequency T = 1/Fs; % Sample time L = 50000; % Length of signal t = (0:L-1)*T; % Time vector Hd = KAISERFilter; for i=1:50 a = 5; b = 500; r1 = a + (b-a).*rand(1,1); r2 = a + (b-a).*rand(1,1); r3 = a + (b-a).*rand(1,1); r4 = a + (b-a).*rand(1,1); n = r1 *sin(2*pi*49.2*t) + r2 *sin(2*pi*50.5*t) + 0.1 * randn(size(t)) + r3 *sin(2*pi*15.5*t) + r4 *sin(2*pi*110*t) ; x = 30 *sin(2*pi*50*t); % main frequency y = x+n; subplot(2,1,1); plot(y) title('Signal') xlabel('time (milliseconds)'); yf = filter(Hd.Numerator,1,y);
and Kaiser filter code is :
function Hd = KieserFilter % All frequency values are in Hz. Fs = 2000; % Sampling Frequency Fstop1 = 49.5; % First Stopband Frequency Fpass1 = 49.9; % First Passband Frequency Fpass2 = 50.1; % Second Passband Frequency Fstop2 = 50.5; % Second Stopband Frequency Dstop1 = 1e-06; % First Stopband Attenuation Dpass = 0.057501127785; % Passband Ripple Dstop2 = 1e-06; % Second Stopband Attenuation flag = 'scale'; % Sampling Flag % Calculate the order from the parameters using KAISERORD. [N,Wn,BETA,TYPE] = kaiserord([Fstop1 Fpass1 Fpass2 Fstop2]/(Fs/2), [0 ... 1 0], [Dstop1 Dpass Dstop2]); % Calculate the coefficients using the FIR1 function. b = fir1(N, Wn, TYPE, kaiser(N+1, BETA), flag); Hd = dfilt.dffir(b);