Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the command for butterworth bandpass filter

Tags:

matlab

I have signal data to filter using bandpass filter which the frequencies are 10-45s, 45-150s and 150-600s. how to create bandpass filter command in matlab to filter that frequencies?

like image 470
baizura Avatar asked Dec 29 '25 03:12

baizura


1 Answers

Assuming you have the signal processing toolbox (for the butter command - see lower code if butter is unavailable), and if you know the sampling frequency fs, you can make a simple recursive Butterworth filter using the low and high frequency (in Hz) -3dB poins using the following code. Higher orders will give you better off-frequency rejection at the expense of a longer impulse response and a little more computation expense.

[b,a] = butter(order, [lowFreq hiFreq]/(fs/2), 'bandpass');
 y = filter(b,a,x)

The output signal y is obtained by filtering the input signal x using the coefficients generated using the butter command.

If you want to have the output from all 3 bands at once, you can sum the outputs from 3 separate filter operations, one for each band. However, you may like to use the filtfilt command over filter when doing this if you want to preserve the phase relationship between the bands.

If you do not have the signal processing toolbox, you cancreate 2nd order bandpass butterworth coefficients using the code below, where dt = 1/fs and fl and fu are low and high cutoff frequencies.

function [ b, a ] = butterTwoBp( dt, fl, fu ) 
q=pi*dt*(fu-fl);
r=pi*dt*(fu+fl);
N = (tan(q)^2) + sqrt(2)*tan(q) + 1;
M = (tan(q)^2) / N; %M after N because it depends on N
O = -cos(r) * (2*sqrt(2)*tan(q) + 4) / ((cos(q))*N);
P = (-2*(tan(q)^2) + ((  (2*cos(r))   /  (cos(q))   )^2) + 2 )  /   N;
Q = cos(r)*(2*sqrt(2)*tan(q) - 4)/(cos(q)*N);
R = (   (tan(q)^2) - sqrt(2)*tan(q) + 1   )  /  N;

b=[M 0 -2*M 0 M];
a=[1 O P Q R];
like image 53
learnvst Avatar answered Dec 30 '25 22:12

learnvst