Main Content

Optimized Fixed-Point FIR Filters

This example shows how to optimize fixed-point FIR filters. The optimization can refer to the characteristics of the filter response such as the stopband attenuation or the number of bits required to achieve a particular specification. This functionality is particularly useful for users targeting hardware that have a number of configurable coefficients of a specific wordlength and/or in cases typically found on ASICs and FPGAs where there is a large design space to explore. A hardware designer can usually trade off more coefficients for less bits or vice-versa to optimize for different ASICs or FPGAs.

This example illustrates various techniques based on the noise shaping procedure that yield optimized fixed-point FIR filter coefficients. The example shows how to:

  • minimize coefficients wordlength,

  • constrain coefficients wordlength,

  • maximize stopband attenuation.

Theoretical Background

The noise shaping algorithm essentially moves the quantization noise out of a critical frequency band (usually the stopband) of a fixed-point FIR filter at the expense of increasing it in other bands. The block diagram below illustrates the process of noise shaping. Essentially, the filter coefficients are passed through a system that resembles a digital filter, but with a quantizer in the middle. The system is computing the quantization error for each coefficient, then passing the error through a simple IIR highpass filter defined by the b1, b2 and b3 coefficients. The 'round' block rounds the input to the nearest quantized value. After this, the quantized value is subtracted from the original floating point value. The values of the initial state in each delay block can be set to random noise between -LSB and +LSB.

The output of the system is the new, quantized and noise shaped filter coefficients. By repeating this procedure many times with different random initial states in the delay blocks, different filters can be produced.

Minimize Coefficients Wordlength

To begin with, we want to determine the minimum wordlength fixed-point FIR filter that meets a single-stage or multistage design specification. We take the example of a halfband filter with a normalized transition width of .08 and a stopband attenuation of 59 dB. A Kaiser window design yields 91 double-precision floating-point coefficients to meet the specifications.

TW = .08;   % Transition Width
Astop = 59; % Stopband Attenuation (dB)
f  = fdesign.halfband('TW,Ast', TW, Astop);
Hd = design(f, 'kaiserwin');

To establish a baseline, we quantize the filter by setting its 'Arithmetic' property to 'fixed' and by iterating on the coefficients' wordlength until the minimum value that meets the specifications is found. Alternatively, we can use the minimizecoeffwl() to speed up the process. The baseline fixed-point filter contains 91 17-bit coefficients.

Hqbase = minimizecoeffwl(Hd,...
    MatchRefFilter=true, NoiseShaping=false, ...
    Astoptol=0);       % 91 17-bit coefficients, Astop = 59.1 dB

The 17-bit wordlength is unappealing for many hardware targets. In certain situations we may be able to compromise by using only 16-bit coefficients. Notice however that the original specification is no longer strictly met since the maximum stopband attenuation of the filter is only 58.8 dB instead of the 59 dB desired.

Hq1 = copy(Hqbase);
Hq1.CoeffWordLength = 16; % 91 16-bit coefficients, Astop = 58.8 dB
m1 = measure(Hq1) 
m1 = 
Sample Rate      : N/A (normalized frequency)
Passband Edge    : 0.46                      
3-dB Point       : 0.49074                   
6-dB Point       : 0.5                       
Stopband Edge    : 0.54                      
Passband Ripple  : 0.017157 dB               
Stopband Atten.  : 58.8741 dB                
Transition Width : 0.08                      
 

Alternatively, we can set a tolerance to control the stopband error that is acceptable. For example, with a stopband tolerance of .15 dB we can save 3 bits and get a filter with 91 14-bit coefficients.

Hq2 = minimizecoeffwl(Hd,...
                      MatchRefFilter=true, NoiseShaping=false, ...
                      Astoptol=.15);      % 91 14-bit coefficients, Astop = 58.8 dB

The saving in coefficients wordlength comes at the price of the fixed-point design no longer meeting the specifications. Tolerances can vary from one application to another but this strategy may have limited appeal in many situations. We can use another degree of freedom by relaxing the 'MatchRefFilter' constraint. By setting the 'MatchRefFilter' property to false, we no longer try to match the filter order (for minimum-order designs) or the filter transition width (for fixed order designs) of Hd. Allowing a re-design of the intermediate floating-point filter results in fixed-point filter that meets the specifications with 93 13-bit coefficients. Compared to the reference fixed-point designs, we saved 4 bits but ended up with 2 extra (1 non zero) coefficients.

