Scale/offset wave

dc-offsetmicrocontrollerwave

I have a wave profile stored in a micro-controller that I want to scale and shift with two input arguments. Is it possible to fix an 'absolute' scale (max/min = 1.02 for e.g.) and have an offset that is unchanged? Currently I can add the offset first, account for the scale inherent in the wave and scale it again to get my desired scale, but this changes the offset.

Is there a way to do this?

Best Answer

Let me see if I understood this properly:

Your constraints are a given offset and max/min ratio, and your wave has some original minimum (m) and maximum (M) values, that you wish you scale+offset in order to meet the constraints.

If that is the case then you can simply scale with respect to the minimum and then offset.

Any point in your wave will be scaled with respect to the minimum and offset:

$$ y=scale\cdot (x-m)+m+offset $$

The offset is given, you just need the scale:

$$ ratio = \frac{max}{min} = \frac{scale\cdot (M-m)+m+offset}{scale\cdot (m-m)+m+offset} $$

You just need to solve for scale in the above equation.

Another method would be to scale with respect to zero or mid-range, and then apply the offset. I'm just not sure what your application requires.

If you scale with respect to zero, then the above equations get reduced to:

$$ y=scale\cdot x+offset $$ $$ ratio = \frac{max}{min} = \frac{scale\cdot M+offset}{scale\cdot m+offset} $$