-
Notifications
You must be signed in to change notification settings - Fork 2
/
pop_eeg_fooof.m
62 lines (56 loc) · 3.55 KB
/
pop_eeg_fooof.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
function [EEG, LASTCOM] = pop_eeg_fooof(EEG, varargin)
% Author: The Voytek Lab and Brian Barry
% GUI for FOOOF wrapper on spectral data from EEGLAB
% For fooof related docs see: https://github.com/fooof-tools/fooof_mat/blob/master/fooof_mat/
% For relevant EEGLAB related docs see:
% https://github.com/sccn/eeglab/blob/develop/functions/popfunc/pop_spectopo.m
if ~isempty(EEG.icaweights) %Might remove this
default_comps = [num2str(1) ':' num2str(max(EEG.icachansind))];
else
default_comps = '';
end
uilist = {{ 'style' 'text' 'string' 'Type of data to fit (component or channel):' } ...
{ 'style' 'edit' 'string' '"component"' } ...
{ 'style' 'text' 'string' 'ICs/channels to fit' } ...
{ 'style' 'edit' 'string' default_comps } ...
{ 'style' 'text' 'string' 'epoch range [min_ms max_ms]:' } ... % 2 element array
{ 'style' 'edit' 'string' [num2str( EEG.xmin*1000) ' ' num2str(EEG.xmax*1000)] } ...
{ 'style' 'text' 'string' 'percent of the data to sample for computing:' } ...
{ 'style' 'edit' 'string' 100 } ...
{ 'style' 'text' 'string' 'Frequency range to fit:' } ...
{ 'style' 'edit' 'string' '' } ...
... % Now FOOOF settings
{ 'style' 'text' 'string' ' FOOOF settings (optional)' 'fontweight' 'bold' }...
{ 'style' 'text' 'string' 'peak_width_limits' } ...
{ 'style' 'edit' 'string' '' } ...
{ 'style' 'text' 'string' 'max_n_peaks' } ...
{ 'style' 'edit' 'string' '' } ...
{ 'style' 'text' 'string' 'min_peak_height' } ...
{ 'style' 'edit' 'string' '' } ...
{ 'style' 'text' 'string' 'peak_threshold' } ...
{ 'style' 'edit' 'string' '' } ...
{ 'style' 'text' 'string' 'aperiodic_mode' } ...
{ 'style' 'edit' 'string' "'fixed'" } ... %want to make a checkmark later
{ 'style' 'text' 'string' 'verbose (boolean)' } ...
{ 'style' 'edit' 'string' 'false' } };
uigeom = { [11 4] [11 3] [11 3] [11 3] [11 3] [1] [11 3] [11 3] [11 3] [11 3] [11 3] [11 3]};
[result, usrdat, sres2, sres] = inputgui( 'uilist', uilist, 'geometry', uigeom, 'title', 'FOOOF EEG - pop_eeg_fooof()', 'helpcom', 'pophelp(''pop_eeg_fooof'');', 'userdata', 0); %currently ignoring usrdat, sres2, sres
params = {}; %parameters for fooof_eeg w/o FOOOF settings
settings_keys = {'peak_width_limits','max_n_peaks','min_peak_height','peak_threshold','aperiodic_mode','verbose'}; %the FOOOF settings
settings = struct(); %can be empty
for i = 1:length(result)
if i < 6 % spectral settings
param_curr = eval( [ '[' result{i} ']' ] );
params{end+1} = param_curr;
else % FOOOF settings
if ~isempty(eval( [ '[' result{i} ']' ] ))
settings.(settings_keys{i-5}) = eval( [ '[' result{i} ']' ] );
end
end
end
if ~isempty(params)
EEG = eeg_fooof(EEG, params{1}, params{2}, params{3}, params{4}, params{5}, settings);
LASTCOM = sprintf('EEG = eeg_fooof(EEG, %s, [ %s ], [%d %d], %d, [%d %d], %s)', params{1}, sprintf('%d ', params{2}), params{3}(1), params{3}(2), params{4}, params{5}(1), params{5}(2), struct2str(settings));
else % datatype %ids % epoch 1 epoch 2 percent f_range1 f_range2
LASTCOM = '';
end