# Interpolate removed data

This function replaces removed data using interpolation. Either linear or cubic interpolation can be used. All data that has been previously removed will be interpolated. Note that either [tesa\_removedata or pop\_tesa\_removedata](remove_tms_pulse) must be ran prior to this function.

## EEGLAB interface

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

**1.** Choose the type of interpolation to perform on the data from the drop down menu.

Linear - performs a linear interpolation between the existing data points either side of the removed data.

Cubic - performs a cubic interpolation using Matlab's polyfit function. A cubic function is fitted on the data either side of the removed data indicated in _2_.

**2.** Time window for fitting cubic. This determines how many milliseconds either side of the removed data are considered when fitting the cubic function. Default values are 20 ms. Note that at least two samples must be present in each window for fitting a cubic function (e.g. if the data are sampled at 1 kHz a 1 ms window will only have 1 sample, however if the data are sampled at 5 kHz a 1 ms window will have 5 samples).

## Script

### Base function

`EEG = tesa_interpdata( EEG, interpolation );` Default use.

`EEG = tesa_interpdata( EEG, interpolation, interpWin );` Custom input.

### Pop function

`EEG = pop_tesa_interpdata( EEG );` Pop up window

`EEG = pop_tesa_interpdata( EEG, interpolation );` Default use.

`EEG = pop_tesa_interpdata( EEG, interpolation, interpWin );` Custom input.

### Required inputs

| Inputs        | Description                                                                               | Example   | Default  |
| ------------- | ----------------------------------------------------------------------------------------- | --------- | -------- |
| EEG           | EEGLAB EEG structure                                                                      | EEG       | -        |
| interpolation | (Required) String describing type of interpolation, either 'linear' or 'cubic'            | 'linear'  | -        |
| interpWin     | (Optional) Vector with times before and after artifact window for fitting cubic function. | \[20, 20] | \[20,20] |

### Outputs

| Outputs | Description          |
| ------- | -------------------- |
| EEG     | EEGLAB EEG structure |

### Examples

`EEG = pop_tesa_interpdata( EEG, 'linear' );` replaces missing data with linear interpolation. Linear function is fitted on data point before and after missing data.

`EEG = pop_tesa_interpdata( EEG, 'cubic', [50,50] );` replaces mising data with cubic interpolation. Cubic is fitted on data 50 ms before and 50 ms after missing data
