# 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 wiki. Also tutorials can be added. Every time you explain somebody something about FieldTrip, please consider whether you could use the wiki for this so others can learn from it as well. If you want to contribute one of your scripts, please add it directly to the wiki 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
- Fixing a missing sensor
- Use independent component analysis (ICA)_to_remove_ECG_artifacts
- Use independent component analysis (ICA)_to_remove_EOG_artifacts
- Interpolating data from the CTF151 to the CTF275 sensor array using ft_megrealign
- Detect the muscle activity in an EMG channel and use that as trial definition
- How to incorporate head movements in MEG analysis
- The correct pipeline order for combining planar MEG channels

### Spectral analysis

- Fourier analysis of oscillatory power and coherence
- Cross-frequency analysis
- Effects of tapering for power estimates
- Simulate an oscillatory signal with phase resetting
- Analyze Steady-State Visual Evoked Potentials (SSVEPs)
- Effect of Signal-to-Noise Ratio on Coherence
- Analysis of high-gamma band signals in human ECoG

### Source reconstruction

- Align EEG electrode positions to BEM headmodel
- Compute forward simulated data and apply a dipole fit
- Compute forward simulated data and apply a beamformer scan
- Testing BEM created lead fields
- Create MNI-aligned grids in individual head-space
- Determine the filter characteristics
- Fit a dipole to the tactile ERF after mechanical stimulation
- Make leadfields using different headmodels
- Use your own forward leadfield model in an inverse beamformer computation
- Common filters in beamforming
- Read neuromag .fif mri and create MNI-aligned single_shell grids in individual head-space
- Using the low-level compute_leadfield function
- Plotting the result of source reconstructing on a cortical mesh
- Combined EEG and MEG source reconstruction
- Localizing the sources underlying the difference in event related fields
- Check the quality of the anatomical coregistration
- Sphere fitting and scaling of the template (Colin27) MRI to the MEG polhemus headshape

### Statistical analysis

- Stratify the distribution of two variables
- Source statistics
- Apply clusterrandanalysis on TFRs of power that were computed with BESA
- Use simulated ERPs to explore cluster statistics
- How can I compute and report the effect size?

### Real-time analysis

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

### Miscellaneous

- Correlation analysis in fMRI data
- How to use checkconfig
- Writing simulated data to a CTF dataset
- Example analysis pipeline for Biosemi bdf data
- Find the orientation of planar gradiometer channels
- How to import data from MNE-Python and FreeSurfer
- Preparing an MEG+fMRI dataset for sharing
- Preparing an EEG dataset for sharing