Products & Services Solutions Academia Support User Community Company

Learn more about Signal Processing Toolbox   

Filter Implementation and Analysis

Filtering Overview

This section describes how to filter discrete signals using the MATLAB® filter function and other Signal Processing Toolbox™ functions. It also discusses how to use the toolbox functions to analyze filter characteristics, including impulse response, magnitude and phase response, group delay, and zero-pole locations.

Convolution and Filtering

The mathematical foundation of filtering is convolution. The MATLAB conv function performs standard one-dimensional convolution, convolving one vector with another:

conv([1 1 1],[1 1 1])
ans =
     1     2     3     2     1

A digital filter's output y(k) is related to its input x(k) by convolution with its impulse response h(k).

If a digital filter's impulse response h(k) is finite length, and the input x(k) is also finite length, you can implement the filter using conv. Store x(k) in a vector x, h(k) in a vector h, and convolve the two:

x = randn(5,1);     % A random vector of length 5
h = [1 1 1 1]/4;    % Length 4 averaging filter
y = conv(h,x);

Filters and Transfer Functions

In general, the z-transform Y(z) of a digital filter's output y(n) is related to the z-transform X(z) of the input by

where H(z) is the filter's transfer function. Here, the constants b(i) and a(i) are the filter coefficients and the order of the filter is the maximum of n and m.

MATLAB filter functions store the coefficients in two vectors, one for the numerator and one for the denominator. By convention, it uses row vectors for filter coefficients.

Filter Coefficients and Filter Names

Many standard names for filters reflect the number of a and b coefficients present:

The acronyms AR, MA, and ARMA are usually applied to filters associated with filtered stochastic processes.

Filtering with the filter Function

It is simple to work back to a difference equation from the z-transform relation shown earlier. Assume that a(1) = 1. Move the denominator to the left-hand side and take the inverse z-transform.

In terms of current and past inputs, and past outputs, y(n) is

This is the standard time-domain representation of a digital filter, computed starting with y(1) and assuming zero initial conditions. This representation's progression is

A filter in this form is easy to implement with the filter function. For example, a simple single-pole filter (lowpass) is

b = 1;          % Numerator
a = [1 -0.9];   % Denominator

where the vectors b and a represent the coefficients of a filter in transfer function form. To apply this filter to your data, use

y = filter(b,a,x);

filter gives you as many output samples as there are input samples, that is, the length of y is the same as the length of x. If the first element of a is not 1, filter divides the coefficients by a(1) before implementing the difference equation.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS