Hauptinhalt

Filter Requirements and Specification

Filter design is the process of creating the filter coefficients to meet specific filtering requirements. Filter implementation involves choosing and applying a particular filter structure to those coefficients. Only after both design and implementation have been performed can data be filtered. The following chapter describes filter design and implementation in Signal Processing Toolbox™ software.

The goal of filter design is to perform frequency dependent alteration of a data sequence. A possible requirement might be to remove noise above 200 Hz from a data sequence sampled at 1000 Hz. A more rigorous specification might call for a specific amount of passband ripple, stopband attenuation, or transition width. A very precise specification could ask to achieve the performance goals with the minimum filter order, or it could call for an arbitrary magnitude shape, or it might require an FIR filter. Filter design methods differ primarily in how performance is specified.

To design a filter, the Signal Processing Toolbox software offers two approaches. The first approach uses the designfilt function. As an example, design and implement a 5th-order lowpass Butterworth filter with a 3-dB frequency of 200 Hz. Assume a sample rate of 1 kHz. Apply the filter to input data.

Fs = 1000;
fc = 200;
time = 0:1/Fs:1;
x = cos(2*pi*60*time)+sin(2*pi*120*time)+randn(size(time));

d = designfilt('lowpassiir','FilterOrder',5, ...
    'HalfPowerFrequency',fc,'DesignMethod','butter', ...
    'SampleRate',Fs);
yd = filter(d,x);

The other approach implements the filter using a function such as butter or firpm. All of these "classic" filter design functions operate with normalized frequencies. Convert frequency specifications in Hz to normalized frequency to use these functions. The Signal Processing Toolbox software defines normalized frequency to be in the closed interval [0,1], with 1 denoting π rad/sample. For example, to specify a normalized frequency of π/2 rad/sample, enter 0.5.

To convert from Hz to normalized frequency, multiply the frequency in Hz by two and divide by the sampling frequency. For example, design a 5th-order lowpass Butterworth filter with a 3-dB frequency of 200 Hz using butter.

Wn = fc/(Fs/2);

[b,a] = butter(5,Wn,'low');
yb = filter(b,a,x);

Plot the two filtered signals.

plot(time,yd,time,yb)
legend('designfilt','butter')

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent designfilt, butter.

See Also

| |