cancel
Showing results for 
Search instead for 
Did you mean: 

Saturating arithmetic

ccowdery9
Associate III
Posted on March 30, 2009 at 14:43

Saturating arithmetic

10 REPLIES 10
picguy
Associate II
Posted on May 17, 2011 at 13:07

To my way of thinking you want gradual compression such that you will never get to the point of clipping. I would focus my thinking around 0V +/- signal. Because you are only using two channels the following may work well:

Arithmetically scale your a+b and a-b signal to +/- pi/2. Then take the sine. You now have a number in –1..+1. Scale appropriately and output to your DAC.

I have a fast sin(x) where x is an unsigned 32-bit integer representing 0 to 2pi. Value returned is a signed 32-bit integer = sin(x)*2^24 good to 12 bits. My function is all integer following the infinite series through -x^7/7! It never returns a result >1.0. I only use 0x6C bytes of ROM, a few stack words and no dedicated RAM.

With this scheme low amplitude values are hardly attenuated. High amplitude values are reduced by as much as 50%. And the reduction is gradual.

I would begin by using a floating point library sine function. That will take many more clocks that my fast integer sine. If it sounds okay than write a fast integer sine.

Or... you could simply use (a+b)/2 and (a-b)/2 using an analog amplifier if needed to boost the signal.