主要内容

MATLAB中的固定点滤波器设计

此示例显示了如何设计用于与定点输入的过滤器。该示例分析了系数量化对滤波器设计的影响。您必须具有定义点Designer™软件来运行此示例。

介绍

固定点过滤器通常用于数据存储和功耗是关键限制因素的数字信号处理器。借助您指定的约束,DSP System Toolbox™软件使您可以设计有效的定点过滤器。此示例的过滤器是一个低通等式FIR滤波器。首先设计过滤器以获取浮点输入以获得基线。您可以使用此基线与定点过滤器进行比较。

FIR滤波器设计

这lowpass FIR filter has the following specifications:

  • 样本率:2000 Hz

  • 中心频率:450 Hz

  • 过渡宽度:100 Hz

  • Equiripple设计

  • Maximum 1 dB of ripple in the passband

  • 停止带中至少80 dB的衰减

samplingFrequency = 2000; centerFrequency = 450; transitionWidth = 100; passbandRipple = 1; stopbandAttenuation = 80; designSpec = fdesign.lowpass('fp,fst,ap,ast',,,,...Center-FriceCency-TransitionWidth/2,...centerFrequency+transitionWidth/2,...Passbandripple,Stopbandattenuation,...samplingFrequency); LPF = design(designSpec,'equiripple',,,,...“系统对象”,真的)
LPF = dsp.FIRFilter with properties: Structure: 'Direct form' NumeratorSource: 'Property' Numerator: [-0.0013 -0.0055 -0.0112 -0.0125 -0.0048 0.0062 ... ] InitialConditions: 0 Show all properties

查看基线频率响应。虚线显示了用于创建过滤器的设计规范。

fvtool(LPF)

图量响应(DB)包含一个轴对象。带有标题幅度响应(DB)的轴对象包含2个类型线的对象。

完整精确的定点操作

过滤器的定点特性包含在Fixed-point propertiessection in the display of the object. By default, the filter uses full-precision arithmetic to deal with fixed-point inputs. With full-precision arithmetic, the filter uses as many bits for the product, accumulator, and output as needed to prevent any overflow or rounding. If you do not want to use full-precision arithmetic, you can set theFullPrecisionOverride财产为然后独立设置产品,累加器和输出数据类型。

