Skip to content

Commit 4d0a37f

Browse files
committed
Update process_detrend_emd to work with diff InputTypes
1 parent 804e2fb commit 4d0a37f

1 file changed

Lines changed: 50 additions & 27 deletions

File tree

toolbox/process/functions/process_remove_drift_emd.m renamed to toolbox/process/functions/process_detrend_emd.m

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
function varargout = process_remove_drift_emd(varargin)
2-
% PROCESS_REMOVE_DRIFT_EMD: Remove drift using Empirical Mode Decomposition (EMD)
1+
function varargout = process_detrend_emd( varargin )
2+
% PROCESS_DETREND_EMD: Remove a non-linear trend in a signal with EMD
33
%
44
% This process:
55
% 1) Decomposes each channel into intrinsic mode functions using EMD
66
% 2) Estimates the characteristic frequency of each IMF
77
% 3) Keeps only modes above the selected cutoff frequency
88
%
99
% USAGE:
10-
% OutputFiles = process_remove_drift_emd('Run', sProcess, sInputs)
10+
% OutputFiles = process_detrend_emd('Run', sProcess, sInputs)
1111

1212
% @=============================================================================
1313
% This function is part of the Brainstorm software:
@@ -28,45 +28,62 @@
2828
% =============================================================================@
2929
%
3030
% Authors: Kenneth N. Taylor, 2020
31-
% John C. Mosher, 2020
31+
% John C. Mosher, 2020
3232
% Chinmay Chinara, 2026
3333

3434
eval(macro_method);
3535
end
3636

37+
3738
%% ===== GET DESCRIPTION =====
3839
function sProcess = GetDescription() %#ok<DEFNU>
39-
% Description the process
40-
sProcess.Comment = 'Remove drift using EMD';
41-
sProcess.FileTag = 'emd';
42-
sProcess.Category = 'Filter';
43-
sProcess.SubGroup = 'FAST graph';
44-
sProcess.Index = 1302;
45-
sProcess.Description = 'https://neuroimage.usc.edu/brainstorm/Tutorials/FastGraph';
46-
% Definition of the input accepted by this process
47-
sProcess.InputTypes = {'data'};
48-
sProcess.OutputTypes = {'data'};
49-
sProcess.nInputs = 1;
50-
sProcess.nMinFiles = 1;
51-
% EMD cutoff frequency
52-
sProcess.options.cutoff.Comment = 'EMD cutoff frequency: ';
53-
sProcess.options.cutoff.Type = 'value';
54-
sProcess.options.cutoff.Value = {2, 'Hz', 2};
40+
% Description the process
41+
sProcess.Comment = 'Remove non-linear trend with EMD';
42+
sProcess.FileTag = 'emd';
43+
sProcess.Category = 'Filter';
44+
sProcess.SubGroup = 'Pre-process';
45+
sProcess.Index = 61.5;
46+
sProcess.Description = 'https://neuroimage.usc.edu/brainstorm/Tutorials/FastGraph';
47+
% Definition of the input accepted by this process
48+
sProcess.InputTypes = {'raw', 'data', 'results', 'matrix'};
49+
sProcess.OutputTypes = {'raw', 'data', 'results', 'matrix'};
50+
sProcess.nInputs = 1;
51+
sProcess.nMinFiles = 1;
52+
% Default values for some options
53+
sProcess.processDim = 1; % Process channel by channel
54+
55+
% Definition of the options
56+
% === Sensor types
57+
sProcess.options.sensortypes.Comment = 'Sensor types or names (empty=all): ';
58+
sProcess.options.sensortypes.Type = 'text';
59+
sProcess.options.sensortypes.Value = 'MEG, EEG';
60+
sProcess.options.sensortypes.InputTypes = {'data', 'raw'};
61+
% === EMD cutoff frequency
62+
sProcess.options.emdcutoff.Comment = 'EMD cutoff frequency: ';
63+
sProcess.options.emdcutoff.Type = 'value';
64+
sProcess.options.emdcutoff.Value = {2, 'Hz', 2};
5565
end
5666

67+
5768
%% ===== FORMAT COMMENT =====
5869
function Comment = FormatComment(sProcess) %#ok<DEFNU>
5970
Comment = sProcess.Comment;
6071
end
6172

73+
6274
%% ===== RUN =====
6375
function sInput = Run(sProcess, sInput) %#ok<DEFNU>
64-
% Get process option values
65-
CutoffFreq = sProcess.options.cutoff.Value{1};
66-
if CutoffFreq <= 0
67-
bst_report('Error', sProcess, [], 'EMD cutoff frequency must be positive.');
68-
return;
69-
end
76+
% Get options
77+
if isfield(sProcess.options, 'emdcutoff') && isfield(sProcess.options.emdcutoff, 'Value') && iscell(sProcess.options.emdcutoff.Value) && ~isempty(sProcess.options.emdcutoff.Value)
78+
CutoffFreq = sProcess.options.emdcutoff.Value{1};
79+
else
80+
CutoffFreq = [];
81+
end
82+
if isempty(CutoffFreq) || isequal(CutoffFreq, 0)
83+
bst_report('Error', sProcess, [], 'Invalid cutoff frequency value.');
84+
sInput = [];
85+
return
86+
end
7087

7188
% Sampling frequency
7289
Fs = 1 / mean(diff(sInput.TimeVector));
@@ -82,9 +99,15 @@
8299
end
83100

84101
% Add history comment
85-
sInput.HistoryComment = sprintf('Removed drift using EMD: cutoff frequency = %.3f Hz', CutoffFreq);
102+
sInput.HistoryComment = sprintf('Removed non-linear trend with EMD: cutoff frequency = %.3f Hz', CutoffFreq);
103+
104+
% Do not keep the Std field in the output
105+
if isfield(sInput, 'Std') && ~isempty(sInput.Std)
106+
sInput.Std = [];
107+
end
86108
end
87109

110+
88111
%% ===== IMF MODE STATISTICS =====
89112
function modeFreq = ImfStats(imf, Fs)
90113
% IMF matrix is expected as [time x modes]

0 commit comments

Comments
 (0)