Band-Pass Filter using 2nd order butterworth filter then Normalize
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
G
el 7 de Nov. de 2018
Comentada: Star Strider
el 8 de Nov. de 2018
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.
0 comentarios
Respuesta aceptada
Star Strider
el 7 de Nov. de 2018
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.
4 comentarios
Star Strider
el 8 de Nov. de 2018
If your sampling frequency is 125 Hz, then you should have no problem. That is much higher than your passband and stopband frequencies.
I would use this design:
load('DATA_01_TYPE01.mat')
A = sig;
x = A(2,1:1000); %PPG channel
y = A(3,1:1000); %x-axis acceleration
Fs = 125; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = [0.4 5.0]/Fn; % Passband Frequency Vector (Normalised)
Ws = [0.3 5.1]/Fn; % Stopband Frequency Vector (Normalised)
% Wp = 3.5/Fn;
% Ws = 2.5/Fn;
Rp = 1; % Passband Ripple (dB)
Rs = 50; % Stopband Attenuation (dB)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Calculate Filter Order
[z,p,k] = ellip(n,Rp,Rs,Wp,'bandpass'); % Default Here Is A Lowpass Filter
[sos,g] = zp2sos(z,p,k); % Use Second-Order-Section Implementation For Stability
x_filtered = filtfilt(sos,g,x); % Filter Signal (Here: ‘x’)
figure
freqz(sos, 2^14, Fs) % Bode Plot Of Filter
set(subplot(2,1,1), 'XLim',[0 15]) % Optional, Change Limits As Necessary
set(subplot(2,1,2), 'XLim',[0 15]) % Optional, Change Limits As Necessary
That should give you the filter you want, with the characteristics you want. It designs a short, efficient filter with narrow transition regions and good stopband attenuation. The passband ripple is negligible.
I am not certain what signal you are filtering (could be ‘y’). This code filters ‘x’. You can easily change that in the filtfilt call.
Más respuestas (0)
Ver también
Categorías
Más información sobre Digital Filter Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!