-------------------------------------------------------------------------------------------------------------------------------------------------
clc
clear all
close all
file = 'test3.txt';
time_min = 0;
time_max = 5;
Nclm = 2;
[outdata,HEAD] = readclm(file,Nclm,1);
t = outdata(:,1);
Data = outdata(:,2);
clear outdata
ind = find(t>=time_min & t<=time_max);
t = t(ind);
Data = Data(ind);
samples = length(t);
Fs = round((samples-1)/(max(t)-min(t)));
Filename_title = file(1:length(file)-4);
decim = 2;
Data2 = decimate(Data,decim);
Fs2 = Fs/decim;
t2 = min(t)+ (0:length(Data2)-1)/Fs2;
f_low = 150;
f_high = 300;
Wn = 2*[f_low f_high]/Fs2;
N = 2;
[B,A] = BUTTER(N,Wn);
Data_filtered = filtfilt(B,A,Data2);
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']);
Best Answer