> For the complete documentation index, see [llms.txt](https://nigelrogasch.gitbook.io/tesa-user-manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nigelrogasch.gitbook.io/tesa-user-manual/remove_minimise_tms_muscle_activity/detrend.md).

# Detrend

This function detrends the data by fitting and subtracting a function from each channel. Either a linear (fitted and subtracted from each trial), exponential or double exponential function (fitted to average and subtracted from each trial) can be fitted.

Note that the Curve Fitting Toolbox is required to run either the exponential or the double exponential fit.

## EEGLAB user interface

![](https://3092694373-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmJDCxgyXG9A9GA-gSy%2F-LmJDDdbvCHG7SXDX4aP%2F-LmJDGOW0QasUjgfKIIO%2Fdetrend.png?generation=1565854875316484\&alt=media)

**1.** Select the type of function that will be fitted to the data: either linear, exponential or double (i.e. double exponential).

**2.** Enter the time range over which the detrend will be fitted and applied (in ms).

## Scripts

### Base function

`EEG = tesa_detrend( EEG, detrend, timeWin );` Default use.

### Pop function

`EEG = pop_tesa_detrend( EEG );` Pop up window.

`EEG = pop_tesa_detrend( EEG, detrend, timeWin );` Custom inputs.

### Required inputs

| Input   | Description                                                                   | Example   | Default |
| ------- | ----------------------------------------------------------------------------- | --------- | ------- |
| EEG     | EEGLAB EEG structure                                                          | EEG       | -       |
| detrend | String with type of detrend to perform; 'linear'  or 'exponetial' or 'double' | 'linear'  | -       |
| timeWin | Vector setting time window for detrending in ms. \[start, end]                | \[11,500] | -       |

### Outputs

| Output | Description          |
| ------ | -------------------- |
| EEG    | EEGLAB EEG structure |

### Examples

`EEG = pop_tesa_detrend( EEG, 'linear', [11,500]);` Linear detrend.

`EEG = pop_tesa_detrend( EEG, 'exponential', [11,500]);` Exponential detrend.

`EEG = pop_tesa_detrend( EEG, 'double', [11,500]);` Double exponential detrend.