Hq3 = minimizecoeffwl(Hd,...
                      MatchRefFilter=false, NoiseShaping=false); % 93 13-bit coefficients

A better solution yet is to use noise shaping to maximize the stopband attenuation of the quantized filter. The noise shaping procedure is stochastic. You may want to experiment with the 'NTrials' option and/or to initialize RAND in order to reproduce the results below. Because 'MatchRefFilter' is false by default and 'NoiseShaping' is true, we can omit them. The optimized fixed-point filter meets the specifications with 91 13-bit coefficients. This represents a saving of 4 bits over the reference fixed-point design with the same number of coefficients.

Hq4 = minimizecoeffwl(Hd, Ntrials=10);  % 91 13-bit coefficients
hfvt = fvtool(Hqbase,Hq4, ShowReference='off',Color='white');
legend(hfvt, '17-bit Reference Filter', '13-bit Noise-Shaped Filter');

Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB), xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Magnitude (dB) contains 3 objects of type line. These objects represent 17-bit Reference Filter, 13-bit Noise-Shaped Filter.

As a trade-off of the noise being shaped out of the stopband, the passband ripple of the noise-shaped filter increases slightly, which is usually not a problem. Also note that there is no simple relationship of passband ripple to frequency after the noise-shaping is applied.

zoom(hfvt,[0 0.5060 -0.0109 0.0109])

Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB), xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Magnitude (dB) contains 3 objects of type line. These objects represent 17-bit Reference Filter, 13-bit Noise-Shaped Filter.

Constrain Coefficients Wordlength

We have seen previously how we can trade-off more coefficients (or a larger transition width for designs with a fixed filter order) for a smaller coefficients wordlength by setting the 'MatchRefFilter' parameter of the minimizecoeffwl() method to 'false'. We now show how we can further control this trade-off by relaxing this constraint.

fm = fdesign.lowpass('Fp,Fst,Ap,Ast',0.1,0.12,1,70);
Hm  = design(fm);

We first match the order of the floating-point design and obtain a noise-shaped fixed-point filter that meets the specifications with 237 coefficients of a 20-bits wordlength.

