Let's say I have 16 bit fixed point DSP, and am performing a multiply accumulate operation in a loop-

  1. What would be the correct way to check for saturation of the accumulated value? As far as I understand, replacing the exceeded value with the maximum value will create distortion.

  2. How do I bring the accumulated result (within let's say a 40 bit accumulator) back to a 16 bit variable?

  1. Store everything in a variable (of an appropriate type) that is capable of storing the largest possible value (e.g double is 64 bit)

  2. Find the peak (maximum) value (if you end up with an array).

  3. Divide everything by the peak value (this will produce values in the 0-1 range with the peak value having a value of 1)

  4. Convert floating point to fixed point values (16 bit) (just multiply by the maximum allowed value e.g. 32768)

This sort of normalization will produce maximum values allowed for a particular range. You can, of course, increase this scaling factor to limit (reduce) the amplitudes to a range more suitable for your application.

| improve this answer | |
  • $\begingroup$ Should we anticipate any issues while the output is generated, in this case? It seems to me like scaling is done to bring everything to the 0 - 1 range, but eventually we would want to scale it back to its original value which may be outside the 16 bit range. Or I might be missing some information here.. $\endgroup$ – Naveen Dec 5 '17 at 10:23
  • 1
    $\begingroup$ I've changed my answer. There's no need for the scaling factor (it was a mistake), just divide everything by the peak value. This will not produce any artifacts provided that the accumulated array dynamic range (the difference between the largest and smallest value) can fit within the range for 16bit fixed point array. If it doesn't you will end up with a compressed signal but in this case no other method will help you either. $\endgroup$ – dsp_user Dec 5 '17 at 11:06
  • $\begingroup$ Would limiting the accumulated value have any adverse effects? For example, if I place a condition that checks if the accumulated value is between 7fff and 8000, and if its outside this range, replace it with 7fff or 8000, could this possibly create distortion? $\endgroup$ – Naveen Dec 5 '17 at 12:09
  • $\begingroup$ Yes, you'd compress the signal if you did that (and would also create distortion). (btw, 8000-7fff=1). $\endgroup$ – dsp_user Dec 5 '17 at 12:25
  • $\begingroup$ If I'm not mistaken, 0x8000 = -32768 in 2's complement, and 0x7fff is 32767.. $\endgroup$ – Naveen Dec 5 '17 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.