I use a simple filter in my programing for many situations. Mathematically I think its called a progression.

The function takes the form.

func (v){
   c = (c + (v - r) * a) * b;
   r = r + c;
   return r;


  • $v$ is any number and is the input value, each time step it may be a different.
  • $a$ and $b$ are constants within the range $0 < a$ and $0 < b < 1$
  • $c$ is the change over the time step, it is static (programing lingo for it remembers its last value). Its initial value is normally $c = 0$
  • $r$ is the result, it is static. It initial value is set to $v$ on the first time step.

It can be thought of as a signal processing function. The function has the effect of smoothing out a signal.

The following images show the response of $c$ (green) and $r$ (red) to the input $v$ (blue) over time Sample function response to input Sample function response to input

As you can see the value of $r$ approaches $v$ over time, the signal is smoothed out.

For some values of $a$,$b$ I get a the following response. enter image description here

The value of $r$ and $c$ oscillate over time. As long as $b < 1$ the oscillations seem to flatten out.

I am very interested in the period of the oscillations. From experimentation, for the same values of $a$ and $b$ and no matter the input value $v$ the oscillations seem to have a constant period (to within my ability to measure it)

What I would like to do is find what values of $a$,$b$ I can use to get a specific frequency.

My current and ugly solution is a statistical solution, where I sample the frequency of $c$ over many different values of $a$,$b$ and for many different input signals $v$. I can then select a value for $b$ and use the table to find what value $a$ should be for a required frequency.

The following image show a some of the sampled data and hints to me that there is a formula that will fit this data.

enter image description here

$b$ is on the x axis, $a$ is the colour coded index and the y axies is increasing period going up (high frequencies are down with infinity at $y = 0$)

My solution is not accurate especially at higher frequencies.

Is there a way to compute possible values of $a$ and $b$ given a required period/frequency?

My best attempt is this

$f(b)\ =0.8+\left(1.2-a\right)\frac{\left(1.2-a+\frac{\left(b-0.4\right)}{2}\right)^{2\left(1.2-a\right)}}{\frac{\left(b-0.4\right)}{2}}$

$f(b)$ returns the period. It is just a guess on my part but its close as it has a similar look the the sampled data when I change the value $a$ but I have given up on playing with the constants to find a fit.

It looks like this enter image description here

Sorry I have no idea what tags this should come under, hope I got it correct.

Any help is appreciated if just to point me in the right direction or tell me it's not possible. Thank you. :)


In signal processing terms you've implemented a recursive filter. The difference equations corresponding to your code are

$$\begin{align}c[n]&=b\cdot (c[n-1]+a\cdot(x[n]-y[n]))\\ y[n]&=y[n-1]+c[n]\end{align}\tag{1}$$

where I've followed the convention to use $x[n]$ for the input signal, and $y[n]$ for the output signal.

Such recursions can be solved using the Z-transform. Applying the Z-transform to $(1)$ gives:

$$\begin{align}C(z)&=b\cdot [C(z)z^{-1}+a\cdot(X(z)-Y(z))]\\ Y(z)&=Y(z)z^{-1}+C(z)\end{align}\tag{2}$$

which can be solved for $Y(z)$ in terms of $X(z)$:


The function $H(z)$ is called the system's transfer function. It completely characterizes the system.

The roots of the denominator of $(3)$ determine whether the system's response to a step oscillates or not. If the roots are real-valued there is no oscillation, and if there are complex-conjugated roots there will be oscillations.

Let us define $d=ab-b-1$. Then the roots of the denominator of $(3)$ are


So there are only oscillations if $b>\frac{d^2}{4}$, i.e., if there are complex roots. The frequency of the oscillations is determined by the angle of the complex roots. Assuming $b>\frac{d^2}{4}$, we have

$$\theta=\arg\{z_{\infty}\}=\begin{cases}\arctan\left(-2\frac{\sqrt{b-\frac{d^2}{4}}}{d}\right),&d<0\\ \arctan\left(-2\frac{\sqrt{b-\frac{d^2}{4}}}{d}\right)+\pi,&d>0\end{cases}\tag{5}$$

The oscillation frequency is simply $f_0=\theta/(2\pi)$.


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.