You can keep other project helpers (e.g., pre_post_val.m, group_sleep_var.m, task_para4plot.m, groups_indx.m, Fisher_transf.m, donutchart.m, daviolinplot.m) under /helpers as well.
- Clone/download this repository.
- Add FieldTrip (and optionally EEGLAB) to your MATLAB path and run
ft_defaults. - Copy your template files into
/templatesor update paths in scripts (all paths are written with<YOUR_PATH>placeholders—set them once at the top of each script as instructed in comments). - Keep raw data and subject lists under
/data(not committed).
- Raw EEG: EGI high-density .mff per subject.
- Sleep staging: CSV/Excel with epoch codes (30-s epochs). Project uses the stage codes:
200 = Wake, 100 = REM, -100 = N1, -200 = N2, -300 = N3.
- Subject list: a MATLAB file (e.g.,
subjects_files_2.mat) with fields:mff_file,scoring_csv,subject,group.
Use preper_sleep_data4.m (called by your batch script) to:
- Load .mff, apply band-pass 0.5–45 Hz, remove line noise (50 Hz & harmonics via DFT or notch),
- Resample to 250 Hz,
- Segment into 30-s epochs,
- Align/sanitize staging vector length, and
- Save epoched FieldTrip data (
data,epoched_scoring).
Note on line noise: The scripts support both a narrow notch and FieldTrip’s DFT filter (cfg.dftfilter='yes'; cfg.dftfreq=[50 100 150];). Choose one consistently.
Run prep_REM_sleep_stages.m to:
- Select REM epochs only.
- Create eyes and brain datasets; eyes electrodes are set to
NaNin brain data to preserve indexing. - Mark bad channels per subject (edit the
bad_eyes_chn/bad_brain_chnlists). - Interactive inspection with
ft_databrowserand trial/channel rejection withft_rejectvisual. - ICA (
ft_componentanalysis,method='runica'by default). Useplot_top_comp.mfor component maps; manually list components to remove. - Reconstruct clean data with
ft_rejectcomponent. - Interpolate bad/missing channels with
Fix_bad_Chann(usesft_channelrepair) andFix_Miss_Chann. - Save
<subject>_clean_REM.matand akeep_trackstruct documenting: removed trials, removed channels, ICA components, etc.
Use sleep_group_cal.m (REM-only) to:
- Load cleaned subject files per group folder,
- Interpolate/fix channels again for safety,
- Re-reference (
avgor as configured), reorder labels if needed, - Compute power with
sleep_frequency_bands.m(bands: All, δ, θ, α, σ, β, γ), and - Collect into
freq_controlandfreq_PD(per-band cell arrays of FieldTripfreqstructures).
Run REM_GroupSpectralStats_Main.m to:
- Produce multi-band topographies per group:
topo_SpectralBands_3groups_multiFig.m(Control, PD−RSWA, PD+RSWA). - Compute cluster-based T-maps between groups:
Tmaps_3groups_multiFig.m(usesmontecarlo_statistics3). - Plot ROI violin plots and run pairwise tests:
daviolinplot_3groups.m/daviolinplot_3groups_singleROI.m. - Run per-band omnibus ANOVA:
bands_ANOVA_3group.mor full permutation ANOVAANOVA_3group_freq_new.m.
Statistical note. Pairwise tests/visualizations are treated as post-hoc. Use them after an omnibus ANOVA shows a significant group effect, or interpret with appropriate multiplicity control (e.g., BH-FDR with
FDR_corr.m).
- GML_Sleep_Correlation_Plots.m – scatter + regression (by subgroup) for any sleep metric vs GML improvement.
- plot_sleep2task_diff_size.m – same but X = REM% (REM/TST×100), with point size by RSWAi via
RSWAi_2scattSize.m. - daviolinplot_RSWAi.m – RSWAi distributions (phasic/tonic/any) for Control vs PD.
- sleep_donut.m – group donut plots of sleep stage composition.
- Filtering: 0.5–45 Hz band-pass. Add DFT notch at 50/100/150 Hz as needed.
- Epoching: 30-s (aligned to staging). Ensure
scoringlength matches data length; script pads/trims accordingly. - Resampling: to 250 Hz if original is 1000 Hz.
- Stage codes:
200=Wake, 100=REM, -100=N1, -200=N2, -300=N3. - Frequency bands:
[0.5–40/45], δ [0.5–4], θ [4–8], α [8–12], σ [12–15], β [15–25], γ [25–45](configurable). - Statistics: BH-FDR via
FDR_corr.m; permutation ANOVA viaANOVA_3group_freq_new.m.
- Bad channels: set
bad_eyes_chn,bad_brain_chnper subject before REM cleaning. - Visual rejection: use
ft_rejectvisualinprep_REM_sleep_stages.m(keeps NaNs to preserve indexing where necessary). - ICA components: decide visually using
plot_top_comp.m; list components to remove in the script. ECG-like components can also be saved separately. - Provenance: the
keep_trackstruct records removed channels, trials, and components for reporting.
- Line noise persists: prefer FieldTrip’s
dftfilterwithdftfreq=[50 100 150]. Avoid stacking notch + DFT simultaneously. - Label mismatches (E257/VREF): use
Fix_bad_Chann/Fix_Miss_Channand provided templates to normalize labels. - ICA fails or components look odd: check referencing and that only brain channels (not eye channels) drive the ICA input.
- Missing functions: some plotting/stat helpers are third-party (
daviolinplot,donutchart). Add them to the MATLAB path.
Lanir-Azaria S, Nir Y, Tauman R, Zitser J, Giladi N. (2023). Beyond RBD: Covert REM sleep abnormalities in Parkinson’s disease. npj Parkinson’s Disease.
Questions or issues? Please open an issue or contact Saar Lanir-Azaria.