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.
The mathematical foundation of filtering is convolution. The MATLAB
performs standard one-dimensional convolution, convolving one vector
conv([1 1 1],[1 1 1]) ans = 1 2 3 2 1
Convolve rectangular matrices for two-dimensional signal processing
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
in length, and the input x(k)
is also of finite length, you can implement the filter
conv. Store x(k)
in a vector
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);
The length of the output is the sum of the finite-length input vectors minus 1.
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.
Many standard names for filters reflect the number of
The acronyms AR, MA, and ARMA are usually applied to filters associated with filtered stochastic processes.
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 side and take the inverse Z-transform.
In terms of current and past inputs, and past outputs, y(k) 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
the coefficients of a filter in transfer function form. Note that
A coefficient vectors are written as if the
output and input terms are separated in the difference equation. For
the example, the previous coefficient vectors represent a linear constant-coefficient
difference equation of
Changing the sign of the
results in the difference equation
The previous coefficients are represented as:
B = 1; %Numerator A = [1 0.9]; %Denominator
y = filter(B,A,x);
filter gives you as many output samples as
there are input samples, that is, the length of
the same as the length of
x. If the first element
a is not 1,
the coefficients by
a(1) before implementing the