MATLAB: Band-Pass Filter using 2nd order butterworth filter then Normalize

butterworthfilter

clear,clc
load('DATA_01_TYPE01.mat')
A = sig;
x = A(2,1:1000) %PPG channel
y=A(3,1:1000); %x-axis acceleration
t=1:1:1000;
[x,y]=butter(2,[0.4 5]);
d = designfilt('bandpassiir','FilterOrder',2,'HalfPowerFrequency1',0.4,'HalfPowerFrequency2',5, 'SampleRate',1500);
sos = ss2sos(x,y);
N=normalize(x,y)
subplot(3,1,1)
plot(t,sos)
title('Raw Signals')
xlabel('Sampling Points')
legend('PPG','Acceleration','Location','Southeast','Orientation','Horizontal')
I am trying to filter the PPG and acceleration signals using a band-pass filter from 0.4Hz to 5Hz using a 2nd order Butterworth filter. Then normalize the PPG and acceleration signals. I am not sure what I am doing wrong. I am getting errors of:
Error using butter (line 62)
The cutoff frequencies must be within the interval of (0,1).
Error in Butterworth_Practice (line 29)
[x,y]=butter(2,[0.4 5]);
I do not even have a line 62 in my code. My lines of code range from 22-37. Thanks for your help.

Best Answer

You have to normalise the filter frequencies by dividing them by the Nyquist frequency.
Fs = ...; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
[b,a] = butter(2,[0.4 5]/Fn);
That should work, although a second-order Butterworth design might not give you the result you want. See the relevant documentation for buttord, zp2sos, and other functions for hints on designing an effective filter. Also, use the filtfilt function to do the actual filtering.
If you have R2018a or later, you can use the bandpass (link) function. If you use the second ‘d’ output as your designed filter, use filtfilt to do the actual filtering with it as well.
Related Question