-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfilter_data.m
35 lines (34 loc) · 1.4 KB
/
filter_data.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function [moment_cal_filt,moment_cor_filt,acc_cal_filt,acc_cor_filt]=...
filter_data(data_table, cutoff_frequency)
%=========================================================================
%function FILTER_DATA
% Filters the data through a low-pass Butterworth filter based on the
% provided cutoff frequency.
%
%-------
%Inputs
%-------
% data_table (Nsamples x 4) Array of pitch moment and
% accelerations from both the
% calibration and correction trials in
% the form:
% [Mom_cal, Mom_cor, Acc_cal, Acc_cor]
% cutoff_frequency (double) The desired cutoff frequency for the
% low-pass filter.
%
%--------
%Outputs
%--------
% moment_cal_filt (Nsamples x 1) Filtered pitch moment (cal)
% moment_cor_filt (Nsamples x 1) Filtered pitch moment (cor)
% acc_cal_filt (Nsamples x 1) Filtered acceleration (cal)
% acc_cor_filt (Nsamples x 1) Filtered acceleration (cor)
%=========================================================================
%Filtering
[num,den]=butter(2,cutoff_frequency/(100/2));
filtered=filter(num,den,data_table);
moment_cal_filt=filtered(:,1);
moment_cor_filt=filtered(:,2);
acc_cal_filt=filtered(:,3);
acc_cor_filt=filtered(:,4);
end