> 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/filter_data/butterworth_filter.md).

# Butterworth filter

This function filters the data using a zero-phase butterworth filter. Either a band pass, band stop, high pass, or low pass filter can be implemented. The filter order is defined by the user. This function uses the Matlab `butter` and `filtfilt` functions.

## EEGLAB user interface

![](/files/-LmJDKEbcWLPGJVscX-y)

**1.** Enter the frequencies for filtering.

**2.** Enter the order of the filter.

**3.** Select the filter type. For a band-pass filter, frequencies outside of the high and low pass cutoffs will be excluded, whereas for the band-stop filter, frequencies within the high and low pass cutoffs will be excluded. For a high-pass filter, frequencies below the cutoff will be excluded (note that low-pass field can be left blank), whereas for a low-pass filter, frequencies above the cuttoff will be excluded (note that high-pass field can be left blank).

## Scripts

### Base function

`EEG = tesa_filtbutter( EEG, high, low, ord, type );` Default use.

### Pop function

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

`EEG = pop_tesa_filtbutter( EEG, high, low, ord, type );` Custom inputs

### Required inputs

| Input | Description                                                                                                                                                                              | Example    | Default |
| ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------- |
| EEG   | EEGLAB EEG structure                                                                                                                                                                     | EEG        | -       |
| high  | Integer setting the high pass frequency                                                                                                                                                  | 1          | -       |
| low   | Integer setting the low pass frequency                                                                                                                                                   | 100        | -       |
| ord   | Integer setting the filter order                                                                                                                                                         | 4          | -       |
| type  | String which sets the design of either a zero-phase band pass, band stop , high pass or low pass butterworth filter; string is either 'bandpass',  'bandstop', 'highpass', or 'lowpass'. | 'bandpass' | -       |

### Outputs

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

### Examples

`EEG = pop_tesa_filtbutter( EEG, 1, 100, 4, 'bandpass' );` Zero-phase, 4th-order band pass butterworth filter between 1-100 Hz.

`EEG = pop_tesa_filtbutter( EEG, 48, 52, 4, 'bandstop' );` Zero-phase, 4th-order band stop butterworth filter between 48-52 Hz.

`EEG = tesa_filtbutter( EEG, 1, [], 4, 'highpass' );` Zero-phase, 4th-order high pass butterworth filter allowing frequencies above 1 Hz

`EEG = tesa_filtbutter( EEG, [], 45, 4, 'lowpass' );` Zero-phase, 4th-order low pass butterworth filter allowing frequencies below 45 Hz


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://nigelrogasch.gitbook.io/tesa-user-manual/filter_data/butterworth_filter.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
