filter

Filter a signal with an IIR or FIR filter.

Syntax

y=filter(b,a,x)

[y,sf]=filter(b,[],x)

[y,sf]=filter(b,a,x,si,dim)

[y,sf]=filter(b,a,x,[],dim)

[y,sf]=filter(...)

Inputs

b
The numerator polynomial coefficients of the filter.
Type: double
Dimension: vector
a
The denominator polynomial coefficients of the filter.
Type: double
Dimension: vector
x
The signal to be filtered. If x is a matrix, then each column is filtered.
Type: double
Dimension: vector | matrix
si
The initial state conditions.
In the multi-dimensional case the dimensions must correspond to those of x.
Type: double
Dimension: vector | matrix
dim
The dimension on which to operate, for both x and si.
Default: first non-singleton dimension.
Type: integer
Dimension: scalar

Outputs

y
The filtered signal.
Dimension: vector | matrix
sf
The final state conditions.
Type: double
Dimension: vector | matrix

Example

Filter a signal with a 100 Hz Butterworth filter using filter.

% define signal
f1 = 62.5;
f2 = 250;
omega1 = 2*pi*f1;
omega2 = 2*pi*f2;
fs = 2000;
ts = 1/fs;
n = 100;
t = [0:ts:n*ts];
signal = sqrt(2) * sin(0.5*omega1*t) + sin(omega1*t) + 0.25 * sin(omega2*t);

% define filter
[a,b] = butter(4,100/(fs/2));

% filter signal and plot
output = filter(a,b,signal);
plot(t,signal);
hold on;
plot(t,output);
legend('raw signal', 'filtered signal');
Figure 1. filter figure 1


Comments

An infinite impulse response (IIR) filter has both a numerator and a denominator. A finite impulse response (FIR) filters has only a numerator, so its denominator is specified as [].

A common use for the si and sf arguments is to allow a filter operation to be interrupted and later resumed without introducing a new startup transient response when resuming.