Signal Processing Toolbox Help Desk

Purpose

Filter data with a recursive (IIR) or nonrecursive (FIR) filter.

Syntax

```y = filter(b,a,x)
[y,zf] = filter(b,a,x)
[...] = filter(b,a,x,zi)
[...] = filter(b,a,x,zi,dim)
```

Description

`filter` is part of the MATLAB environment. It filters data using a digital filter. The filter realization is the transposed direct form II structure , which can handle both FIR and IIR filters.

If a(1) 1, `filter` normalizes the filter coefficients by a(1). If a(1) = 0, the input is in error.

```y = filter(b,a,x) ``` filters the data in vector `x` with the filter described by coefficient vectors `a` and `b` to create the filtered data vector `y`. When `x` is a matrix, filter operates on the columns of `x`. When `x` is an N-dimensional array, filter operates on the first non-singleton dimension.

```[y,zf] = filter(b,a,x) ``` returns the final values of the states in the vector `zf`.

```[...] = filter(b,a,x,zi) ``` specifies initial state conditions in the vector `zi`.

The size of the initial/final condition vector is `max(length(b),length(a))-1`. `zi` or `zf` can also be an array of such vectors, one for each column of `x` if `x` is a matrix. If `x` is a multidimensional array, `filter` works across the first nonsingleton dimension of `x` by default.

```[...] = filter(b,a,x,zi,dim) ``` works across the dimension `dim` of `x`. Set `zi` to empty to get the default initial conditions.

`filter` works for both real and complex inputs.

Example

Find and graph the 100-point unit impulse response of a digital filter:

```x = [1 zeros(1,100)];
[b,a] = butter(12,400/1000);
y = filter(b,a,x);
stem(y) ```

Algorithm

`filter` is a built-in MATLAB function. `filter` is implemented as a transposed direct form II structure where n-1 is the filter order.

The operation of `filter` at sample m is given by the time domain difference equations for y and the states zi : You can use `filtic` to generate the state vector zi(0) from past inputs and outputs.

The input-output description of this filtering operation in the z-transform domain is a rational transfer function: Diagnostics

If a(1) = 0, `filter` gives the following error message:

```First denominator coefficient must be nonzero.
```
If the length of the initial condition vector is not the greater of na and nb, `filter` gives the following error message:

```Initial condition vector has incorrect dimensions.
```

 ```fftfilt ``` ```filter2 ``` ```filtfilt ``` ```filtic ``` Make initial conditions for `filter` function.