Keep a signal that depends on an external input in some interval without using two cases or the max function

43 Views Asked by At

This problem regards keeping a signal x between the bounds of the interval $[D, B]$, by specifying the derivative of $x$ with respect to time as a function of some external input, say a real between $-1$ and $1.$ For example, if there were no bounds, this equation could be $dx/dt = \text{input}.$

When bounds $D$ and $B$ are present, the equation is:

$\dfrac{dx}{dt} = (B - x)*\max(0, \text{input}) + (D - x)*\max(0, -\text{input})$

Obviously, what this achieves is that when input is positive, $x$ grows towards $B$ and becomes saturated close to it, and if it was larger than $B,$ it gets lowered back. Vice versa for $D.$

My questions is whether a similar behavior (boundaries, saturation, proportional correction when $x$ is beyond boundaries) can be achieved without splitting the input signal into a positive and negative case using the max function, that is, using only basic algebraic operations?

For example, at first I incorrectly thought that a second-degree polynomial in the form $-(x - B)(x - D)*\text{input}$ may be used, because it has roots $D$ and $B$ between which it is positive, so the signal $x$ would increase for a positive input, and decrease for a negative input, and also if $B>x$ a positive signal would knock it back; but this falls apart once a negative signal is given when $x$ is over $B,$ or a positive signal is given when $x<D.$ I gave this example just to illustrate what could be an acceptable alternative that wouldn't use two cases and max--the appearance of the function could change however as long as those essential properties of controlling $x$ remain.

2

There are 2 best solutions below

1
On

This may or may not help, as I indicated in chat. You can write $$\max(x,y) = \frac12\big(x+y+|y-x|\big).$$ Perhaps that's no more helpful (as absolute value is, in truth, defined by cases).

2
On

If you can store, say, 5 inputs $I_n$ in an array, then every time you get a new input you can boot out the oldest, move all the other inputs back in the array, and put your new input into the newest slot, and then calculate your new $x$:

$$x_n = a\sum_{1}^5 I_n$$

You'll have to set $a$ so that you get the limits you want and you will have to add/subtract some constant if you want your solution to occupy the whole range of $B$ to $D$.

Another way to do it that doesn't need extra storage is to let

$$x_n = a x_{n-1} + I_n$$

where $0<a<1$. Note that if $I_n$ is constant, $x$ asymptotes to $I/(1-a)$. Again, you'll have to select $a$ depending on your circumstances and will have to add a constant in there somewhere to occupy all of your range.