Hmref = minimizecoeffwl(Hm, MatchRefFilter=true);
disp(Hmref)
     FilterStructure: 'Direct-Form FIR'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
          Arithmetic: 'fixed'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
           Numerator: [-0.000230312347412109 -0.000170230865478516 -0.000205755233764648 -0.000220060348510742 -0.000200748443603516 -0.000134706497192383 -1.09672546386719e-05 0.000179290771484375 0.000439882278442383 0.000768899917602539 0.00115752220153809 0.00158929824829102 0.00204086303710938 0.00248265266418457 0.00288128852844238 0.00320172309875488 0.00341033935546875 0.0034792423248291 0.00338864326477051 0.00313019752502441 0.00270867347717285 0.00214338302612305 0.00146818161010742 0.00072789192199707 -2.33650207519531e-05 -0.000725984573364258 -0.00132298469543457 -0.00176262855529785 -0.00200533866882324 -0.00202846527099609 -0.00182843208312988 -0.00142383575439453 -0.000853300094604492 -0.000173330307006836 0.00054621696472168 0.00122904777526855 0.0017998218536377 0.00219249725341797 0.00235700607299805 0.00226593017578125 0.00191855430603027 0.00134181976318359 0.000589132308959961 -0.00026392936706543 -0.00112748146057129 -0.00190567970275879 -0.00250744819641113 -0.00285696983337402 -0.00290179252624512 -0.00262188911437988 -0.00203156471252441 -0.00118088722229004 -0.000151872634887695 0.00094914436340332 0.00200176239013672 0.00288486480712891 0.00348949432373047 0.00373172760009766 0.00356459617614746 0.00298380851745605 0.00203204154968262 0.000795602798461914 -0.000601053237915039 -0.00200939178466797 -0.00327038764953613 -0.00423264503479004 -0.00476932525634766 -0.00479459762573242 -0.00427508354187012 -0.00323748588562012 -0.00176811218261719 -7.39097595214844e-06 0.0018620491027832 0.00363516807556152 0.00510382652282715 0.00608205795288086 0.00642728805541992 0.00605893135070801 0.00497198104858398 0.00324273109436035 0.00102400779724121 -0.00146484375 -0.00395941734313965 -0.00617623329162598 -0.0078427791595459 -0.00872921943664551 -0.00867581367492676 -0.00761699676513672 -0.00559449195861816 -0.0027613639831543 0.000626325607299805 0.00423002243041992 0.00765872001647949 0.0105066299438477 0.0123970508575439 0.0130240917205811 0.0121917724609375 0.00984549522399902 0.00608921051025391 0.0011906623840332 -0.00443053245544434 -0.0102307796478271 -0.0155820846557617 -0.0198259353637695 -0.0223300457000732 -0.0225484371185303 -0.0200765132904053 -0.0146968364715576 -0.00641036033630371 0.00454950332641602 0.0177228450775146 0.0324482917785645 0.0479071140289307 0.0631821155548096 0.077324390411377 0.0894284248352051 0.098701000213623 0.104526042938232 0.106512546539307 0.104526042938232 0.098701000213623 0.0894284248352051 0.077324390411377 0.0631821155548096 0.0479071140289307 0.0324482917785645 0.0177228450775146 0.00454950332641602 -0.00641036033630371 -0.0146968364715576 -0.0200765132904053 -0.0225484371185303 -0.0223300457000732 -0.0198259353637695 -0.0155820846557617 -0.0102307796478271 -0.00443053245544434 0.0011906623840332 0.00608921051025391 0.00984549522399902 0.0121917724609375 0.0130240917205811 0.0123970508575439 0.0105066299438477 0.00765872001647949 0.00423002243041992 0.000626325607299805 -0.0027613639831543 -0.00559449195861816 -0.00761699676513672 -0.00867581367492676 -0.00872921943664551 -0.0078427791595459 -0.00617623329162598 -0.00395941734313965 -0.00146484375 0.00102400779724121 0.00324273109436035 0.00497198104858398 0.00605893135070801 0.00642728805541992 0.00608205795288086 0.00510382652282715 0.00363516807556152 0.0018620491027832 -7.39097595214844e-06 -0.00176811218261719 -0.00323748588562012 -0.00427508354187012 -0.00479459762573242 -0.00476932525634766 -0.00423264503479004 -0.00327038764953613 -0.00200939178466797 -0.000601053237915039 0.000795602798461914 0.00203204154968262 0.00298380851745605 0.00356459617614746 0.00373172760009766 0.00348949432373047 0.00288486480712891 0.00200176239013672 0.00094914436340332 -0.000151872634887695 -0.00118088722229004 -0.00203156471252441 -0.00262188911437988 -0.00290179252624512 -0.00285696983337402 -0.00250744819641113 -0.00190567970275879 -0.00112748146057129 -0.00026392936706543 0.000589132308959961 0.00134181976318359 0.00191855430603027 0.00226593017578125 0.00235700607299805 0.00219249725341797 0.0017998218536377 0.00122904777526855 0.00054621696472168 -0.000173330307006836 -0.000853300094604492 -0.00142383575439453 -0.00182843208312988 -0.00202846527099609 -0.00200533866882324 -0.00176262855529785 -0.00132298469543457 -0.000725984573364258 -2.33650207519531e-05 0.00072789192199707 0.00146818161010742 0.00214338302612305 0.00270867347717285 0.00313019752502441 0.00338864326477051 0.0034792423248291 0.00341033935546875 0.00320172309875488 0.00288128852844238 0.00248265266418457 0.00204086303710938 0.00158929824829102 0.00115752220153809 0.000768899917602539 0.000439882278442383 0.000179290771484375 -1.09672546386719e-05 -0.000134706497192383 -0.000200748443603516 -0.000220060348510742 -0.000205755233764648 -0.000170230865478516 -0.000230312347412109]
    PersistentMemory: false                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
     CoeffWordLength: 20             
      CoeffAutoScale: true           
              Signed: true           
                                     
     InputWordLength: 16             
     InputFracLength: 15             
                                     
     FilterInternals: 'FullPrecision'
                                     

By relaxing the matching requirement (thus letting the filter order increase), we get 247 coefficients (a modest increase over the previous case) with a reduced wordlength of 15-bits.

