Clear Filters
Clear Filters

bandpass butterworth filter cutoff frequencies

14 views (last 30 days)
G
G on 2 Dec 2018
Commented: Elysandra Solis on 27 Oct 2022
I am trying to create a band-pass butterworth filter from 0.4 to 5 Hz... Here is my code:
I am getting an error that the cutoff frequencies must be within the interval of (0,1)... I need the the range to be from 0.4 to 5Hz
clear,clc
load('DATA_01_TYPE01.mat')
A = sig;
x = A(3,1:1000); %PPG channel
y=A(4,1:1000); %x-axis acceleration
t=1:1:1000;
subplot(3,1,1)
plot(t,x,t,y)
title('Filtered Signals')
xlabel('Sampling Points')
legend('PPG','Acceleration','Location','Southeast','Orientation','Horizontal')
[b,a] = butter(2,[0.4 5],'bandpass');
dataPPG = filter(b,a,x);
dataAcc = filter(b,a,y);
subplot(3,1,3)
plot(t,dataPPG,t,dataAcc)
title('Filtered Signals')
xlabel('Sampling Points')
legend('PPG','Acceleration','Location','Southeast','Orientation','Horizontal')

Answers (1)

Areej Varamban Kallan
Areej Varamban Kallan on 5 Dec 2018
Hi G,
The second argument to the 'butter' function should be the required cut off frequencies divided by half of the sample rate. For example, if you need to design a band pass filter with a lower cutoff frequency 500 Hz and a higher cutoff frequency of 600 Hz and at a sample rate of 1500 Hz, then the second argument to the butter function should be [500 600]/750.
Please refere to the documentation of butter for more information.
  1 Comment
Elysandra Solis
Elysandra Solis on 27 Oct 2022
I am having the same issue with my code and I have the right formula but it is still giving the same error.
set_sampfreq = 1000;
nyq_sampfreq = set_sampfreq/2;
ogsampfreq = [];
filter_range = [0.1 500]; % insert as a matrix
filtorder = 4;
ftype = 'bandpass';
[b a] = butter(filtorder,[filter_range(:,1)/nyq_sampfreq filter_range(:,2)/nyq_sampfreq],ftype);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!