Skip to content

filter

Filter for vectors

We consider a filter having the system function: $$ H(z)=\frac{b_0+b_1z^{-1}+b_2z^{-2}+\cdots+b_Nz^{-N}}{a_0+a_1z^{-1}+a_2z^{-2}+\cdots+a_Nz^{-N}}, $$ where a_0=1,a_1,\ldots,a_N, and b_0,b_1,\ldots,b_N are real numbers. The function filter is implemented based on the transposed direct form II structure:

filter structure

For n=1,2,\ldots, the difference equations for the above filter are given by

\begin{align} y(n)&=w_1(n-1)+b_0x(n),\\ w_k(n)&=w_{k+1}(n-1)-a_ky(n)+b_kx(n),\ k=1,2,\ldots,N-1,\\ w_N(n)&=b_Nx(n)-a_Ny(n). \end{align}

y = filter(b, a, x, wi)

[y, wf] = filter(b, a, x, wi)

  • a and b are vectors of real numbers, containing filter coefficients a_0,a_1,\ldots,a_N and b_0,b_1,\ldots,b_N, respectively. The numbers a(1) and b(1) correspond to the lowest order tems.
  • If a(1) is not 1, each element of a and b are divided by a(1) before filtering. Hence, a(1) must be non-zero.
  • Input x contains data to be filtered, and y contains the filtered data. The output y has the same size as x.
  • wi contains values at the outputs of the delay blocks when the filtering begins.
  • If wi is a vector, it should have length N = max(length(a), length(b)) - 1. If x is multi-dimensional, the same vector wi is applied to all dimensions of x.
  • If wi is multi-demensional, its size should be [N sz[1:(dim - 1) (dim + 1):ndims(x)]], where N is equal to max(length(a), length(b)) - 1, sz = size(x), and dim is the first nonsingleton dimension of x.
  • If x is a vector, the filter is applied along the longer dimension. Otherwise, it is applied to vectors along the first nonsingleton dimension.
  • wf contains values at the outputs of the delay blocks when the filtering ends.

y = filter(b, a, x)

[y, wf] = filter(b, a, x)

  • They are the same as y = filter(b, a, x, wi) and [y, wf] = filter(b, a, x, wi) with wi being a zero vector.

y = filter(b, a, x, wi, dim)

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

  • They are the same as y = filter(b, a, x, wi) and [y, wf] = filter(b, a, x, wi) except that the filter is applied to vectors along the dim-th dimension.
  • dim should be a real, positive integer not exceeding ndims(x). If wi is a vector, it should have length N = max(length(a), length(b)) - 1. If x is multi-dimensional, the same vector wi is applied to all dimensions of x.
  • If wi is multi-demensional, its size should be [N sz[1:(dim - 1) (dim + 1):ndims(x)]], where N is equal to max(length(a), length(b)) - 1, sz = size(x), and dim is as specified in the input argument.

Example 1: The vertical direction is the y-direction, whereas the horizontal direction is the x-direction.

[X,Y]=meshgrid(1:5)