Skip to content

Commit ec5f59d

Browse files
committed
DOC: Updates & clean ups
1 parent 9a8bbc4 commit ec5f59d

File tree

6 files changed

+56
-51
lines changed

6 files changed

+56
-51
lines changed

fooof_mat/fooof.m

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% fooof() - Fit the FOOOF model on a neural power spectrum.
22
%
33
% Usage:
4-
% >> fooof_results = fooof(freqs, power_spectrum, f_range, settings);
4+
% >> fooof_results = fooof(freqs, power_spectrum, f_range, settings, return_model);
55
%
66
% Inputs:
77
% freqs = row vector of frequency values
@@ -14,7 +14,7 @@
1414
% settings.peak_threshold
1515
% settings.background_mode
1616
% settings.verbose
17-
% return_model = boolean of whether to return actual model, optional
17+
% return_model = boolean of whether to return the FOOOF model fit, optional
1818
%
1919
% Outputs:
2020
% fooof_results = fooof model ouputs, in a struct, including:
@@ -30,9 +30,9 @@
3030
% fooof_results.bg_fit
3131
%
3232
% Notes
33-
% Not all settings need to be set. Any settings that are not
34-
% provided as set to default values. To run with all defaults,
35-
% input settings as an empty struct.
33+
% Not all settings need to be defined by the user.
34+
% Any settings that are not provided are set to default values.
35+
% To run with all defaults, input settings as an empty struct.
3636

3737
function fooof_results = fooof(freqs, power_spectrum, f_range, settings, return_model)
3838

@@ -43,32 +43,32 @@
4343
freqs = py.numpy.array(freqs);
4444
power_spectrum = py.numpy.array(power_spectrum);
4545
f_range = py.list(f_range);
46-
46+
4747
% Initialize FOOOF object
4848
fm = py.fooof.FOOOF(settings.peak_width_limits, ...
4949
settings.max_n_peaks, ...
5050
settings.min_peak_amplitude, ...
5151
settings.peak_threshold, ...
5252
settings.background_mode, ...
5353
settings.verbose);
54-
54+
5555
% Run FOOOF fit
5656
fm.fit(freqs, power_spectrum, f_range)
5757

5858
% Extract outputs
5959
fooof_results = fm.get_results();
6060
fooof_results = fooof_unpack_results(fooof_results);
61-
61+
6262
% Also return the actual model fit, if requested
6363
% This will default to not return model, if variable not set
6464
if exist('return_model', 'var') && return_model
65-
66-
% Get the model, and add outputs to foof_results
65+
66+
% Get the model, and add outputs to fooof_results
6767
model_out = fooof_get_model(fm);
6868
for field = fieldnames(model_out)'
6969
fooof_results.(field{1}) = model_out.(field{1});
7070
end
71-
71+
7272
end
73-
73+
7474
end

fooof_mat/fooof_check_settings.m

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
% settings.background_mode
1313
% settings.verbose
1414
%
15-
% Returns:
15+
% Outputs:
1616
% settings = struct, with all settings defined:
1717
% settings.peak_width_limts
1818
% settings.max_n_peaks
1919
% settings.min_peak_amplitude
2020
% settings.peak_threshold
2121
% settings.background_mode
2222
% settings.verbose
23-
23+
%
2424
% Notes:
25-
% This is a helper function, probably not called directly by the user.
25+
% This is a helper function, probably not called directly by the user.
2626
% Any settings not specified are set to default values
2727

2828
function settings = fooof_check_settings(settings)
@@ -35,8 +35,8 @@
3535
'peak_threshold', 2.0, ...
3636
'background_mode', 'fixed', ...
3737
'verbose', true);
38-
39-
% Overwrite any non-existent of nan settings with defaults
38+
39+
% Overwrite any non-existent or nan settings with defaults
4040
for field = fieldnames(defaults)'
4141
if ~isfield(settings, field) || all(isnan(settings.(field{1})))
4242
settings.(field{1}) = defaults.(field{1});

fooof_mat/fooof_get_model.m

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
% model_fit.bg_fit
1515
%
1616
% Notes
17-
% This function is mostly an internal function, but can be called
18-
% directly by the user if you are interacting with FOOOF objects
19-
% directly.
17+
% This function is mostly an internal function.
18+
% It can be called directly by the user if you are interacting with FOOOF objects directly.
2019

21-
% Get the actual fit model from a FOOOF object
2220
function model_fit = fooof_get_model(fm)
2321

2422
model_fit = struct();
25-
23+
2624
model_fit.freqs = double(py.array.array('d',fm.freqs));
2725
model_fit.power_spectrum = double(py.array.array('d', fm.power_spectrum));
2826
model_fit.fooofed_spectrum = double(py.array.array('d', fm.fooofed_spectrum_));

fooof_mat/fooof_plot.m

+15-13
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,49 @@
1313
function fooof_plot(fooof_results, log_freqs)
1414

