# Re: [music-dsp] Time-variant 2nd-order sinusoidal resonator

```Thanks everyone for your answers.

Ian: I'll look into that. My uni library doesn't seem to have access to
that paper but I'll see what I can find about the topic.```
```
Ethan: would that be a complex oscillator if taking both outputs? Perhaps I
could keep the system stable by using the following lines

L = a^2 + b^2
a = a/sqrt(L)
b = b/sqrt(L)

though this might introduce quite a bit of noise if performed at each tick.
I might just do that when a zero-crossing is detected. Also, is the system
initialised with a Dirac?

Evan: thanks for that information, it will be useful to implement the
filter.

Robert: that is perhaps the most stable design but also the one with most
calculations if I'm not wrong.

Currently, I was using

y(n) = x(n) + b1*y(n-1)  + b2*y(n-2)

with x(0) = sin(w)
b1 = 2cos(w)
b2 = -1

though changing the frequency would change the amplitude, so I need to
reset the states and retrigger the impulse to do so. But that would also
reset the phase so another solution, maybe less simple, could be to do so
whenever there is a zero-crossing on a rising wave.

Thanks,
Dario

On Thu, 21 Feb 2019 at 09:06, robert bristow-johnson <
r...@audioimagination.com> wrote:

>
>
> ---------------------------- Original Message ----------------------------
> Subject: Re: [music-dsp] Time-variant 2nd-order sinusoidal resonator
> From: "Andrew Simper" <a...@cytomic.com>
> Date: Wed, February 20, 2019 9:20 pm
> To: "Robert Bristow-Johnson" <r...@audioimagination.com>
> "A discussion list for music-related DSP" <music-dsp@music.columbia.edu>
> --------------------------------------------------------------------------
>
> > This looks pretty good to me, and I like the amplitude adjustment g[n]
> term
> > :)
>
> well, then let's integrate that into your code.
>
>
> >
> > Depending on the situation you may want to modulate the frequency of the
> > oscillator pretty fast, so it can help to use a tan approximation
> function
> > and then a division and a few other operations to get your cos (w) and
> sin
> > (w) rotation terms from that single approximation. I've called the
> rotation
> > terms g0 and g1, and c and s are the output cos and sin quadrature
> > oscillator values
> >
> > init:
> > c = cos(2*pi*startphase)
> > s = sin(2*pi*startphase)
>    gain = 1
>    adaptationspeed = 0.5     // this could be made smaller, but must be
> positive
> >
> > set frequency:
> > g0 = cos(2*pi*frequency/samplerate)
> > g1 = sin(2*pi*frequency/samplerate)
> >
> > or
> >
> > g = tan(pi*frequency/samplerate);
> > gg = 2/(1 + g*g)
> > g0 = gg-1
> > g1 = g*gg
> >
> > tick:
> > t0 = g0*c - g1*s
> > t1 = g1*c + g0*s
>   c = gain*t0
>   s = gain*t1
>   gain = 1 + adaptationspeed*(1 - c*c - s*s)
>
>
>
> --
>
> r b-j                         r...@audioimagination.com
>
> "Imagination is more important than knowledge."
>
>
>
>
>
>
>
> _______________________________________________
> dupswapdrop: music-dsp mailing list
> music-dsp@music.columbia.edu
> https://lists.columbia.edu/mailman/listinfo/music-dsp
```
```_______________________________________________
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp```