Skip to content

Commit 41d9190

Browse files
authored
Merge pull request #1 from fooof-tools/dev
Update for FOOOF 1.0
2 parents 2b7144a + 9090fec commit 41d9190

9 files changed

+72
-69
lines changed

LonePSD_A_matlab_preprocessing.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
%% Load Data
1313

1414
% Load a single channel of data
15-
load('dat/ch_dat_one.mat');
15+
load('data/ch_dat_one.mat');
1616

1717
%% Calculate Power Spectra
1818

LonePSD_B_python_fooofing.ipynb

Lines changed: 18 additions & 21 deletions
Large diffs are not rendered by default.

MultiPSD_A_matlab_preprocessing.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
%% Matlab PreProcessing - Multiple PSDs
2-
%
2+
%
33
% This script is an example, with multiple power spectra,
4-
% of integrating Python FOOOF into a Matlab workflow.
5-
%
4+
% of integrating Python FOOOF into a Matlab workflow.
5+
%
66
% It is part of a trio of files that must be run in order:
77
% - `MultiPSD_A_*
88
% - `MultiPSD_B_*
@@ -12,16 +12,16 @@
1212
%% Load Data
1313

1414
% Load two channels of time series data
15-
load('dat/ch_dat_one.mat');
16-
load('dat/ch_dat_two.mat');
15+
load('data/ch_dat_one.mat');
16+
load('data/ch_dat_two.mat');
1717

1818
% Combine into a multi-channel data matrix
19-
chs_dat = [ch_dat_one; ch_dat_two]';
19+
chs_data = [ch_dat_one; ch_dat_two]';
2020

2121
%% Calculate Power Spectra
2222

2323
% Calculate power spectra with Welch's method
24-
[psds, freqs] = pwelch(chs_dat, 500, [], [], s_rate);
24+
[psds, freqs] = pwelch(chs_data, 500, [], [], s_rate);
2525

2626
%% Save Out Data
2727

MultiPSD_B_python_fooofing.ipynb

Lines changed: 19 additions & 19 deletions
Large diffs are not rendered by default.

MultiPSD_C_matlab_analysis.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
%% Load and Analyze FOOOF Results in Matlab - Multiple PSDs
2-
%
2+
%
33
% This script is an example, with multiple power spectra,
4-
% of integrating Python FOOOF into a Matlab workflow.
5-
%
4+
% of integrating Python FOOOF into a Matlab workflow.
5+
%
66
% It is part of a trio of files that must be run in order:
77
% - `MultiPSD_A_*
88
% - `MultiPSD_B_*
@@ -13,11 +13,11 @@
1313

1414
%% Load a specific variable that was saved out to a mat file
1515

16-
% Load slopes
17-
sls = load('slopes');
16+
% Load exponents
17+
exps = load('exps.mat');
1818

19-
% Check out slopes
20-
sls
19+
% Check out the exponents
20+
exps
2121

2222
%% Load in FOOOF results that have been saved out - from json file
2323

@@ -34,7 +34,7 @@
3434

3535
fooof_results = [];
3636
for ind = 0:1
37-
cur_result = load(strcat('f_res_', string(ind)));
37+
cur_result = load(strcat('f_results_', string(ind)));
3838
fooof_results = [fooof_results, cur_result];
3939
end
4040

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
# FOOOF: Matlab -> Python -> Matlab
22

