| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Filter Design Toolbox |
| Contents | Index |
| Learn more about Filter Design Toolbox |
| On this page… |
|---|
Comparing Magnitude Response and Magnitude Response Estimate |
The conversion from floating-point to fixed-point consists of two main parts: quantizing the coefficients and performing the dynamic range analysis. Quantizing the coefficients is a process of converting the coefficients to fixed-point numbers. The dynamic range analysis is a process of fine tuning the scaling of each node to ensure that the fraction lengths are set for full input range coverage and maximum precision. The following steps describe this conversion process.
Start by designing a regular, floating-point, equiripple bandpass filter, as shown in the following figure.

where the passband is from .45 to .55 of normalized frequency, the amount of ripple acceptable in the passband is 1 dB, the first stopband is from 0 to .35 (normalized), the second stopband is from .65 to 1 (normalized), and both stopbands provide 60 dB of attenuation.
To design this filter, evaluate the following code, or type it at the MATLAB command prompt:
f = fdesign.bandpass(.35,.45,.55,.65,60,1,60); Hd = design(f, 'equiripple'); fvtool(Hd)
The last line of code invokes the Filter Visualization Tool, which displays the designed filter. You use Hd, which is a double, floating-point filter, both as the baseline and a starting point for the conversion.
The first step in quantizing the coefficients is to find the valid word length for the coefficients. Here again, the hardware usually dictates the maximum allowable setting. However, if this constraint is large enough, there is room for some trial and error. Start with the coefficient word length of 8 and determine if the resulting filter is sufficient for your needs.
To set the coefficient word length of 8, evaluate or type the following code at the MATLAB command prompt:
Hf = Hd; Hf.Arithmetic = 'fixed'; set(Hf, 'CoeffWordLength', 8); fvtool(Hf)
The resulting filter is shown in the following figure.

As the figure shows, the filter design constraints are not met. The attenuation is not complete, and there is noise at the edges of the stopbands. You can experiment with different coefficient word lengths if you like. For this example, however, the word length of 12 is sufficient.
To set the coefficient word length of 12, evaluate or type the following code at the MATLAB command prompt:
set(Hf, 'CoeffWordLength', 12); fvtool(Hf)
The resulting filter satisfies the design constraints, as shown in the following figure.

Now that the coefficient word length is set, there are other data width constraints that might require attention. Type the following at the MATLAB command prompt:
>> info(Hf) Discrete-Time FIR Filter (real) ------------------------------- Filter Structure : Direct-Form FIR Filter Length : 48 Stable : Yes Linear Phase : Yes (Type 2) Arithmetic : fixed Numerator : s12,14 -> [-1.250000e-001 1.250000e-001) Input : s16,15 -> [-1 1) Filter Internals : Full Precision Output : s31,29 -> [-2 2) (auto determined) Product : s27,29 -> [-1.250000e-001 1.250000e-001)... (auto determined) Accumulator : s31,29 -> [-2 2) (auto determined) Round Mode : No rounding Overflow Mode : No overflow
You see the output is 31 bits, the accumulator requires 31 bits and the multiplier requires 27 bits. A typical piece of hardware might have a 16 bit data bus, a 24 bit multiplier, and an accumulator with 4 guard bits. Another reasonable assumption is that the data comes from a 12 bit ADC. To reflect these constraints type or evaluate the following code:
set (Hf, 'InputWordLength', 12); set (Hf, 'FilterInternals', 'SpecifyPrecision'); set (Hf, 'ProductWordLength', 24); set (Hf, 'AccumWordLength', 28); set (Hf, 'OutputWordLength', 16);
Although the filter is basically done, if you try to filter some data with it at this stage, you may get erroneous results due to overflows. Such overflows occur because you have defined the constraints, but you have not tuned the filter coefficients to handle properly the range of input data where the filter is designed to operate. Next, the dynamic range analysis is necessary to ensure no overflows.
The purpose of the dynamic range analysis is to fine tune the scaling of the coefficients. The ideal set of coefficients is valid for the full range of input data, while the fraction lengths maximize precision. Consider carefully the range of input data to use for this step. If you provide data that covers the largest dynamic range in the filter, the resulting scaling is more conservative, and some precision is lost. If you provide data that covers a very narrow input range, the precision can be much greater, but an input out of the design range may produce an overflow. In this example, you use the worst-case input signal, covering a full dynamic range, in order to ensure that no overflow ever occurs. This worst-case input signal is a scaled version of the sign of the flipped impulse response.
To scale the coefficients based on the full dynamic range, type or evaluate the following code:
x = 1.9*sign(fliplr(impz(Hf))); Hf = autoscale(Hf, x);
To check that the coefficients are in range (no overflows) and have maximum possible precision, type or evaluate the following code:
fipref('LoggingMode', 'on', 'DataTypeOverride', 'ForceOff');
y = filter(Hf, x);
fipref('LoggingMode', 'off');
R = qreport(Hf)
Where R is shown in the following figure:

The report shows no overflows, and all data falls within the designed range. The conversion has completed successfully.
You can use the fvtool GUI to do final analysis on your quantized filter, to see the effects of the quantization on stopband attenuation, etc. Two important last checks when analyzing a quantized filter are the Magnitude Response Estimate and the Round-off Noise Power Spectrum. The value of the Magnitude Response Estimate analysis can be seen in the following example.
Viewing Magnitude Response Estimate
Begin by designing a simple lowpass filter using the command.
h = design(fdesign.lowpass, 'butter');
Now set the arithmetic to fixed-point.
h.arithmetic = 'fixed';
Open the filter using fvtool.
fvtool(h)
When fvtool displays the filter using the Magnitude response view, the quantized filter seems to match the original filter quite well.

However if you look at the Magnitude Response Estimate plot from the Analysis menu, you will see that the actual filter created may not perform nearly as well as indicated by the Magnitude Response plot.

This is because by using the noise-based method of the Magnitude Response Estimate, you estimate the complex frequency response for your filter as determined by applying a noise- like signal to the filter input. Magnitude Response Estimate uses the Monte Carlo trials to generate a noise signal that contains complete frequency content across the range 0 to Fs. For more information about analyzing filters in this way, refer to the section titled Analyzing Filters with a Noise-Based Method in the User Guide.
For more information, refer to McClellan, et al., Computer-Based Exercises for Signal Processing Using MATLAB 5, Prentice-Hall, 1998. See Project 5: Quantization Noise in Digital Filters, page 231.
![]() | Overview of Fixed-Point Filters | Data Types | ![]() |

Learn how to apply early verification to your development process through these technical resources.
How much time do you spend on testing to ensure implementation meets system-level requirements?
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |