Skip to content

Commit

Permalink
Merge pull request #1 from fooof-tools/dev
Browse files Browse the repository at this point in the history
Update for FOOOF 1.0
  • Loading branch information
TomDonoghue authored Apr 28, 2020
2 parents 2b7144a + 9090fec commit 41d9190
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 69 deletions.
2 changes: 1 addition & 1 deletion LonePSD_A_matlab_preprocessing.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
%% Load Data

% Load a single channel of data
load('dat/ch_dat_one.mat');
load('data/ch_dat_one.mat');

%% Calculate Power Spectra

Expand Down
39 changes: 18 additions & 21 deletions LonePSD_B_python_fooofing.ipynb

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions MultiPSD_A_matlab_preprocessing.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%% Matlab PreProcessing - Multiple PSDs
%
%
% This script is an example, with multiple power spectra,
% of integrating Python FOOOF into a Matlab workflow.
%
% of integrating Python FOOOF into a Matlab workflow.
%
% It is part of a trio of files that must be run in order:
% - `MultiPSD_A_*
% - `MultiPSD_B_*
Expand All @@ -12,16 +12,16 @@
%% Load Data

% Load two channels of time series data
load('dat/ch_dat_one.mat');
load('dat/ch_dat_two.mat');
load('data/ch_dat_one.mat');
load('data/ch_dat_two.mat');

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

%% Calculate Power Spectra

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

%% Save Out Data

Expand Down
38 changes: 19 additions & 19 deletions MultiPSD_B_python_fooofing.ipynb

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions MultiPSD_C_matlab_analysis.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%% Load and Analyze FOOOF Results in Matlab - Multiple PSDs
%
%
% This script is an example, with multiple power spectra,
% of integrating Python FOOOF into a Matlab workflow.
%
% of integrating Python FOOOF into a Matlab workflow.
%
% It is part of a trio of files that must be run in order:
% - `MultiPSD_A_*
% - `MultiPSD_B_*
Expand All @@ -13,11 +13,11 @@

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

% Load slopes
sls = load('slopes');
% Load exponents
exps = load('exps.mat');

% Check out slopes
sls
% Check out the exponents
exps

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

Expand All @@ -34,7 +34,7 @@

fooof_results = [];
for ind = 0:1
cur_result = load(strcat('f_res_', string(ind)));
cur_result = load(strcat('f_results_', string(ind)));
fooof_results = [fooof_results, cur_result];
end

Expand Down
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
# FOOOF: Matlab -> Python -> Matlab

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

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
## Overview

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).
This repository offers examples for how to integrate [FOOOF](https://github.com/fooof-tools/fooof) into a Matlab workflow.

## Overview
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.

The benefit of this approach, is that you have full access to the FOOOF module in Python.

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).
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.

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.
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).

Note that the main documentation for the FOOOF module itself is on the [documentation site](https://fooof-tools.github.io/fooof/).

## Workflow

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.
Some examples for using this approach, including Matlab and Python scripts, are available here.

With this template, you should be able get running without having to write almost any Python code.

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

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.

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

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.
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.
4 changes: 2 additions & 2 deletions utils/load_fooof_results.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% load_fooof_results () - load results from a json file (as saved out by FOOOF)
% load_fooof_results () - Load results from a json file, as saved out by FOOOF.
%
% Usage:
% >> fooof_results = load_fooof_results(file_name)
Expand All @@ -8,7 +8,7 @@
%
% Ouputs:
% fooof_results = fooof model ouputs, in a struct, including:
% fooof_results.background_params
% fooof_results.aperiodic_params
% fooof_results.peak_params
% fooof_results.gaussian_params
% fooof_results.error
Expand Down

0 comments on commit 41d9190

Please sign in to comment.