# Example MATLAB scripts

Here you can find example MATLAB scripts together with documentation that show specific analyses done in FieldTrip or in MATLAB. The documentation here is often not as elaborate as the tutorials, but goes more in detail into specific aspects of the data, code or analysis.

We invite you to add your own example scripts or frequently asked questions to the website. Also tutorials can be added. Every time you explain somebody something about FieldTrip, please consider whether you could use the website for this, so others can learn from it as well. If you want to contribute one of your example scripts, please add it directly to the website or contact us.

See also the tutorials and frequently asked questions.

### Reading and preprocessing data

- Getting started with reading raw EEG or MEG data
- Making your own trialfun for conditional trial definition
- Detect the muscle activity in an EMG channel and use that as trial definition
- Independent component analysis (ICA) to remove ECG artifacts
- Independent component analysis (ICA) to remove EOG artifacts
- Combine MEG with Eyelink eyetracker data
- Use denoising source separation (DSS) to remove ECG artifacts
- Fixing a missing sensor
- Re-reference EEG and iEEG data

### Sensor-level analysis

- Analyzing NIRS data recorded during unilateral finger- and foot-tapping
- Analyzing NIRS data recorded during listening to and repeating speech
- The correct pipeline order for combining planar MEG channels
- How to incorporate head movements in MEG analysis
- Interpolating data from the CTF151 to the CTF275 sensor array using ft_megrealign

### Spectral analysis

- Analysis of high-gamma band signals in human ECoG
- Analyze Steady-State Visual Evoked Potentials (SSVEPs)
- Cross-frequency analysis
- Effect of Signal-to-Noise Ratio on Coherence
- Effects of tapering for power estimates
- Fourier analysis of oscillatory power and coherence
- Simulate an oscillatory signal with phase resetting
- Irregular Resampling Auto-Spectral Analysis (IRASA)
- Fitting oscillations and one-over-F (FOOOF)
- Conditional Granger causality in the frequency domain

### Source reconstruction

- Align EEG electrode positions to BEM headmodel
- Check the quality of the anatomical coregistration
- Combined EEG and MEG source reconstruction
- Common filters in beamforming
- Compute EEG leadfields using a FEM headmodel
- Compute forward simulated data and apply a beamformer scan
- Compute forward simulated data and apply a dipole fit
- Compute forward simulated data using ft_dipolesimulation
- Compute forward simulated data with the low-level ft_compute_leadfield
- Create MNI-aligned grids in individual head-space
- Determine the filter characteristics
- Fit a dipole to the tactile ERF after mechanical stimulation
- How to create a head model if you do not have an individual MRI
- Localizing the sources underlying the difference in event-related fields
- Make leadfields using different headmodels
- Read neuromag .fif mri and create a MNI-aligned single-shell head model
- Testing BEM created lead fields
- Use your own forward leadfield model in an inverse beamformer computation

### Statistical analysis

- Apply non-parametric statistics with clustering on TFRs of power that were computed with BESA
- Computing and reporting the effect size
- Defining electrodes as neighbours for cluster-level statistics
- Source statistics
- Stratify the distribution of two variables
- Use simulated ERPs to explore cluster statistics
- Using GLM to analyze NIRS timeseries data
- Using General Linear Modeling over trials
- Using General Linear Modeling on time series data
- Using simulations to estimate the sample size for cluster-based permutation test
- Using threshold-free cluster enhancement for cluster statistics

### Real-time analysis

- Example real-time average
- Example real-time classification
- Example real-time power estimate
- Example real-time selective average
- Example real-time signal viewer
- Measuring the timing delay and jitter for a real-time application
- Realtime neurofeedback application based on Hilbert phase estimation

## Plotting and visualization

- Creating a layout for plotting NIRS optodes and channels
- Plotting the result of source reconstructing on a cortical mesh
- Making a synchronous movie of EEG or NIRS combined with video recordings

## Various other examples

- BIDS - the brain imaging data structure
- Combining simultaneous recordings in BIDS
- Converting an example audio dataset for sharing in BIDS
- Converting an example behavioral dataset for sharing in BIDS
- Converting an example EEG dataset for sharing in BIDS
- Converting an example EMG dataset for sharing in BIDS
- Converting an example eyetracker dataset for sharing in BIDS
- Converting an example MEG dataset for sharing in BIDS
- Converting an example motion tracking dataset for sharing in BIDS
- Converting an example NIRS dataset for sharing in BIDS
- Converting an example video dataset for sharing in BIDS
- Converting the combined MEG/fMRI MOUS dataset for sharing in BIDS
- Making your analysis pipeline reproducible using reproducescript
- Using reproducescript for a group analysis
- Using reproducescript on a full study
- Correlation analysis of fMRI data
- Example analysis pipeline for Biosemi bdf data
- Find the orientation of planar gradiometer channels
- How to import data from MNE-Python and FreeSurfer
- How to use ft_checkconfig
- Performing modified Multiscale Entropy (mMSE) analysis