main content

optimized fixed-凯发k8网页登录

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 r a d / s a m p l e ), 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 r a d / s a m p l e ), 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 r a d / s a m p l e ), 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.

网站地图