| Filter Design Toolbox | ![]() |
Syntax
Hq = qfilt Hq = qfilt('Structure',{Coef}) Hq = qfilt('prop1',value1,'prop2',value2,...) Hq = qfilt('Structure',{Coef},'prop1',value1,'prop2',value2,...) Hq = qfilt(`quantizer',[13, 14])
Description
creates a quantized filter Hq = qfilt
Hq with default property settings. The default settings for Hq imply Hq is a fixed-point quantized filter with a transposed direct form II filter structure. All of the filter properties, along with their default values are listed in Quantized Filter Properties Reference.
Hq = qfilt(' creates a quantized filter Structure',{Coef})
Hq with all properties set to default values, except that the filter structure is specified by the string 'Structure', and the reference filter parameters (the ReferenceCoefficients property values) are specified in the cell array {Coef}. The syntax for entering reference coefficients is specified in Specifying the Filter Reference Coefficients. 'Structure' can be one of the strings for the FilterStructure property values listed in the following table.
Hq = qfilt(' creates a quantized filter prop1',value1,'prop2',value2,...)
Hq with all properties set to the default values, except for those you specify with the input string arguments 'prop1', 'prop2',..., along with the corresponding values in value1, value2,.... Filter properties you can set, with their default values, are listed in Quantized Filter Properties Reference. Any properties that you do not explicitly set when you create the quantized filter are assigned default values.
by first specifying the FilterStructure property value as 'Structure' and the reference filter parameters (the ReferenceCoefficients property values) in the cell array {Coef}.
Hq = qfilt('quantizer',[13 14]
sets all the data format properties for quantized filter Hq to the same word length and fraction length.
Examples
Example 1: Quantized Filter with Two Second-Order Sections
From a reference filter, create a fixed-point quantized filter Hq that has two second-order sections, setting the rounding mode to 'fix' and displaying the results.
% Create the reference filter transfer function. [b,a] = ellip(4,3,20,.6); % Create a quantized filter with 2 second-order sections % and display the results. hq = sos(qfilt('df2',{b,a},'roundmode','fix')) hq = Quantized Direct form II transposed filter ------- Section 1 ------- Numerator QuantizedCoefficients{1}{1} ReferenceCoefficients{1}{1} (1) 0.551605224609375 0.551616219027048720 (2) 0.776458740234375 0.776489000631472080 (3) 0.551605224609375 0.551616219027047940 Denominator QuantizedCoefficients{1}{2} ReferenceCoefficients{1}{2} (1) 0.999969482421875 0.999969482421875000 (2) -0.054809570312500 -0.054810658312267876 (3) 0.473083496093750 0.473108096805785360 ------- Section 2 ------- Numerator QuantizedCoefficients{2}{1} ReferenceCoefficients{2}{1} (1) 0.499969482421875 0.499984741210937500 (2) 0.359802246093750 0.359832079066733920 (3) 0.499969482421875 0.499984741210938170 Denominator QuantizedCoefficients{2}{2} ReferenceCoefficients{2}{2} (1) 0.999969482421875 0.999969482421875000 (2) 0.588378906250000 0.588389482549356520 (3) 0.957336425781250 0.957363508666007170 FilterStructure = df2t ScaleValues = [0.5 2 1] NumberOfSections = 2 StatesPerSection = [2 2] CoefficientFormat = quantizer('fixed', 'fix', 'saturate', [16 15]) InputFormat = quantizer('fixed', 'fix', 'saturate', [16 15]) OutputFormat = quantizer('fixed', 'fix', 'saturate', [16 15]) MultiplicandFormat = quantizer('fixed', 'fix', 'saturate', [16 15]) ProductFormat = quantizer('fixed', 'fix', 'saturate', [32 30]) SumFormat = quantizer('fixed', 'fix', 'saturate', [32 30])
Example 2: Quantized Filter from Table of Filter Coefficients
In this example, you create a sixth-order quantized filter from filter coefficients in a reference table.
Enter the filter coefficients from a table of coefficients. The following coefficients represent a 6-pole Chebyshev high pass filter, with 0.5% ripple in the passband and cutoff at 0.25 in normalized frequency.
Create a quantized filter using the reference coefficients b and a.
hq = qfilt('ref',{b,a}) hq = Quantized Direct form II transposed filter Numerator QuantizedCoefficients{1} ReferenceCoefficients{1} (1) 0.014343261718750 0.014344500000000000 (2) -0.086059570312500 -0.086067009999999999 (3) 0.215179443359375 0.215167500000000010 (4) -0.286895751953125 -0.286889999999999980 (5) 0.215179443359375 0.215167500000000010 (6) -0.086059570312500 -0.086067009999999999 (7) 0.014343261718750 0.014344500000000000 Denominator QuantizedCoefficients{2} ReferenceCoefficients{2} + (1) 0.999969482421875 1.000000000000000000 + (2) 0.999969482421875 1.076051000000000100 + (3) 0.999969482421875 1.662847000000000000 + (4) 0.999969482421875 1.191062000000000100 (5) 0.740295410156250 0.740308500000000040 (6) 0.275207519531250 0.275215600000000000 (7) 0.057220458984375 0.057222500000000003 FilterStructure = df2t ScaleValues = [1] NumberOfSections = 1 StatesPerSection = [6] CoefficientFormat = quantizer('fixed', 'round', 'saturate', [16 15]) InputFormat = quantizer('fixed', 'floor', 'saturate', [16 15]) OutputFormat = quantizer('fixed', 'floor', 'saturate', [16 15]) MultiplicandFormat = quantizer('fixed', 'floor', 'saturate', [16 15]) ProductFormat = quantizer('fixed', 'floor', 'saturate', [32 30]) SumFormat = quantizer('fixed', 'floor', 'saturate', [32 30]) Warning: 4 overflows in coefficients.
Eliminate the overflows by normalizing the coefficients.
You have a sixth-order, high pass filter with no overflowing coefficients.
Some things to think about when you use coefficients from a table.
Example 3: Comparing Fixed-Point and Floating-Point Filters
To demonstrate the effect of filtering a signal with a quantized filter that has a leading zero in the denominator coefficients, this example creates a default quantized filter, then changes the reference coefficients to be numerator=1 and denominator=0.
q=qfilt q = Quantized Direct form II transposed filter Numerator QuantizedCoefficients{1} ReferenceCoefficients{1} + (1) 0.999969482421875 1.000000000000000000 Denominator QuantizedCoefficients{2} ReferenceCoefficients{2} + (1) 0.999969482421875 1.000000000000000000 FilterStructure = df2t ScaleValues = [1] NumberOfSections = 1 StatesPerSection = [0] CoefficientFormat = quantizer('fixed', 'round', 'saturate', [16 15]) InputFormat = quantizer('fixed', 'floor', 'saturate', [16 15]) OutputFormat = quantizer('fixed', 'floor', 'saturate', [16 15]) MultiplicandFormat = quantizer('fixed', 'floor', 'saturate', [16 15]) ProductFormat = quantizer('fixed', 'floor', 'saturate', [32 30]) SumFormat = quantizer('fixed', 'floor', 'saturate', [32 30]) Warning: 2 overflows in coefficients. q.ref={1 0}; Warning: 1 overflow in coefficients.
q is a fixed-point quantized filter with references coefficients of b=1 and a=0. Now filter a signal with q and look at the results.
filter(q,rand(1,2)) Warning: 3 overflows in QFILT/FILTER. Max Min NOverflows NUnderflows NOperations Coefficient 1 0 1 0 2 Input 0.9501 0.2311 0 0 2 Output 1 1 0 0 2 Multiplicand 2 0.2311 2 0 8 Product Inf 0.2311 2 0 8 Sum 0.9501 0.2311 0 0 2 ans = 1.0000 1.0000
In two's complement fixed-point format, NaNs and Infs cannot be represented. When the division by zero occurs during the filtering process, which happens when the leading coefficient in the denominator is zero, the result saturates to (1-215). The direct form filter structures, such as df1 and df2t, demonstrate this behavior when they have leading zeros in the denominator.
When you change the filter mode to 'float' from 'fixed', the results return as Inf, as you should expect.
q.mode='float'; filter(q,rand(1,2)) Warning: 6 overflows in QFILT/FILTER. Max Min NOverflows NUnderflows NOperations Coefficient 1 0 0 0 2 Input 0.6068 0.486 0 0 2 Output Inf 1.798e+308 2 0 2 Multiplicand Inf 0.25 2 0 8 Product Inf 0.25 4 0 8 Sum 0.5 0.25 0 0 2 ans = Inf Inf
Changing the mode results in Inf because IEEE floating-point arithmetic returns Inf as the result of a division by zero operation.
| qfft | qfilt2tf | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |