Zero State Machine

Mathematics, hacking and the daily struggle.

How to: Zero Delay State Variable Filter Part 3

| Comments

Zero delay feedback SVF

We will now build a linear and nonlinear zero delay feedback filters starting from the state variable filter differential equation

Linear model

The linear model simply assumes the differential equation above, without adding any nonlinear elements. Changing the variables with more descriptive ones, we get

where $u(t)$ is the filter input function.

Starting with the trapezoidal rule

as in part 2, the expression for $bp_{t+1}$ becomes

where

The equation ultimately resolves to

This equation now has two unknown variables on the left hand side, $bp_{t+1}$ and $lp_{t+1}$, so we need to first express $lp_{t+1}$ in terms of $bp_{t+1}$ and $bp_{t}$.

Since $lp’(t) = bp(t)$, applying trapezoidal rule results into

which can now be substituted back into the first equation. Gathering $bp_{t+1}$ terms to the left-hand side of the equation after the substitution

or after combining terms and solving for $bp_{t+1}$

This and

provide the final closed-form time stepping equations for the linear model. In this case, fortunately, there was no need to solve an implicit equation with Newton’s method.

The pseudocode for the integration then looks like

1
2
3
4
5
6
7
a=(1-0.5*sqrt(2)*h-0.25*h*h)/(1+0.5*sqrt(2)*h+0.25*h*h);
b=h/(1+0.5*sqrt(2)*h+0.25*h*h);
c=h/(2+sqrt(2)*f+0.5*h*h);
bp1=bp;
bp=a*bp-b*lp+c*(u(tt+1)+u(tt));
lp=lp+0.5*h*(bp1+bp);
hp=-lp-sqrt(2)*bp+u(tt+1);

The end product here is practically the same as what a semi-implicit integration would get you - the added benefit is the stability of the fully implicit integration.

However, it usually doesn’t make sense to apply implicit integration methods to fully linear differential equations. Nonlinear differential equations are where they show their teeth.

Nonlinear model

Starting with the same differential equation as previously and adding $tanh()$ as nonlinear elements (which is what ideal transistor curves usually resolve to in circuits mathematically)

and once again applying the trapezoidal rule, first for $lp_{t+1}$ (which is trivial)

and for $bp_{t+1}$

which requires an implicit solution. Gathering $bp_{t+1}$ terms to the left-hand side of the equation, substituting for $lp_{t+1}$ and gathering the right-hand side as a constant

we get

Forming the Newton’s method iteration functions (see part 2), substituting $x=bp_{t+1}$, $a=lp_{t}$, $b=bp_{t}$ and $c=u_{t+1}$

and it’s derivative

which gets us the following to iterate Newton’s method with

Pulling it all together, the pseudocode for the filter is now

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
A_n=bp+0.5*h*tanh(-lp-sqrt(2)*bp+u(tt));
aa=lp;
bb=bp;
cc=u(tt+1);
xx=bp;
bp_1=bp;
for(ii=0;ii++;ii<32){
   xx2=xx-(xx-0.5*h*tanh(-(aa+0.5*h*(tanh(bb)+tanh(xx)))-sqrt(2)*xx+cc)-A_n)/
		(1-(h*(sqrt(2)-(h*(tanh(xx)^2-1))/2)*
                    (tanh(cc-aa-sqrt(2)*xx-(h*(tanh(bb)+tanh(xx)))/2)^2-1))/2);
   if(abs(xx2-xx)<1e-15){
      xx=xx2;
      break;
   }
   xx=xx2;
}
bp=xx;
lp=lp+0.5*h*(tanh(bp_1)+tanh(bp));    
hp=-lp-sqrt(2)*bp+u(tt+1);

Conclusions

We have now succesfully built a zero delay feedback filter and detailed the steps to achieve it. It is left to the reader to experiment and determine if zero delay feedback is actually worth the trouble.

Comments