MATLAB Answers

Proper (butterworth) bandpass filter

409 views (last 30 days)
Emil Brandt
Emil Brandt on 18 Jan 2017
Commented: Star Strider on 11 Mar 2020
Hey guys! I'm fairly new with signal processing in matlab. I have some labdata that are corrupted by noise. I would like to make a (butterworth) bandpass filter between approx. 0.5 kHz and 1.5 kHz. I have tried a lot of different approaches from browsing the net. My latest attempt looks like this:
%-------- loading time series-----------
load('filtest1000hz.txt');
time=filtest1000hz(:,1); %time
volin=filtest1000hz(:,2); %volt input [V]
volout=filtest1000hz(:,3); %volt output [mV]
%-------- loading spectrum -----------------
load('filtestspectrum1000hz.txt');
freq=filtestspectrum1000hz(:,1)*10^3; %frequency in kHz
powin=filtestspectrum1000hz(:,2); %power input
powout=filtestspectrum1000hz(:,3); %power output
fs=10*10^(3); %sample rate in kHz
inputsig=powin; %input signal
order=2; %order of filter
fcutlow=0.1; %low cut frequency in kHz
fcuthigh=1.7; %high cut frequency in kHz
[b,a]=butter(order,[fcutlow,fcuthigh]/(fs/2),'bandpass');
filtsig=filter(b,a,inputsig); %filtered signal
This is the output i get (3rd subplot) when i plot the "filtsig" vs. the frequency (freq). You can see the original spectrum (intended) but the filtered spectrum does not even show up:
and this is the format of my data from the time series and the spectrum (input channel and output channel):
I have spend a lot of hours trying to figure out how to do the bandpass properly. Can some of you figure out what is wrong?
Kind regards

  0 Comments

Sign in to comment.

Answers (1)

Jordan Ross
Jordan Ross on 24 Jan 2017
Hello Emil,
I believe the issue is that when you specify the passband frequencies for the filter you are specifying it to be between 0.1 and 1.7Hz instead of the KHz that you are expecting. Therefore, what you need is the following:
fcutlow=100; %low cut frequency in Hz
fcuthigh=1700; %high cut frequency in Hz
[b,a]=butter(order,[fcutlow,fcuthigh]/(fs/2),'bandpass');
Also, I would recommend checking out the Filter Designer tool. In the tool you can export the designed filter to a .m file. http://www.mathworks.com/help/signal/ug/getting-started-with-filter-designer.html

  3 Comments

Andi Ferdiawan
Andi Ferdiawan on 17 Dec 2019
what function for order ?
Biswajit Ojha
Biswajit Ojha on 11 Mar 2020
For the order, you have to choose numeric values , e.g. 3 or 4 or 5 ..

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by