Hq5 = minimizecoeffwl(Hm, MatchRefFilter=false); 
disp(Hq5);
     FilterStructure: 'Direct-Form FIR'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
          Arithmetic: 'fixed'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
           Numerator: [7.62939453125e-06 -0.0002288818359375 -0.00030517578125 -0.00048065185546875 -0.000701904296875 -0.0009613037109375 -0.00125885009765625 -0.00156402587890625 -0.0018768310546875 -0.00215911865234375 -0.0023956298828125 -0.00255584716796875 -0.00262451171875 -0.0025787353515625 -0.002410888671875 -0.0021209716796875 -0.0017242431640625 -0.0012359619140625 -0.00067901611328125 -9.918212890625e-05 0.000457763671875 0.0009613037109375 0.0013580322265625 0.00160980224609375 0.00170135498046875 0.00162506103515625 0.00138092041015625 0.00098419189453125 0.00048065185546875 -8.392333984375e-05 -0.00064849853515625 -0.00115966796875 -0.00156402587890625 -0.00180816650390625 -0.001861572265625 -0.001708984375 -0.0013580322265625 -0.00084686279296875 -0.000213623046875 0.00046539306640625 0.001129150390625 0.0016937255859375 0.00209808349609375 0.00228118896484375 0.002227783203125 0.0019073486328125 0.00136566162109375 0.000640869140625 -0.0001983642578125 -0.0010528564453125 -0.00183868408203125 -0.0024566650390625 -0.00283050537109375 -0.00290679931640625 -0.002655029296875 -0.0020904541015625 -0.00125885009765625 -0.00023651123046875 0.0008697509765625 0.00193023681640625 0.002838134765625 0.00347137451171875 0.00374603271484375 0.00360870361328125 0.0030517578125 0.0021209716796875 0.00089263916015625 -0.0005035400390625 -0.00193023681640625 -0.00321197509765625 -0.00420379638671875 -0.0047760009765625 -0.0048370361328125 -0.0043487548828125 -0.00333404541015625 -0.0018768310546875 -0.00011444091796875 0.00176239013671875 0.00356292724609375 0.00505828857421875 0.006072998046875 0.00646209716796875 0.00612640380859375 0.00506591796875 0.00335693359375 0.0011444091796875 -0.0013580322265625 -0.00386810302734375 -0.0061187744140625 -0.00782012939453125 -0.0087432861328125 -0.00872802734375 -0.0077056884765625 -0.005706787109375 -0.0028839111328125 0.0005035400390625 0.00412750244140625 0.00757598876953125 0.0104598999023438 0.01239013671875 0.0130615234375 0.01226806640625 0.00994873046875 0.0062103271484375 0.00131988525390625 -0.00431060791015625 -0.0101318359375 -0.0155105590820312 -0.0197982788085938 -0.0223388671875 -0.0225982666015625 -0.0201644897460938 -0.0148086547851562 -0.00653076171875 0.004425048828125 0.0176162719726562 0.0323638916015625 0.0478591918945312 0.0631790161132812 0.077362060546875 0.089508056640625 0.0988082885742188 0.104652404785156 0.106643676757812 0.104652404785156 0.0988082885742188 0.089508056640625 0.077362060546875 0.0631790161132812 0.0478591918945312 0.0323638916015625 0.0176162719726562 0.004425048828125 -0.00653076171875 -0.0148086547851562 -0.0201644897460938 -0.0225982666015625 -0.0223388671875 -0.0197982788085938 -0.0155105590820312 -0.0101318359375 -0.00431060791015625 0.00131988525390625 0.0062103271484375 0.00994873046875 0.01226806640625 0.0130615234375 0.01239013671875 0.0104598999023438 0.00757598876953125 0.00412750244140625 0.0005035400390625 -0.0028839111328125 -0.005706787109375 -0.0077056884765625 -0.00872802734375 -0.0087432861328125 -0.00782012939453125 -0.0061187744140625 -0.00386810302734375 -0.0013580322265625 0.0011444091796875 0.00335693359375 0.00506591796875 0.00612640380859375 0.00646209716796875 0.006072998046875 0.00505828857421875 0.00356292724609375 0.00176239013671875 -0.00011444091796875 -0.0018768310546875 -0.00333404541015625 -0.0043487548828125 -0.0048370361328125 -0.0047760009765625 -0.00420379638671875 -0.00321197509765625 -0.00193023681640625 -0.0005035400390625 0.00089263916015625 0.0021209716796875 0.0030517578125 0.00360870361328125 0.00374603271484375 0.00347137451171875 0.002838134765625 0.00193023681640625 0.0008697509765625 -0.00023651123046875 -0.00125885009765625 -0.0020904541015625 -0.002655029296875 -0.00290679931640625 -0.00283050537109375 -0.0024566650390625 -0.00183868408203125 -0.0010528564453125 -0.0001983642578125 0.000640869140625 0.00136566162109375 0.0019073486328125 0.002227783203125 0.00228118896484375 0.00209808349609375 0.0016937255859375 0.001129150390625 0.00046539306640625 -0.000213623046875 -0.00084686279296875 -0.0013580322265625 -0.001708984375 -0.001861572265625 -0.00180816650390625 -0.00156402587890625 -0.00115966796875 -0.00064849853515625 -8.392333984375e-05 0.00048065185546875 0.00098419189453125 0.00138092041015625 0.00162506103515625 0.00170135498046875 0.00160980224609375 0.0013580322265625 0.0009613037109375 0.000457763671875 -9.918212890625e-05 -0.00067901611328125 -0.0012359619140625 -0.0017242431640625 -0.0021209716796875 -0.002410888671875 -0.0025787353515625 -0.00262451171875 -0.00255584716796875 -0.0023956298828125 -0.00215911865234375 -0.0018768310546875 -0.00156402587890625 -0.00125885009765625 -0.0009613037109375 -0.000701904296875 -0.00048065185546875 -0.00030517578125 -0.0002288818359375 7.62939453125e-06]
    PersistentMemory: false                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
     CoeffWordLength: 15             
      CoeffAutoScale: true           
              Signed: true           
                                     
     InputWordLength: 16             
     InputFracLength: 15             
                                     
     FilterInternals: 'FullPrecision'
                                     

