# bandpass filter not working in matlab

Status
Not open for further replies.

#### fences

##### Junior Member level 3
I try to simulate a noisy signal and Filter it. the signal mix some low frequency signals and some random noise. my goal is to get 14.8Hz signal. my band-pass bandwidth is 14.7Hz to 14.9Hz.

Code:
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);

my signal image is :

and filter result is :

when i try to increase Filter Order from 4096 to 32*4096 , i get this result :

why this filter do not work correct? do i chage my filtering method? what should i do to get 14.8Hz frequency signal?

thanks.

#### BradtheRad

##### Super Moderator
Staff member
Did you test your filter on sinewaves at just one frequency? That should make it easier to check the response.

Can you find sample code of a bandpass filter? Start with that, then change it to suit your specs.

It looks like a big jump to change from 4096 to 32*4096. Did you try values in between?

#### fences

##### Junior Member level 3
Did you test your filter on sinewaves at just one frequency? That should make it easier to check the response.

Can you find sample code of a bandpass filter? Start with that, then change it to suit your specs.

It looks like a big jump to change from 4096 to 32*4096. Did you try values in between?

thank you. this is Kaiser bad-pass filter and it's work fine. the point is when 14.7Hz signal and 15.1hz signal amplitude growing up, this filter do not work properly. in this sample r1 ( amplitude of 14.7Hz ) and r2 ( amplitude of 15.1 Hz ) is too big than main Signal ( 14.8 Hz and it's amplitude is 50 ).
in other hand when my amplitude of my main signal is small than other noisy signal, bandpass filter do not able to filter noisy signal.
i looking how i can fix it?

#### FvM

##### Super Moderator
Staff member
There's nothing wrong with the filter. But you see that the second filter still passes part of the unwanted signals. Furthermore, you need to wait at least the threefold time for complete settling of the output signal. Finally there's a relation between the length of the impulse response (Fs*filter order) and the minimal achievable bandwidth.

#### fences

##### Junior Member level 3
There's nothing wrong with the filter. But you see that the second filter still passes part of the unwanted signals. Furthermore, you need to wait at least the threefold time for complete settling of the output signal. Finally there's a relation between the length of the impulse response (Fs*filter order) and the minimal achievable bandwidth.

thanks you, yes, filter is correct. but how can i get correct result? in second filter if i increase my signal samples data from 40000 to 100000, but filterign result not acceptable. filter result is too noisy yet.
is there any idea to design a filter that pass only 14.8Hz signal?
thanks

#### FvM

##### Super Moderator
Staff member
By filter specification, you don't have much attenuation for 14.7 Hz signal. The 32*4096 filter can achieve smaller bandwidth, but made it intentionally 0.2 Hz wide.

Status
Not open for further replies.