Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

 

Filter Design Toolbox 4.6

Fixed-Point Scaling of an Elliptic IIR Filter

This demo illustrates the autoscaling capability of fixed-point filter objects. The autoscale method provides dynamic range scaling for each node of the filter. This method runs the filter in floating-point and uses the maximum and minimum data obtained from that simulation to set fraction lengths so that the simulation range is covered and the precision is maximized. Word lengths do not change.

Contents

Designing the Filter

We are using a minimum-order elliptic design. Elliptic designs have the characteristic of being relatively well scaled when using the 'Linf' second-order section scaling norm.

f = fdesign.lowpass('Fp,Fst,Ap,Ast',.48,.52,1,60);
Hd = design(f, 'ellip', 'FilterStructure', 'df1sos', 'SOSScaleNorm', 'Linf')
;
hfvt = fvtool(Hd, 'Color', 'white');
hfvt.SosviewSettings.View = 'Cumulative';

Notice that none of the cumulative internal frequency responses -measured from the input to the filter to the various states of each section- exceed 0 dB. Thus, this design is a good candidate for a fixed-point implementation.

Input Stimulus

Because we just want to evaluate accuracy, we use some random data to filter and compare against. We create a quantizer, with a range of [-1,1) to generate random uniformly distributed white-noise data using 10 bits of wordlength. We generate 5 independent channels to be used in a Monte-Carlo simulation to scale the fixed-point filter.

rand('state',5);
q = quantizer([10,9],'RoundMode','round');
xq = randquant(q,100,5);
x = fi(xq,true,10,9);

Scaling the Filter

We assume that the hardware supports 14-bit coefficients, 10-bit bus for the input and the states and has a 24-bit MAC unit. Also, we assume that we can keep only 12 bits at the output of the filter.

Hd.Arithmetic = 'fixed';
set(Hd, 'CoeffWordLength', 14, ...
    'InputWordLength', 10, 'InputFracLength', 9, ...
    'NumStateWordLength', 10, 'DenStateWordLength', 10, ...
    'AccumWordLength', 24, ...
    'OutPutWordLength', 12);
set(hfvt,'Filters',Hd, 'Color', 'white')
legend(hfvt,' ', 'Location', 'Best');

A length of 14 bits seems enough to represent the coefficients. Now, we autoscale the filter internals:

Hd = autoscale(Hd,x);

Verifying the Fixed-Point Settings

We can verify that the settings are correct by running the filter in fixed-point:

fipref('LoggingMode', 'on', 'DataTypeOverride', 'ForceOff');
y = filter(Hd,x);
fipref('LoggingMode', 'off');
R = qreport(Hd)
R =


                                                  Fixed-Point Report
                 -----------------------------------------------------------
----------------------------------
                      Min              Max       |              Range       
       |      Number of Overflows
                 -----------------------------------------------------------
----------------------------------
         Input:              -1       0.99609375 |             -1       0.99
804688 |               0/500 (0%)
        Output:     -0.91796875        1.0390625 |             -2        1.9
990234 |               0/500 (0%)
    Num States:              -1       0.99609375 |             -1       0.99
804688 |              0/4000 (0%)
    Den States:     -0.91796875        1.0390625 |             -2        1.9
960938 |              0/4000 (0%)
      Num Prod:     -0.55561066       0.70284748 |             -2        1.9
999998 |              0/6000 (0%)
      Den Prod:      -1.0729704       0.92389297 |             -8         7.
999999 |              0/4000 (0%)
       Num Acc:      -1.0850372        1.3692884 |             -2        1.9
999998 |              0/4000 (0%)
       Den Acc:      -1.3030701        1.6069908 |             -8         7.
999999 |              0/4000 (0%)

We verify that there is no overflow, i.e., all the signals are within available dynamic range.

Comparing DF1SOS versus DF2SOS

We can compare the quantization noise added by a Direct-Form I implementation versus a Direct-Form II implementation. Both implementations use cascades of 'Linf'-scaled second-order sections:

Hd2 = design(f, 'ellip', 'FilterStructure', 'df2sos', 'SOSScaleNorm', 'Linf'
);
Hd2.Arithmetic = 'fixed';
set(Hd2, 'CoeffWordLength', 14, ...
    'InputWordLength', 10, 'InputFracLength', 9, ...
    'SectionInputWordLength', 10, 'SectionOutputWordLength', 10, ...
    'StateWordLength', 10, 'AccumWordLength', 24, ...
    'OutPutWordLength', 12);
Hd2 = autoscale(Hd2,x);
set(hfvt,'Filters',[Hd Hd2],'Analysis', 'magestimate', 'ShowReference', 'off
', 'Color', 'white');
set(hfvt,'Filters',[Hd Hd2],'Analysis', 'noisepower', 'ShowReference', 'off'
, 'Color', 'white');
legend(hfvt,'DF1SOS','DF2SOS')

We compute the average noise power in the passband for both implementations:

df1sosnoisepsd = noisepsd(Hd,100);
df1sos_pb_avg_noisepwr = db(avgpower(df1sosnoisepsd,[0 .48]*pi),'power')
df1sos_pb_avg_noisepwr =

  -43.8443

df2sosnoisepsd = noisepsd(Hd2,100);
df2sos_pb_avg_noisepwr = db(avgpower(df2sosnoisepsd,[0 .48]*pi),'power')
df2sos_pb_avg_noisepwr =

  -41.2077

The df1sos has less noise power in particular in the passband where the difference is about 2.5 dB. The noise power in the df1sos, however, is much larger in the transition band and we can see its negative consequences clearly from the magnitude response estimate.

df1sos_tw_avg_noisepwr = db(avgpower(df1sosnoisepsd,[.48 .52]*pi),'power')
df1sos_tw_avg_noisepwr =

  -48.5011

df2sos_tw_avg_noisepwr = db(avgpower(df2sosnoisepsd,[.48 .52]*pi),'power')
df2sos_tw_avg_noisepwr =

  -54.6562

This time, the df2sos has an advantage of about 5.8 dB in the transition band. Finally, we compute the average noise power in the stopband:

df1sos_sb_avg_noisepwr = db(avgpower(df1sosnoisepsd,[.52 1]*pi),'power')
df1sos_sb_avg_noisepwr =

  -61.8266

df2sos_sb_avg_noisepwr = db(avgpower(df2sosnoisepsd,[.52 1]*pi),'power')
df2sos_sb_avg_noisepwr =

  -60.6695

In the stopband -as in the passband- the df1sos has slightly less noise power. The difference in the stopband is about 1.3 dB.

Contact sales
Free technical kit
Trial software
E-mail this page

Get Pricing and
Licensing Options