For better control of the final wordlengths, use the constraincoeffwl() method. For example, constrain the design to 16 bits coefficients.

WL = 16;
Hqc = constraincoeffwl(Hm,WL);
disp(Hqc)
     FilterStructure: 'Direct-Form FIR'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
          Arithmetic: 'fixed'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
           Numerator: [-0.000244140625 -0.0002899169921875 -0.000438690185546875 -0.000614166259765625 -0.0008087158203125 -0.001007080078125 -0.001190185546875 -0.00134658813476562 -0.0014495849609375 -0.0014801025390625 -0.00142288208007812 -0.00126266479492188 -0.000995635986328125 -0.000621795654296875 -0.000156402587890625 0.000377655029296875 0.000949859619140625 0.00152587890625 0.00206375122070312 0.0025177001953125 0.00284957885742188 0.00303268432617188 0.00304031372070312 0.00287246704101562 0.002532958984375 0.00205230712890625 0.00146865844726562 0.000827789306640625 0.000194549560546875 -0.000377655029296875 -0.000823974609375 -0.00110626220703125 -0.001190185546875 -0.00106430053710938 -0.000743865966796875 -0.00025177001953125 0.000354766845703125 0.00101089477539062 0.00164794921875 0.00218963623046875 0.0025634765625 0.00271987915039062 0.00263214111328125 0.00229263305664062 0.00172042846679688 0.00096893310546875 0.00011444091796875 -0.000762939453125 -0.00156021118164062 -0.00218963623046875 -0.00257110595703125 -0.00265121459960938 -0.00240707397460938 -0.00185012817382812 -0.00102615356445312 -1.52587890625e-05 0.00107574462890625 0.00212860107421875 0.00301742553710938 0.003631591796875 0.0038909912109375 0.0037384033203125 0.00317001342773438 0.002227783203125 0.0009918212890625 -0.0004119873046875 -0.00183868408203125 -0.00312042236328125 -0.00411224365234375 -0.00468063354492188 -0.00473785400390625 -0.00424575805664062 -0.00323104858398438 -0.00177383422851562 -1.9073486328125e-05 0.00185394287109375 0.00363922119140625 0.00513076782226562 0.00613021850585938 0.00650405883789062 0.00615692138671875 0.00508880615234375 0.0033721923828125 0.00115585327148438 -0.00133895874023438 -0.00384902954101562 -0.00609207153320312 -0.00778579711914062 -0.00870513916015625 -0.0086822509765625 -0.00765228271484375 -0.00564956665039062 -0.00282669067382812 0.000560760498046875 0.00417327880859375 0.00761795043945312 0.0104904174804688 0.0124130249023438 0.0130691528320312 0.0122642517089844 0.00994110107421875 0.00619888305664062 0.00130462646484375 -0.00432205200195312 -0.0101394653320312 -0.0155143737792969 -0.0197868347167969 -0.0223197937011719 -0.0225715637207031 -0.0201263427734375 -0.0147628784179688 -0.00648880004882812 0.0044708251953125 0.0176544189453125 0.0323982238769531 0.0478858947753906 0.0631904602050781 0.077362060546875 0.0894966125488281 0.0987930297851562 0.104633331298828 0.106624603271484 0.104633331298828 0.0987930297851562 0.0894966125488281 0.077362060546875 0.0631904602050781 0.0478858947753906 0.0323982238769531 0.0176544189453125 0.0044708251953125 -0.00648880004882812 -0.0147628784179688 -0.0201263427734375 -0.0225715637207031 -0.0223197937011719 -0.0197868347167969 -0.0155143737792969 -0.0101394653320312 -0.00432205200195312 0.00130462646484375 0.00619888305664062 0.00994110107421875 0.0122642517089844 0.0130691528320312 0.0124130249023438 0.0104904174804688 0.00761795043945312 0.00417327880859375 0.000560760498046875 -0.00282669067382812 -0.00564956665039062 -0.00765228271484375 -0.0086822509765625 -0.00870513916015625 -0.00778579711914062 -0.00609207153320312 -0.00384902954101562 -0.00133895874023438 0.00115585327148438 0.0033721923828125 0.00508880615234375 0.00615692138671875 0.00650405883789062 0.00613021850585938 0.00513076782226562 0.00363922119140625 0.00185394287109375 -1.9073486328125e-05 -0.00177383422851562 -0.00323104858398438 -0.00424575805664062 -0.00473785400390625 -0.00468063354492188 -0.00411224365234375 -0.00312042236328125 -0.00183868408203125 -0.0004119873046875 0.0009918212890625 0.002227783203125 0.00317001342773438 0.0037384033203125 0.0038909912109375 0.003631591796875 0.00301742553710938 0.00212860107421875 0.00107574462890625 -1.52587890625e-05 -0.00102615356445312 -0.00185012817382812 -0.00240707397460938 -0.00265121459960938 -0.00257110595703125 -0.00218963623046875 -0.00156021118164062 -0.000762939453125 0.00011444091796875 0.00096893310546875 0.00172042846679688 0.00229263305664062 0.00263214111328125 0.00271987915039062 0.0025634765625 0.00218963623046875 0.00164794921875 0.00101089477539062 0.000354766845703125 -0.00025177001953125 -0.000743865966796875 -0.00106430053710938 -0.001190185546875 -0.00110626220703125 -0.000823974609375 -0.000377655029296875 0.000194549560546875 0.000827789306640625 0.00146865844726562 0.00205230712890625 0.002532958984375 0.00287246704101562 0.00304031372070312 0.00303268432617188 0.00284957885742188 0.0025177001953125 0.00206375122070312 0.00152587890625 0.000949859619140625 0.000377655029296875 -0.000156402587890625 -0.000621795654296875 -0.000995635986328125 -0.00126266479492188 -0.00142288208007812 -0.0014801025390625 -0.0014495849609375 -0.00134658813476562 -0.001190185546875 -0.001007080078125 -0.0008087158203125 -0.000614166259765625 -0.000438690185546875 -0.0002899169921875 -0.000244140625]
    PersistentMemory: false                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
     CoeffWordLength: 16             
      CoeffAutoScale: true           
              Signed: true           
                                     
     InputWordLength: 16             
     InputFracLength: 15             
                                     
     FilterInternals: 'FullPrecision'
                                     