3-
This repository offers support and examples for how to integrate [FOOOF](https://github.com/fooof-tools/fooof) into a Matlab workflow.
3+
Using an integrated workflow in which using Matlab is combined with running FOOOF directly in Python.
44

5-
Note that this workflow does use Python directly. Alternatively there is a full [Matlab wrapper](https://github.com/fooof-tools/fooof_mat). The benefit of this approach, over using the [wrapper](https://github.com/fooof-tools/fooof_mat), is that you have full access to the FOOOF module in Python, which makes it easier to use utilities to plot outputs and see what's happening. This approach
5+
## Overview
66

7-
All [descriptions](https://github.com/fooof-tools/fooof/README.md) and [tutorials](https://github.com/fooof-tools/fooof/tutorial) for FOOOF are in the [main repository](https://github.com/fooof-tools/fooof), and a full description of the method is available in the [paper](https://www.biorxiv.org/content/early/2018/04/11/299859).
7+
This repository offers examples for how to integrate [FOOOF](https://github.com/fooof-tools/fooof) into a Matlab workflow.
88

9-
## Overview
9+
This approach does use Python directly, and seeks to demonstrate how to use a primarily Matlab based approach, using Python only as needed for fitting power spectrum models. The idea is that one can do all of the processing and analysis in Matlab, up to and including calculating power spectra. These power spectra can then be saved out. These files can then be loaded into Python, and FOOOF can be used to fit power spectrum, and do any model related processing needed using the FOOOF module. The model results can also be saved out, and loaded back into Matlab.
10+
11+
The benefit of this approach, is that you have full access to the FOOOF module in Python.
1012

11-
This repository includes example code for a potential workflow whereby most stuff is done in Matlab, only using Python for FOOOF fitting specifically. This approach does require that you have Python and FOOOF installed. You can follow the direction to do so from [here](https://github.com/fooof-tools/fooof_mat).
13+
Alternatively there is a [Matlab wrapper](https://github.com/fooof-tools/fooof_mat), which you can use to call FOOOF directly from Matlab, without having to interact directly with Python.
1214

13-
The idea is that one can do all of the processing and analysis in Matlab, up to and including calculating power spectra. Power spectra are then saved out to mat files, and loaded into Python. You can the run and explore using FOOOF, in Python, fitting models, and then save out the model fit results, which can be loaded back into Matlab, if you prefer.
15+
This approach does require that you have Python and FOOOF installed. You can follow the directions to do so from [here](https://github.com/fooof-tools/fooof_mat).
16+
17+
Note that the main documentation for the FOOOF module itself is on the [documentation site](https://fooof-tools.github.io/fooof/).
1418

1519
## Workflow
1620

17-
An example / template workflow for using this approach, including matlab and python scripts, is available here. This workflow is for using FOOOF in a Matlab pipeline, in which you process and analyze the data mostly in Matlab, but do the FOOOF fitting directly in Python. With this template, you should be able get working with this workflow without having to write almost any Python code.
21+
Some examples for using this approach, including Matlab and Python scripts, are available here.
22+
23+
With this template, you should be able get running without having to write almost any Python code.
1824

1925
This suggested workflow is to:
20-
- A) Pre-process all data in Matlab, up to the point of creating and saving out power spectra
26+
- A) Pre-process data in Matlab, including creating and saving out power spectra
2127
- B) Switch to Python, load these power spectra, explore and fit FOOOF models, then save out FOOOF results
22-
- C) Continue analysis of the FOOOF results in Matlab
28+
- C) Continue analysis of FOOOF results in Matlab
2329

2430
In this folder you will find two examples of this workflow, one showing the outline with a single PSD, and another showing how you can update this workflow to analyze multiple power spectra.
2531

26-
You can also use these files as templates - just download this folder, and update the files as you need to to use your data.
32+
You can also use these files as templates - just download this folder, and update the files as needed to use your own data.
2733

28-
Note that as outlined the Python parts are done in notebooks, which allows for easy access to the plotting and exploration tools in FOOOF. When you have settled on parameters and so on, you can instead run this part as a Python script.
34+
Note that as outlined the Python parts are done using [Jupyter notebooks](https://jupyter.org/), which allow for interactive coding and integrated plotting, etc. Once you have checked the fitting, and settled on parameters and so on, you can instead run this part as a Python script.
File renamed without changes.
File renamed without changes.

utils/load_fooof_results.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% load_fooof_results () - load results from a json file (as saved out by FOOOF)
1+
% load_fooof_results () - Load results from a json file, as saved out by FOOOF.
22
%
33
% Usage:
44
% >> fooof_results = load_fooof_results(file_name)
@@ -8,7 +8,7 @@
88
%
99
% Ouputs:
1010
% fooof_results = fooof model ouputs, in a struct, including:
11-
% fooof_results.background_params
11+
% fooof_results.aperiodic_params
1212
% fooof_results.peak_params
1313
% fooof_results.gaussian_params
1414
% fooof_results.error

0 commit comments

Comments
 (0)