I am trying to convert a signal into another unit, but the error keeps increasing during each iteration I have a signal, A, and I want to convert it into another unit by using a formula:

$$s_i = \frac{(1+x_i)}{(1-x_i)}\cdot s_{i-1}$$

where $x_i$ is each sample of the signal. I am using a loop where the last value of $s$ is stored and used for the next iteration (as the new value of $P$). It goes on and on until the last sample of the signal.


Signal B is the result of the calculation. However, I noticed that the error keeps increasing during the calculation. As shown in the figure, the red line is how I want the signal to be.
If I understand your notation, you have $y[n] = \frac{1+x[n]}{1-x[n]}y[n-1]$, where $y[n]$ is the output signal.

This can be rewritten as $y[n] = y[n-1] + \frac{2x[n]}{1-x[n]}y[n-1]$. This is an integrator ($y[n] = y[n-1] + w[n]$) where $w[n]$ is some non-linear function of $x$ and $y$.

This integrating component is what gives you the drift in output. Note that the small positive offset in your input signal will result in a drift in your output.

If you could explain your application, and why you came up with the original difference equation, maybe some of us could come up with some insights for a solution.