Maximize Stopband Attenuation

When designing for shelf filtering engines (ASSPs) that have a number of configurable coefficients of a specific wordlength, it is desirable to maximize the stopband attenuation of a filter with a given order and a constrained wordlength. In the next example, we wish to obtain 69 dB of stopband attenuation with a 70th order halfband decimator while using 14 bits to represent the coefficients.

fh = fdesign.halfband('N,Ast',70,69);
Hb1 = design(fh, 'equiripple');

If we simply quantize the filter with 14-bit coefficients, we get only 62.7 dB of attenuation.

Hb1.Arithmetic= 'fixed';
Hb1.CoeffWordLength = 14;
mb1 = measure(Hb1)
mb1 = 
Sample Rate      : N/A (normalized frequency)
Passband Edge    : 0.44518                   
3-dB Point       : 0.48816                   
6-dB Point       : 0.5                       
Stopband Edge    : 0.55482                   
Passband Ripple  : 0.010552 dB               
Stopband Atten.  : 62.7048 dB                
Transition Width : 0.10963                   
 

By shaping the noise out of the stopband we can improve the attenuation by almost 1.5 dB to 64.18 dB but we still cannot meet the specifications.

Hbq1 = maximizestopband(Hb1, 14);
mq1 = measure(Hbq1)
mq1 = 
Sample Rate      : N/A (normalized frequency)
Passband Edge    : 0.44562                   
3-dB Point       : 0.48812                   
6-dB Point       : 0.5                       
Stopband Edge    : 0.55367                   
Passband Ripple  : 0.010959 dB               
Stopband Atten.  : 63.8364 dB                
Transition Width : 0.10805                   
 

