How can I filtrate recorded time acceleration signal with 4th order Butterworth low and high pass filter ??
5 views (last 30 days)
Show older comments
Mohamed Abdelkareem
on 9 Jun 2020
Commented: Mathieu NOE
on 9 Jun 2020
Discription of the problem:
I need to apply a 4th order Butterworth low and high pass filter of 0.1-100 Hz to filter the integrated velocity out from both low frequency and high frequency.
Parameters are listed below: (time frame is 10 Sec. with 0.01 Sec. increament).
0 Comments
Accepted Answer
Mathieu NOE
on 9 Jun 2020
hello
below a script you can use / modify to fit your own needs ;
You may have to change the way you load the time data (example here for txt / ascii files using the readclm function)
the filter is applied on the time data using the filtfilt function
you need the signal processing toolbox
enjoy !
Mathieu
-------------------------------------------------------------------------------------------------------------------------------------------------
clc
clear all
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
file = 'test3.txt';
% time indexes ;
time_min = 0;
time_max = 5;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Nclm = 2; % nb of columns : 1 = time , 2 = vibration
[outdata,HEAD] = readclm(file,Nclm,1);
t = outdata(:,1); % time
Data = outdata(:,2); % vibration channel # 1
clear outdata
ind = find(t>=time_min & t<=time_max); % use only data between the two time indexes
t = t(ind);
Data = Data(ind);
samples = length(t);
Fs = round((samples-1)/(max(t)-min(t))); % Sampling frequency
Filename_title = file(1:length(file)-4);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% decimation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
decim = 2; %;
Data2 = decimate(Data,decim);
Fs2 = Fs/decim;
t2 = min(t)+ (0:length(Data2)-1)/Fs2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% band pass filtering
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f_low = 150;
f_high = 300;
Wn = 2*[f_low f_high]/Fs2;
N = 2;
[B,A] = BUTTER(N,Wn);
% apply band pass filter to data
Data_filtered = filtfilt(B,A,Data2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1);
subplot(2,1,1),plot(t2,Data2);xlabel('Time (s)');ylabel(' amplitude (g)');legend('unfiltered');
title(' Time signal - Accelerometer ');
subplot(2,1,2),plot(t2,Data_filtered);xlabel('Time (s)');ylabel(' amplitude (g)');legend('filtered');
max_amplitude_g = max(abs(Data_filtered));
disp(['Max g level : ' num2str(0.01*round(max_amplitude_g*100)) ' g']);
2 Comments
Mathieu NOE
on 9 Jun 2020
hello
I change the parameters for the Butterworth filter (N = 2 changed to 4)
same for the low and high cut off frequency (look for f_low and f_high ) in the attached m file
Sampling frequency : how do you get you data ? do you have a file ? format ? could you send it to me ?
If your sampling frequency is known , then you can specify it dirctly in your file
see the attaced file : I have created a dummy signal (random numbers) for example
Also keep in mind that filters cut off frequencies cannot be above the Nyquist frequency ( = half of the sampling frequency). In the practice , we usually set the sampling frequency at least as 2.56 times above the highest frequency for analysis (true also for filters cut off frequencies)
so if you are interested to filter out your signal above 100 Hz (and set your filter accordingly) , your recommended lowest sampling frequency is 256 Hz
there is no need for very high frequency sampling if you are only interested in the 100 Hz range; oversampling will just make your data file bigger and the slow down your processing time
all the best
Mathieu
More Answers (0)
See Also
Categories
Find more on Digital Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!