This repository contains MATLAB code for analyzing phase-amplitude coupling (PAC) in MEG data from patients with Alzheimer's Disease (AD) and healthy controls.
If you use this code in your research, please cite our preprint:
Preprint: https://www.medrxiv.org/content/10.64898/2026.02.06.26345635v1
This pipeline processes MEG (Magnetoencephalography) data to investigate phase-amplitude coupling between hippocampal and cortical regions in Alzheimer's Disease. The analysis focuses on theta/alpha phase coupling with low-gamma amplitude, examining differences between AD patients and healthy controls.
- Head Modeling: Automated head model construction using Brainstorm and OpenMEEG
- MEG Preprocessing: Bad channel interpolation, resampling, and trial rejection
- Source Reconstruction: LCMV beamformer-based source localization
- PAC Analysis: Cross-frequency coupling between hippocampus and cortical ROIs
- Statistical Analysis: Cluster-based permutation tests and linear mixed-effects models
- MATLAB (tested with recent versions)
- FieldTrip Toolbox - For anatomy transformation and preprocessing
- Download: https://www.fieldtriptoolbox.org/
- Brainstorm Toolbox - For head model construction
- Download: https://neuroimage.usc.edu/brainstorm/
- FreeSurfer - For cortical surface extraction (must be run on MRI files before the pipeline)
- Download: https://surfer.nmr.mgh.harvard.edu/
MEG and MRI data can be downloaded from:
- OSF Repository: https://osf.io/pd4h9/overview
Data should be placed in a Dataset folder under the main project path.
The PAC estimation code is based on the implementation by Franziska Pellegrini and Stefan Haufe:
-
Clone this repository:
git clone https://github.com/braindatalab/AD_PAC.git cd AD_PAC -
Download and install required toolboxes (FieldTrip, Brainstorm, FreeSurfer)
-
Download the MEG and MRI data from OSF and place in
Dataset/folder -
Add required toolboxes to your MATLAB path in the
main.mscript
The complete analysis pipeline is orchestrated through the main.m script. The pipeline consists of five main stages:
anatomyTransform; % Correct MRI transformation matrices and save as NIfTI files
removeElec; % Remove 'elec' field from MEG files
buildHeadModels; % Build head models and leadfields using Brainstorm and OpenMEEG
processBSFiles; % Convert to MNI, extrapolate to high-res cortex, save leadfieldspreprocessing; % Resample, interpolate bad channels, segment trials, reject bad trialssourceReconstruction_p; % LCMV beamformer source reconstructionseedRoitoCortex; % Compute cross-site PAC between hippocampus and cortical ROIs
% (theta/alpha - low-gamma coupling)prepareTable; % Prepare table with clinical/demographic data and PAC values
powerAnalysis; % Analyze PSD and region-wise power differences
clusterBasedModel; % Cluster-based statistical analysis on PAC differences
linearMixedEffectsModel; % Linear mixed-effects modelingTo run the full analysis:
- Open MATLAB and navigate to the repository directory
- Edit
main.mto set yourmain_pathvariable - Ensure all required toolboxes are in your MATLAB path
- Run individual sections or the complete pipeline:
% Set the main path
main_path = './';
% Add all subdirectories to path
addpath(genpath(main_path));
% Run individual pipeline stages as needed
% (See main.m for complete pipeline)AD_PAC/
├── main.m # Main pipeline orchestration script
├── Dataset/ # Data directory (not included, download from OSF)
├── HeadModelling/ # Head model construction scripts
│ ├── anatomyTransform.m
│ ├── buildHeadModels.m
│ ├── processBSFiles.m
│ └── removeElec.m
├── PreProcessing/ # MEG data preprocessing scripts
│ ├── preprocessing.m
│ ├── interpolate_bad_channels.m
│ ├── detect_bad_trials.m
│ └── plot_data.m
├── SourceReconstruction/ # Source localization scripts
│ ├── sourceReconstruction_p.m
│ ├── lcmv_meg.m
│ └── ...
├── Pac/ # Phase-amplitude coupling analysis
│ ├── seedRoitoCortex.m
│ ├── er_pac.m
│ └── ...
└── Stat/ # Statistical analysis scripts
├── prepareTable.m
├── powerAnalysis.m
├── clusterBasedModel.m
└── linearMixedEffectsModel.m
The head modeling pipeline creates forward models for MEG source localization:
- Transforms anatomical MRI data to standard space
- Constructs realistic head models using OpenMEEG
- Generates leadfield matrices for source reconstruction
- Outputs are saved for each subject and used in subsequent analysis
MEG data preprocessing includes:
- Resampling to 200 Hz (configurable)
- Bad channel detection and interpolation
- Trial segmentation (2-second trials)
- Artifact rejection based on amplitude thresholds
- Quality control plots are generated for each step
Source-level analysis using LCMV beamformer:
- Computes spatial filters for each cortical location
- Projects sensor-level MEG data to source space
- Focuses on regions of interest (ROIs) including hippocampus and cortical areas
- Produces time series for each ROI
Phase-amplitude coupling estimation:
- Computes coupling between hippocampal theta/alpha phase (4-12 Hz)
- And cortical low-gamma amplitude (30-55 Hz)
- Analyzes left/right hippocampus to ipsilateral/contralateral cortex
- Uses bispectral analysis methods (Antisymmetrized bicoherence)
- Results saved per subject for statistical analysis
Group-level statistics:
- Prepares data tables with demographics and PAC metrics
- Power spectral density analysis
- Cluster-based permutation testing for PAC differences
- Linear mixed-effects models accounting for repeated measures
- Visualization of significant results and correlations
Results are organized in the Results/ directory:
Results/Preprocessing/: Preprocessing quality control plotsResults/source/: Source reconstruction results per subjectResults/SeedtoCortex/: PAC analysis results per subject- Statistical analysis outputs including plots and model results
- Missing toolboxes: Ensure FieldTrip, Brainstorm, and FreeSurfer are properly installed and in your MATLAB path
- Data not found: Verify that the Dataset folder exists and contains the downloaded MEG/MRI data
- Memory issues: Large datasets may require substantial RAM; consider processing subjects in batches
- FreeSurfer preprocessing: MRI files must be processed with FreeSurfer before running the head model pipeline
For questions or issues, please open an issue on the GitHub repository.
See LICENSE file for details.
- PAC analysis code adapted from Franziska Pellegrini and Stefan Haufe
- FieldTrip, Brainstorm, and FreeSurfer development teams
- Data contributors and participants