The next step is to over design a floating-point filter with 80 dB of attenuation. We pay the price of the increased attenuation in the form of a larger transition width. The attenuation of the 14-bit non noise-shaped filter improved from 62.7 dB to 66.2 dB but is still not meeting the specifications.

fh.Astop = 80;
Hb2 = design(fh,'equiripple');
Hb2.Arithmetic= 'fixed';
Hb2.CoeffWordLength = 14;
mb2 = measure(Hb2)
mb2 = 
Sample Rate      : N/A (normalized frequency)
Passband Edge    : 0.43464                   
3-dB Point       : 0.48704                   
6-dB Point       : 0.5                       
Stopband Edge    : 0.56536                   
Passband Ripple  : 0.0076847 dB              
Stopband Atten.  : 66.2266 dB                
Transition Width : 0.13073                   
 

The noise shaping technique gives us a filter that finally meets the specifications by improving the stopband attenuation by more than 3 dB, from 66.2 dB to 69.4 dB.

Hbq2 = maximizestopband(Hb2,14);
mq2 = measure(Hbq2)
mq2 = 
Sample Rate      : N/A (normalized frequency)
Passband Edge    : 0.43584                   
3-dB Point       : 0.4871                    
6-dB Point       : 0.5                       
Stopband Edge    : 0.56287                   
Passband Ripple  : 0.0053253 dB              
Stopband Atten.  : 69.4039 dB                
Transition Width : 0.12703                   
 

The transition width of the fixed-point filter is increased compared to the floating-point design. This is the price to pay to get 69 dB of attenuation with only 14-bit coefficients as it would take 24-bit coefficients to match both the transition width and the stopband attenuation of the floating-point design.

close(hfvt);
hfvt = fvtool(reffilter(Hb1),Hbq2, ShowReference='off', Color='white');
legend(hfvt,'Floating-Point Filter','14-bit Noise-Shaped Filter');

Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB), xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Magnitude (dB) contains 2 objects of type line. These objects represent Floating-Point Filter, 14-bit Noise-Shaped Filter.

close(hfvt)

Summary

We have seen how the noise shaping technique can be used to minimize the coefficients wordlength of a single stage or multistage FIR fixed-point filter or how it can be used to maximize the stopband attenuation instead. We have also seen how bits can be traded for more coefficients in case of minimum order designs or for a larger transition width in case of designs with a fixed order.

References

[1] Jens Jorgen Nielsen, Design of Linear-Phase Direct-Form FIR Digital Filters with Quantized Coefficients Using Error Spectrum Shaping Techniques, IEEE® Transactions on Acoustics, Speech, and Signal Processing, Vol. 37, No. 7, July 1989, pp. 1020--1026.

[2] Alan V. Oppenheim and Ronald W. Schafer, Discrete-Time Signal Processing, 2nd edition, Prentice Hall, 1999, ISBN 0-13-754920-2.