| Signal Processing Toolbox | ![]() |
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
y filters the data in vector = filter(b,a,x)
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 nonsingleton dimension. a(1) cannot be 0, and if a(1)
1, filter normalizes the filter coefficients by a(1).
[y,zf] returns the final values = filter(b,a,x)
zf of the state vector. When x is a vector, the size of the final condition vector zf is max(length(b),length(a))-1, the number of delays in the filter. When x is a multidimensional array, zf is an s-by-c matrix, where:
prod(size(x))/size(x,dim), where dim is the dimension into which you are filtering (the first nonsingleton dimension by default).[...] specifies initial state conditions in the vector = filter(b,a,x,zi)
zi. The size of the initial condition vector zi must be the same as max(length(b),length(a))-1, the number of delays in the filter.
[...] filters the input data located along the dimension = filter(b,a,x,zi,dim)
dim of x. Set zi to the empty vector [] to use zero initial conditions.
The filter function is part of the standard MATLAB language.
Examples
Find and graph the 101-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 implemented as a transposed direct form II structure [1], as shown below
where n-1 is the filter order. The state vector z is a vector whose components are derived from the values of the inputs to each delay in the filter.
The operation of filter at sample m is implemented using the transposed direct form II structure. This is calculated by the time domain difference equations for y and the states zi.
Note the division by a(1). For efficient computation, select this coefficient to be a power of 2.
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.
See Also
fftfilt, filter2, filtfilt, filtic
References
[1] Oppenheim, A.V., and R.W. Schafer, Discrete-Time Signal Processing, Prentice-Hall, 1989, pp. 311-312.
| fftshift | filter2 | ![]() |