Using fixed-point toolboxt to simulate DSP's behaviour

81 views Asked by At

I am using a Analog Devices DSP and I would like to do some simulations on a algorithm. From this I specified my architecture:

F = fimath('MaxProductWordLength', 40, ...
    'MaxSumWordLength', 40, ...
    'OverflowAction', 'Saturate', ...
    'ProductMode', 'KeepLSB', ...
    'RoundingMethod', 'Floor', ...
    'SumMode', 'KeepLSB', ...
    'SumFractionLength', 8, ...
    'SumFixedExponent', 40, ...
    'ProductFixedExponent', 40, ...    
    'SumWordLength', 40);

R = numerictype(1, 40, 8);

Then I can declare some numbers and do a multiplication:

a = fi(32.25, R, F);
b = fi(1234, R, F);
c = fi(0.1, R, F);
a*b+c

The output is formatted as this:

        WordLength: 40
    FractionLength: 16

How can I force Matlab to leave the numbers on the specified type (Q32.8)?

The same issue happens with a*b:

ans = 
3.2768e+04
      DataTypeMode: Fixed-point: binary point scaling
        Signedness: Signed
        WordLength: 32
    FractionLength: 16

    RoundingMethod: Floor
    OverflowAction: Saturate
       ProductMode: KeepLSB
 ProductWordLength: 32
           SumMode: KeepLSB
     SumWordLength: 40
     CastBeforeSum: true

I don't want Q16.16 but Q40.8 again...

1

There are 1 answers

0
user3528438 On BEST ANSWER

ProductWordLength: 32

Try changing it to 40?

I'm not sure about this processor, but some processors have multiply-and-shift, so usually I use a shorter product length to simulate a multiply-and-shift.