-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfarm_main_workflow.m
111 lines (63 loc) · 3.05 KB
/
farm_main_workflow.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function data = farm_main_workflow( data, channel_description )
% FARM_MAIN_WORKFLOW is a wrapper that will perform FARM denoisng.
% VERY IMPORTANT : It is optimized for EMG data.
%
% SYNTAX
% data = FARM_MAIN_WORKFLOW( data )
%
% INPUT
% - data : see <a href="matlab: help farm_check_data">farm_check_data</a>
% - channel_description : can be channel index [1 2 ...] or a regex (char or cellstr) for data.label
%
%
%
% See also farm_check_data
if nargin==0, help(mfilename('fullpath')); return; end
%% Check input arguments
narginchk(2,2)
farm_check_data( data )
%% ------------------------------------------------------------------------
%% FARM
% Main FARM functions are below.
% A lot of functions use what is called "regular expressions" (regex). It allows to recognize patterns in strings of characters
% This a powerfull tool, which is common to almost all programing languages. Open some documentation with : doc regular-expressions
%% Check input data
farm_check_data( data )
%% Channel selection
% In your dataset, you might have different nature of signal, for exemple EMG + Accelerometer.
% To perform FARM pipeline only on EMG, you need to select the corresponding channels.
% Select channel for the next processing steps
data = farm.workflow.select_channel( data, channel_description );
fprintf('channel selected : %s \n', data.selected_channels_name{:})
%% Initial HPF @ 30Hz
data = farm.workflow.initial_hpf( data );
%% Which channel with greater artifacts ?
data = farm.workflow.detect_channel_with_greater_artifact( data );
fprintf('channel with greater artifacts : %s \n', data.label{data.target_channel})
%% Add slice markers : initialize sdur & dtime
data = farm.workflow.add_slice_marker( data );
%% Prepare slice candidates for the template generation
data = farm.workflow.pick_slice_for_template( data );
%% Optimize slice markers : optimize sdur & dtime
% with an unconstrained non-linear optimization
data = farm.workflow.optimize_sdur_dtime( data );
%% Slice correction : compute slice template using best candidates
data = farm.workflow.compute_slice_template( data );
%% Volume correction : replace volume-segment (dtime) by 0
% In the FARM article, this method is more advanced, and overwrite less points
% But I didn't succed to code it properly, so I used a "zero filling"
data = farm.workflow.volume_correction( data );
%% Revove noise residuals using PCA
% Here, the templates will be substracted, then PCA will be perform on the residuals.
% PCs will bi fitted to theses residials, and substracted.
data = farm.workflow.optimize_slice_template_using_PCA( data );
%% Revove noise residuals using ANC
% ANC will remove the last residuals not fitted by the PCs
% Don't know why ANC diverges in this dataset
% Clue : in Niazy et al., they think the filtering diverges when the amplitude is large,
% which is the case for EMG burst compared to EEG.
% data = farm.workflow.adaptive_noise_cancellation( data );
%% Remove slice markers
% More convenient
data = farm.workflow.remove_slice_marker( data );
end % function