| DSP Blockset | Search  Help Desk |
| Least Squares FIR Filter Design | Examples See Also |
Design and implement a least-squares FIR filter.
Library
Filter Designs, in FilteringDescription
The Least Squares FIR Filter Design block designs an FIR filter and applies it to the input using the Direct-Form II Transpose Filter block in the Filter Realizations library. The filter design uses thefirls function in the Signal Processing Toolbox to minimize the integral of the squared error between the desired frequency response and the actual frequency response.
The Filter type parameter allows you to specify one of the following filters:
The Multiband filter designs a linear-phase filter with an arbitrary magnitude response.
The Differentiator filter approximates the ideal differentiator. Differentiators are antisymmetric FIR filters with approximately linear magnitude responses. To obtain the correct derivative, scale the Gains at these frequencies vector by
Fs rads/sec, where Fs is the sample frequency in Hertz.
The Hilbert Transformer filter approximates the ideal Hilbert transformer. Hilbert transformers are antisymmetric FIR filters with approximately constant magnitude.
0 to 1, where 1 corresponds to half the sampling frequency (the Nyquist frequency). This vector must have even length, and intermediate points must appear in ascending order. The Gains at these frequencies parameter is a vector containing the desired magnitude response at the corresponding points in the Band-edge frequency vector.
Each odd-indexed frequency-amplitude pair defines the left endpoint of a line segment representing the desired magnitude response in that frequency band. The corresponding even-indexed frequency-amplitude pair defines the right endpoint. Between the frequency bands specified by these end-points, there may be undefined sections of the specified frequency response. These are called "don't care" or "transition" regions, and the magnitude response in these areas is a result of the optimization in the other (specified) frequency ranges.

The Weights parameter is a vector that specifies the emphasis to be placed on minimizing the error in certain frequency bands relative to others. This vector specifies one weight per band, so it is half the length of the Band-edge frequency vector and Gains at these frequencies vectors.
In most cases, differentiators and Hilbert transformers have only a single band, so the weight is a scalar value that does not affect the final filter. However, the Weights parameter is useful when using the block to design an antisymmetric multiband filter, such as a Hilbert transformer with stopbands. For more information on the Band-edge frequency vector, Gains at these frequencies, and Weights parameters, see the "Working with Filter Designs" section of Chapter 3. For more on the FIR filter algorithm, see the description of thefirls function in the Signal Processing Toolbox User's Guide.
The Frame-based inputs parameter allows you to choose between sample-based and frame-based operation.
Sample-Based Operation
When the check box is not selected (default), the block assumes that the input is a 1-by-N sample vector or M-by-N sample matrix. Each of the N vector elements (or M*N matrix elements) is treated as an independent channel, and the block filters each channel over time.Frame-Based Operation
When the Frame-based inputs check box is selected, the block assumes that the input is an M-by-N frame matrix. Each of the N frames in the matrix contains M sequential time samples from an independent signal. The Number of channels parameter specifies the number of independent channels (columns), N, in the matrix, and the block filters each channel independently over time. Frame-based operation provides substantial increases in throughput rates, at the expense of greater model latency. In both sample-based and frame-based operation, the output is the same size as the input.Dialog Box

0 to 1. The value 1 corresponds to the Nyquist frequency. This vector must have even length.Examples
Example 1: Multiband
Consider a lowpass filter with a transition band in the normalized frequency range 0.4 to 0.5, and 10 times more error minimization in the stopband than the passband. In this case,[0 0.4 0.5 1]
[1 1 0 0]
[1 10]
Example 2: Differentiator
Assume the specifications for a differentiator filter require it to have order 21. The "ramp" response extends over the entire frequency range. In this case, specify:21
[0 1]
[0 pi*Fs]
20
[0 0.9]
[0 0.9*pi*Fs]
Example 3: Hilbert Transformer
Assume the specifications for a Hilbert transformer filter require it to have order 21. The passband extends over approximately the entire frequency range. In this case, specify:21
[0.1 1]
[1 1]
References
Oppenheim, A. V. and R. W. Schafer. Discrete-Time Signal Processing. Englewood Cliffs, NJ: Prentice Hall, 1989. Proakis, J. and D. Manolakis. Digital Signal Processing. 3rd ed. Englewood Cliffs, NJ: Prentice-Hall, 1996.See Also
Digital FIR Filter Designfirls (Signal Processing Toolbox)