-
Notifications
You must be signed in to change notification settings - Fork 1
/
filterOptitrackData.m
89 lines (82 loc) · 3.66 KB
/
filterOptitrackData.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function [ MovementDataOut ] = filterOptitrackData( MovementData, cutOffs, filterType )
%function [ MovementDataOut ] = filterOptitrackData( MovementData, cutOffs, filterType )
% Function to filter Movement Data output from csv2mat_sm
% Filtering is done using FieldTrip
%
% INPUT:
% - MovementData: output from csv2mat_sm
% - cutOffs (double vector): filter 3dB cut off point/s. One number if
% using a low or high pass filter, two numbers for band pass or notch
% - filterType (string): 'low', 'high', 'bandpass', or 'bandstop' for a
% low pass, high pass, bandpass or bandstop/notch filter
% respectively.
%
% OUTPUT:
% - MovementDataOut: filtered optitrack data
%
% FUNCTION DEPENDENCIES:
% - ft_preproc_bandstopfilter
% - ft_preproc_highpassfilter
% - ft_preproc_lowpassfilter
% - ft_preproc_bandpassfilter
%
% AUTHOR INFO:
% Stephanie Mellor, [email protected]
% 26/1/21
%
% Create variable to save new movement data
MovementDataOut = MovementData;
% Find the sampling frequency
sf = mean(1./diff(MovementData.time));
% Filter rigid body data
for i = 1:length(MovementData.rigidbodies)
switch filterType
case 'low'
MovementDataOut.rigidbodies(i).data = transpose(ft_preproc_lowpassfilter(...
MovementData.rigidbodies(i).data', sf, cutOffs));
case 'high'
MovementDataOut.rigidbodies(i).data = transpose(ft_preproc_highpassfilter(...
MovementData.rigidbodies(i).data', sf, cutOffs));
case 'bandpass'
MovementDataOut.rigidbodies(i).data = transpose(ft_preproc_bandpassfilter(...
MovementData.rigidbodies(i).data', sf, cutOffs));
case 'bandstop'
MovementDataOut.rigidbodies(i).data = transpose(ft_preproc_bandstopfilter(...
MovementData.rigidbodies(i).data', sf, cutOffs));
end
end
% Filter rigid body marker data
for i = 1:size(MovementData.markers.rigidbodymarkers,2)
switch filterType
case 'low'
MovementDataOut.markers.rigidbodymarkers(i).data = transpose(ft_preproc_lowpassfilter(...
MovementData.markers.rigidbodymarkers(i).data', sf, cutOffs));
case 'high'
MovementDataOut.markers.rigidbodymarkers(i).data = transpose(ft_preproc_highpassfilter(...
MovementData.markers.rigidbodymarkers(i).data', sf, cutOffs));
case 'bandpass'
MovementDataOut.markers.rigidbodymarkers(i).data = transpose(ft_preproc_bandpassfilter(...
MovementData.markers.rigidbodymarkers(i).data', sf, cutOffs));
case 'bandstop'
MovementDataOut.markers.rigidbodymarkers(i).data = transpose(ft_preproc_bandstopfilter(...
MovementData.markers.rigidbodymarkers(i).data', sf, cutOffs));
end
end
% Filter other marker data
for i = 1:size(MovementData.markers.labeledmarkers,2)
switch filterType
case 'low'
MovementDataOut.markers.labeledmarkers(i).data = transpose(ft_preproc_lowpassfilter(...
MovementData.markers.labeledmarkers(i).data', sf, cutOffs));
case 'high'
MovementDataOut.markers.labeledmarkers(i).data = transpose(ft_preproc_highpassfilter(...
MovementData.markers.labeledmarkers(i).data', sf, cutOffs));
case 'bandpass'
MovementDataOut.markers.labeledmarkers(i).data = transpose(ft_preproc_bandpassfilter(...
MovementData.markers.labeledmarkers(i).data', sf, cutOffs));
case 'bandstop'
MovementDataOut.markers.labeledmarkers(i).data = transpose(ft_preproc_bandstopfilter(...
MovementData.markers.labeledmarkers(i).data', sf, cutOffs));
end
end
end