RNG默认inputWordLength = 16;fixedPointInput (r =andn(100,1),true,inputWordLength); floatingPointInput = double(fixedPointInput); floatingPointOutput = LPF(floatingPointInput); release(LPF) fullPrecisionOutput = LPF(fixedPointInput); norm(floatingPointOutput-double(fullPrecisionOutput),'inf'
ANS = 6.8994E-05

完整精确的定点过滤的结果非常接近浮点,但是结果并不精确。其原因是系数量化。在定点过滤器中系数数据属性的系数和输入具有相同的单词长度(16)。过滤器以完整精神模式的频率响应更清楚地显示了这一点。这措施function shows that the minimum stopband attenuation of this filter with quantized coefficients is 76.6913 dB, less than the 80 dB specified for the floating-point filter.

lpf.CoefficientsDatatype
ans ='与输入相同的单词长度'
fvtool(LPF)

图量响应(DB)包含一个轴对象。带有标题幅度响应(DB)的轴对象包含3个类型线的对象。这些对象表示过滤器#1:量化,过滤器#1:参考。

度量(LPF)
ans = Sample Rate : 2 kHz Passband Edge : 400 Hz 3-dB Point : 416.2891 Hz 6-dB Point : 428.1081 Hz Stopband Edge : 500 Hz Passband Ripple : 0.96325 dB Stopband Atten. : 76.6913 dB Transition Width : 100 Hz

该过滤器最后一次与定点输入一起使用,并且仍处于锁定状态。是因为,fvtooldisplays the fixed-point frequency response. The dash-dot response is that of the reference floating-point filter, and the solid plot is the response of the filter that was used with fixed-point input. The desired frequency response cannot be matched because the coefficient word length has been restricted to 16 bits. This accounts for the difference between the floating-point and fixed-point designs. Increasing the number of bits allowed for the coefficient word length makes the quantization error smaller and enables you to match the design requirement for 80 dB of stopband attenuation. Use a coefficient word length of 24 bits to achieve an attenuation of 80.1275 dB.

lpf24bitcoeff = Design(Designspec,'equiripple',,,,...“系统对象”,真的);lpf24bitcoeff.coefficientsDatatype ='Custom';coeffnumerictype = numerictype(fi(lpf24bitcoeff.numerator,true,24));lpf24bitcoeff.customcoefficeffientsdatatype = numerictype(true,,...coeffnumerictype.wordlength,coeffnumerictype.FractionLength);FullPrecisionOutput32BitCoeff = lpf24bitcoeff(fixePointInput);norm(floatingPointOutpote-double(FullPrecisionOutput32bitcoeff),'inf'
ans = 4.1077e-07
FVTool(LPF24Bitcoeff)

图量响应(DB)包含一个轴对象。带有标题幅度响应(DB)的轴对象包含3个类型线的对象。这些对象表示过滤器#1:量化,过滤器#1:参考。

措施(LPF24bitCoeff)
ans = Sample Rate : 2 kHz Passband Edge : 400 Hz 3-dB Point : 416.2901 Hz 6-dB Point : 428.1091 Hz Stopband Edge : 500 Hz Passband Ripple : 0.96329 dB Stopband Atten. : 80.1275 dB Transition Width : 100 Hz

设计参数和系数量化

In many fixed-point design applications, the coefficient word length is not flexible. For example, supposed you are restricted to work with 14 bits. In such cases, the requested minimum stopband attenuation of 80 dB cannot be reached. A filter with 14-bit coefficient quantization can achieve a minimum attenuation of only 67.2987 dB.

lpf14bitcoeff = Design(DesignSpec,'equiripple',,,,...“系统对象”,真的);coeffNumerictype = numerictype(fi(LPF14bitCoeff.Numerator,true,14)); LPF14bitCoeff.CoefficientsDataType ='Custom';lpf14bitcoeff.customcoefficeftientsdatatype = numerictype(true,,...coeffnumerictype.wordlength,coeffnumerictype.FractionLength);测量(lpf14bitcoeff,'算术',,,,'fixed'
ANS =样本率:2 kHz Passband边缘:400 Hz 3-DB点:416.2939 Hz 6-DB点:428.1081 Hz停止边缘:500 Hz Passband带纹波:0.96405 DB停止式端带Atten。:67.2987 DB过渡宽度:100 Hz

对于FIR过滤器,系数词长度的每一点都提供约5 dB的停止带衰减。因此,如果您的过滤器的系数始终量化为14位,则可以预期最小停止带衰减仅为70 dB左右。在这种情况下,用止回局衰减少于70 dB设计过滤器更为实用。放松此要求会导致较低的设计。

designspec.astop = 60;lpf60dbstopband = Design(Designspec,'equiripple',,,,...“系统对象”,真的);LPF60dBStopband.CoefficientsDataType ='Custom';coeffNumerictype = numerictype(fi(LPF60dBStopband.Numerator,true,14)); LPF60dBStopband.CustomCoefficientsDataType = numerictype(true,...coeffnumerictype.wordlength,coeffnumerictype.FractionLength);措施(LPF60dBStopband,'算术',,,,'fixed'
ANS =样本率:2 kHz Passband边缘:400 Hz 3-DB点:419.3391 Hz 6-DB点:432.9718 Hz停止边界:500 Hz Passband Band Band Bripple:0.92801 db stopband atten。:59.1829 DB过渡宽度:100 Hz
订单(lpf14bitcoeff)
ANS = 51
order(LPF60dBStopband)
ANS = 42

这filter order decreases from 51 to 42, implying that fewer taps are required to implement the new FIR filter. If you still want a high minimum stopband attenuation without compromising on the number of bits for coefficients, you must relax the other filter design constraint: the transition width. Increasing the transition width might enable you to get higher attenuation with the same coefficient word length. However, it is almost impossible to achieve more than 5 dB per bit of coefficient word length, even after relaxing the transition width.

designspec.astop = 80;过渡环= 200;Designspec.fpass = CenterFquency-TransitionWidth/2;designspec.fstop =中心频率+transitionWidth/2;LPF300 TransitionWidth = Design(DesignSpec,'equiripple',,,,...“系统对象”,真的);lpf300transitionWidth.coefficientsDatatype ='Custom';coeffnumerictype = numerictype(fi(lpf300 transitionwidth.numerator,...true, 14)); LPF300TransitionWidth.CustomCoefficientsDataType = numerictype(true,...coeffnumerictype.wordlength,coeffnumerictype.FractionLength);措施(LPF300TransitionWidth,'算术',,,,'fixed'
ANS =样本率:2 kHz Passband边缘:350 Hz 3-DB点:385.4095 Hz 6-DB点:408.6465 Hz停止边缘:550 Hz Passband带纹波:0.74045 db stopband atten。:74.439 DB过渡宽度:200 Hz

如您所见,将过渡宽度提高到200 Hz允许使用14位系数的74.439 dB止回局部衰减,与将过渡宽度设置为100 Hz时达到的67.2987 dB相比。增加过渡宽度的另一个好处是,在这种情况下,滤波器顺序也减少到27。

订单(LPF300 TransitionWidth)
ANS = 27