1515
%% Data Checking
16+
1617
if ~isfield(fooof_results, 'freqs')
1718
error('FOOOF results struct does not contain model output.')
1819
end
1920

2021
%% Set Up
22+
2123
if exist('log_freqs', 'var') && log_freqs
2224
plt_freqs = log10(fooof_results.freqs);
2325
else
2426
plt_freqs = fooof_results.freqs;
2527
end
26-
28+
2729
% Plot settings
2830
lw = 2.5;
29-
30-
%% Create the Plots
31-
31+
32+
%% Create the plots
33+
3234
figure()
3335
hold on
36+
3437
% Plot the original data
3538
data = plot(plt_freqs, fooof_results.power_spectrum, 'black');
36-
39+
3740
% Plot the full model fit
3841
model = plot(plt_freqs, fooof_results.fooofed_spectrum, 'red');
3942

40-
4143
% Plot the background fit
4244
bg_fit = plot(plt_freqs, fooof_results.bg_fit, 'b--');
43-
44-
%% Plot Settings
45-
45+
46+
%% Plot settings
47+
4648
% Apply general plot settings
4749
for plt = [data, model, bg_fit]
4850
set(plt, 'LineWidth', lw);
49-
51+
5052
% Set alpha value for model - in a wonky way, because Matlab
51-
% Note: the '4' is magical and mysterious. No idea.
53+
% Note: the '4' is magical and mysterious. No idea.
5254
model.Color(4) = 0.5;
53-
55+
5456
grid on
5557
legend('Original Spectrum', 'Full Model Fit', 'Aperiodic Fit')
56-
58+
5759
hold off
5860

5961
end

fooof_mat/fooof_unpack_results.m

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
% fooof_unpack_results() - Extract model fit results from FOOOFResults.
22
%
33
% Usage:
4-
% >> results_out = fooof_unpack_results(fooof_results);
4+
% >> results_out = fooof_unpack_results(results_in);
55
%
66
% Inputs:
77
% fooof_results = FOOOFResults object
8+
%
89
% Outputs:
910
% results_out = fooof model results, in a struct, including:
1011
% results_out.background_params
@@ -13,34 +14,34 @@
1314
% results_out.error
1415
% results_out.r_squared
1516
%
16-
% Notes:
17-
% This function is mostly an internal function, and doesn't need to be
18-
% called directly by the user - but can be if you are interacting
19-
% directly with FOOOF objects.
17+
% Notes
18+
% This function is mostly an internal function.
19+
% It can be called directly by the user if you are interacting with FOOOF objects directly.
2020

2121
function results_out = fooof_unpack_results(results_in)
2222

2323
results_out = struct();
2424

2525
results_out.background_params = ...
2626
double(py.array.array('d', results_in.background_params));
27-
27+
2828
temp = double(py.array.array('d', results_in.peak_params.ravel));
2929
results_out.peak_params = ...
3030
transpose(reshape(temp, 3, length(temp) / 3));
31-
31+
3232
temp = double(py.array.array('d', results_in.gaussian_params.ravel));
3333
results_out.gaussian_params = ...
3434
transpose(reshape(temp, 3, length(temp) / 3));
35-
35+
3636
results_out.error = ...
3737
double(py.array.array('d', py.numpy.nditer(results_in.error)));
38-
39-
% Note: r_squared seems to come out as float
40-
% It's not clear why this value is different, but doesn't seem
41-
% to require the type casting like other (code commented below)
38+
4239
results_out.r_squared = results_in.r_squared;
40+
41+
% Note: r_squared seems to come out as float, and does not need type casting
42+
% It is not clear why this value is different
43+
% Just in case, the code for type casting is commented out below:
4344
%results_out.r_squared = ...
4445
% double(py.array.array('d', py.numpy.nditer(results_in.r_squared)));
45-
46+
4647
end

fooof_mat/fooof_version.m

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
% fooof_version() - Get FOOOF version information, of both Python & Wrapper.
1+
% fooof_version() - Get FOOOF version information.
22
%
33
% Usage:
44
% >> fooof_version()
5+
%
6+
% Notes
7+
% This function returns versions of both the installed FOOOF in Python, and of this Matlab wrapper.
8+
% The version number of the Matlab FOOOF wrapper is defined in this function.
59

610
function fooof_version()
711

812
% Get the version of the Python implementation of FOOOf being used
913
fooof_py_version = string(py.pkg_resources.get_distribution('fooof').version);
1014

1115
% Set the version number of the matlab wrapper
12-
% Note: this is where version is defined for this wrapper
16+
% Note: this is where version is defined for this wrapper
1317
fooof_wrapper_version = "0.1.0";
1418

1519
% Display versions
1620
disp('Current version of FOOOF: ' + fooof_py_version)
1721
disp('Current version of Wrapper: ' + fooof_wrapper_version)
18-
22+
1923
end

0 commit comments

Comments
 (0)