Troubles with Butterworth Bandpass filter
5 views (last 30 days)
Show older comments
Hi to everyone,
I'm experiencing some problems when trying to apply a Butterworth Bandpass filter in Matlab. In particular, I want to filter an acceleration history recorded at the base of a building. The sampling frequency is 1000Hz, and i want to preserve the signal between 0.1Hz and 27Hz.
I adopted two different ways to code the Butterworth filter in Matlab, but I'm not able to obtain the same response that I obtain adopting the professional software seismosignal. In particular, the problem is with the response obtained by double integration of filitered accelerogram. Here the code I used (the .txt is attached)
%load accelerations (m/s^2)
Acc=load('Acceleration.txt');
%time step
dt=0.001;
% Frequency corresponding to sampling of 0.001s for each acceleration value
Fsp=1/dt;
% set Bandpass frequencies
Fcp_low=0.1; %lower cutoff frequency
Fcp_high=27; %higher cutoff frequency
%version 1
[z,p,k]=butter(4,[Fcp_low Fcp_high]/(Fsp/2),'bandpass');
[sos,g]=zp2sos(z,p,k);
udd_cor=filtfilt(sos,g,Acc);
ud_cor=cumtrapz(udd_cor)*dt;
u_cor=cumtrapz(ud_cor)*dt;
% version 2
[b,a]=butter(4,[Fcp_low Fcp_high]/(Fsp/2));
udd_cor1=filter(b,a,Acc);
ud_cor1=cumtrapz(udd_cor1)*dt;
u_cor1=cumtrapz(ud_cor1)*dt;
This is the displacement response obtained with seismosignal:
This is the response obtained adopting "version 1" of Butterworth filter:
This is the response obtained adopting "version 2" of Butterworth filter:
Probably I'm doing something wrong.
Every help would be very glad.
Thank you in advance
0 Comments
Answers (2)
Star Strider
on 20 May 2020
My expertise in this area stops with the filters and thier implementations.
An appropriate time vector:
Fs = 1000;
L = numel(Acc);
t = linspace(0, L-1, L)/Fs;
Only the ‘version 1’ code designs and implements an appropriate, stable filter. (The filter in ‘version 2’ is unstable, and using filter instead of filtfilt is not advisable.)
Since I have no idea how to interpret the double integration of the same vector (instead of over different variables or with respect to cumtrapz, different dimensions of the same matrix), I will leave that discussion to those who do.
0 Comments
Seong Jun Ha
on 20 Oct 2021
I experienced the same problem. Adding zero pad was the answer. I hope that your problem was already solved.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!