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

2019-02-20 Thread Andrew Simper
This looks pretty good to me, and I like the amplitude adjustment g[n] term
:)

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)

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 = t0
s = t1


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

> i did that wrong.  i meant to say:
>
>x[n] = a[n] + j*b[n] = g[n-1]*exp(j*w[n]) * x[n-1]
>
> this is the same as
>
>   a[n] = g[n-1]*cos(w[n])*a[n-1] - g[n-1]*sin(w[n])*b[n-1]
>
>   b[n] = g[n-1]*sin(w[n])*a[n-1] + g[n-1]*cos(w[n])*b[n-1]
>
> and adjust the gain g[n] so that |x[n]|^2 = a[n]^2 + b[n]^2 converges to
> the desired amplitude squared (let's say that we want that to be 1).  you
> can adjust the gain slowly with:
>
>   g[n] = 3/2 - (a[n]^2 + b[n]^2)/2
>
> that will keep the amplitude sqrt(a[n]^2 + b[n]^2) stably at 1 even as
> w[n] varies.
>
> i've done this before (when i wanted a quadrature sinusoid) for doing
> frequency offset shifting (not pitch shifting).  worked pretty good.
>
> --
>
>
> r b-j r...@audioimagination.com
>
> "Imagination is more important than knowledge."
>
>
>
> > A very simple oscillator recipe is:
> >
> > a(t+1) = C*a(t) - S*b(t)
> > b(t+1) = S*a(t) + C*b(t)
> >
> > Where C=cos(w), S=sin(w), w being the angular frequency. a and b are your
> > two state variables that are updated every sample clock, either of which
> > you can use as your output.
> >
> > There won't be any phase or amplitude discontinuity when you change C and
> > S. However, it's not stable as is, so you periodically have to make an
> > adjustment to make sure that a^2 + b^2 = 1.
> >
> > -Ethan
> >
> >
> > On Wed, Feb 20, 2019 at 12:26 PM Ian Esten  wrote:
> >
> >> The problem you are experiencing is caused by the fact that after
> changing
> >> the filter coefficients, the state of the filter produces something
> >> different to the current output. There are several ways to solve the
> >> problem:
> >> - The time varying bilinear transform:
> >> http://www.aes.org/e-lib/browse.cfm?elib=18490
> >> - Every time you modify the filter coefficients, modify the state of the
> >> filter so that it will produce the output you are expecting. Easy to do.
> >>
> >> I will also add that some filter structures are less prone to problems
> >> like this. I used a lattice filter structure to allow audio rate
> modulation
> >> of a biquad without any amplitude problems. I have no idea how it would
> >> work for using the filter as an oscillator.
> >>
> >> Best,
> >> Ian
> >>
> >> On Wed, Feb 20, 2019 at 9:07 AM Dario Sanfilippo <
> >> sanfilippo.da...@gmail.com> wrote:
> >>
> >>> Hello, list.
> >>>
> >>> I'm currently working with digital resonators for sinusoidal
> oscillators
> >>> and I was wondering if you have worked with some design which allows
> for
> >>> frequency variations without discontinuities in phase or amplitude.
> >>>
> >>> Thank you so much for your help.
> >>>
> >>> Dario
>
>
>
>
>
>
>
>
> ___
> 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

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

2019-02-20 Thread robert bristow-johnson



i did that wrong.  i meant to say:

 

   x[n] = a[n] + j*b[n] = g[n-1]*exp(j*w[n]) * x[n-1]

 

this is the same as

 


  a[n] = g[n-1]*cos(w[n])*a[n-1] - g[n-1]*sin(w[n])*b[n-1]

 


  b[n] = g[n-1]*sin(w[n])*a[n-1] + 
g[n-1]*cos(w[n])*b[n-1] 

 



and adjust the gain g[n] so that |x[n]|^2 = a[n]^2 + b[n]^2 converges 
to the desired amplitude squared (let's say that we want that to be 1).  you 
can adjust the gain slowly with:

 

  g[n] = 3/2 - (a[n]^2 + b[n]^2)/2

 

that will keep the amplitude sqrt(a[n]^2 + b[n]^2) stably at 1 even as 
w[n] varies.

 

i've done this before (when i wanted a quadrature sinusoid) for doing 
frequency offset shifting (not pitch shifting).  worked pretty good.

--


r b-j                         r...@audioimagination.com



"Imagination is more important than knowledge."
 
> A very simple oscillator recipe is:

>

> a(t+1) = C*a(t) - S*b(t)

> b(t+1) = S*a(t) + C*b(t)

>

> Where C=cos(w), S=sin(w), w being the angular frequency. a and b are your

> two state variables that are updated every sample clock, either of which

> you can use as your output.

>

> There won't be any phase or amplitude discontinuity when you change C and

> S. However, it's not stable as is, so you periodically have to make an

> adjustment to make sure that a^2 + b^2 = 1.

>

> -Ethan

>

>

> On Wed, Feb 20, 2019 at 12:26 PM Ian Esten  wrote:

>

>> The problem you are experiencing is caused by the fact that after changing

>> the filter coefficients, the state of the filter produces something

>> different to the current output. There are several ways to solve the

>> problem:

>> - The time varying bilinear transform:

>> http://www.aes.org/e-lib/browse.cfm?elib=18490

>> - Every time you modify the filter coefficients, modify the state of the

>> filter so that it will produce the output you are expecting. Easy to do.

>>

>> I will also add that some filter structures are less prone to problems

>> like this. I used a lattice filter structure to allow audio rate modulation

>> of a biquad without any amplitude problems. I have no idea how it would

>> work for using the filter as an oscillator.

>>

>> Best,

>> Ian

>>

>> On Wed, Feb 20, 2019 at 9:07 AM Dario Sanfilippo <

>> sanfilippo.da...@gmail.com> wrote:

>>

>>> Hello, list.

>>>

>>> I'm currently working with digital resonators for sinusoidal oscillators

>>> and I was wondering if you have worked with some design which allows for

>>> frequency variations without discontinuities in phase or amplitude.

>>>

>>> Thank you so much for your help.

>>>

>>> Dario
 
 
 
 
___
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp

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

2019-02-20 Thread robert bristow-johnson







On Wed, February 20, 2019 9:10 pm, "Ethan Fenn"  wrote:

>

> A very simple oscillator recipe is:

>

> a(t+1) = C*a(t) - S*b(t)

> b(t+1) = S*a(t) + C*b(t)

>

> Where C=cos(w), S=sin(w), w being the angular frequency. a and b are your

> two state variables that are updated every sample clock, either of which

> you can use as your output.

>

> There won't be any phase or amplitude discontinuity when you change C and

> S. However, it's not stable as is, so you periodically have to make an

> adjustment to make sure that a^2 + b^2 = 1.



personally, i think that phase accumulator and wavetable lookup and intersample 
interpolation is the best way to do a time-varying sinusoidal oscillator, but 
if you're gonna do it this way, it's the same as in complex arithmetic:



   x[n] = a[n] + j*b[n] = exp(j*w[n-1]) * x[n-1]
you can put in a little amplitude control and have it
   x[n] = a[n] + j*b[n] = g[n-1]*exp(j*w[n-1]) * x[n-1]
and adjust the gain g[n] so that |x[n]|^2 = a[n]^2 + b[n]^2 converges to the 
desired amplitude squared
(let's say that we want that to be 1).  you can adjust the gain slowly with:
  g[n] = (3/2)*g[n-1] - (a[n]^2 + b[n]^2)/2
that will cause the amplitude to converge back to an amplitude of 1, even as 
w[n] changes in value.

--



r b-j                         r...@audioimagination.com



"Imagination is more important than knowledge."


>

> On Wed, Feb 20, 2019 at 12:26 PM Ian Esten  wrote:

>

>> The problem you are experiencing is caused by the fact that after changing

>> the filter coefficients, the state of the filter produces something

>> different to the current output. There are several ways to solve the

>> problem:

>> - The time varying bilinear transform:

>> http://www.aes.org/e-lib/browse.cfm?elib=18490

>> - Every time you modify the filter coefficients, modify the state of the

>> filter so that it will produce the output you are expecting. Easy to do.

>>

>> I will also add that some filter structures are less prone to problems

>> like this. I used a lattice filter structure to allow audio rate modulation

>> of a biquad without any amplitude problems. I have no idea how it would

>> work for using the filter as an oscillator.

>>

>> Best,

>> Ian

>>

>> On Wed, Feb 20, 2019 at 9:07 AM Dario Sanfilippo <

>> sanfilippo.da...@gmail.com> wrote:

>>

>>> Hello, list.

>>>

>>> I'm currently working with digital resonators for sinusoidal oscillators

>>> and I was wondering if you have worked with some design which allows for

>>> frequency variations without discontinuities in phase or amplitude.

>>>

>>> Thank you so much for your help.

>>>

>>> Dario
 
 
 
 


 


--



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

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

2019-02-20 Thread Evan Balster
Hello —

The method Ethan recommends is sometimes known as a Variable Phasor
, and I'm quite fond of these!  I
like to visualize them as the hand of a clock.  The update function is
effectively a complex product (which works like a rotation) and you can use
a fast inverse square root
 to control the
magnitude of your  vector.

I've learned to be careful about relying too much on LTI filter methodology
in applications where the parameters need to change — breaking linearity
can undermine the assumptions that make those filter designs work in the
first place, especially with higher-order filters and biquad chains.

If you need a resonator (transforming audio input) rather than an
oscillator (creating a new signal from frequency and amplitude parameters),
there is a way to adapt Ethan's design to work as a filter:

a(t+1) = d * (C*a(t) - S*b(t)) + (1 - d) * x(t)
b(t+1) = d * (S*a(t) + C*b(t))

Where x(t) is an input signal and d is a decay-per-sample factor (0 < d <
1) that affects the resonator's bandwidth.  With this design, you don't
need to adjust the magnitude with a fast inverse square root.  For more
control over the bandwidth and general responsiveness, it's possible to
replace the decay math (which is basically a one-pole filter
)
with another low-pass filter design of your choice.

– Evan Balster
creator of imitone 


On Wed, Feb 20, 2019 at 3:10 PM Ethan Fenn  wrote:

> A very simple oscillator recipe is:
>
> a(t+1) = C*a(t) - S*b(t)
> b(t+1) = S*a(t) + C*b(t)
>
> Where C=cos(w), S=sin(w), w being the angular frequency. a and b are your
> two state variables that are updated every sample clock, either of which
> you can use as your output.
>
> There won't be any phase or amplitude discontinuity when you change C and
> S. However, it's not stable as is, so you periodically have to make an
> adjustment to make sure that a^2 + b^2 = 1.
>
> -Ethan
>
>
> On Wed, Feb 20, 2019 at 12:26 PM Ian Esten  wrote:
>
>> The problem you are experiencing is caused by the fact that after
>> changing the filter coefficients, the state of the filter produces
>> something different to the current output. There are several ways to solve
>> the problem:
>> - The time varying bilinear transform:
>> http://www.aes.org/e-lib/browse.cfm?elib=18490
>> - Every time you modify the filter coefficients, modify the state of the
>> filter so that it will produce the output you are expecting. Easy to do.
>>
>> I will also add that some filter structures are less prone to problems
>> like this. I used a lattice filter structure to allow audio rate modulation
>> of a biquad without any amplitude problems. I have no idea how it would
>> work for using the filter as an oscillator.
>>
>> Best,
>> Ian
>>
>> On Wed, Feb 20, 2019 at 9:07 AM Dario Sanfilippo <
>> sanfilippo.da...@gmail.com> wrote:
>>
>>> Hello, list.
>>>
>>> I'm currently working with digital resonators for sinusoidal oscillators
>>> and I was wondering if you have worked with some design which allows for
>>> frequency variations without discontinuities in phase or amplitude.
>>>
>>> Thank you so much for your help.
>>>
>>> Dario
>>> ___
>>> 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
>
> ___
> 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

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

2019-02-20 Thread Ethan Fenn
A very simple oscillator recipe is:

a(t+1) = C*a(t) - S*b(t)
b(t+1) = S*a(t) + C*b(t)

Where C=cos(w), S=sin(w), w being the angular frequency. a and b are your
two state variables that are updated every sample clock, either of which
you can use as your output.

There won't be any phase or amplitude discontinuity when you change C and
S. However, it's not stable as is, so you periodically have to make an
adjustment to make sure that a^2 + b^2 = 1.

-Ethan


On Wed, Feb 20, 2019 at 12:26 PM Ian Esten  wrote:

> The problem you are experiencing is caused by the fact that after changing
> the filter coefficients, the state of the filter produces something
> different to the current output. There are several ways to solve the
> problem:
> - The time varying bilinear transform:
> http://www.aes.org/e-lib/browse.cfm?elib=18490
> - Every time you modify the filter coefficients, modify the state of the
> filter so that it will produce the output you are expecting. Easy to do.
>
> I will also add that some filter structures are less prone to problems
> like this. I used a lattice filter structure to allow audio rate modulation
> of a biquad without any amplitude problems. I have no idea how it would
> work for using the filter as an oscillator.
>
> Best,
> Ian
>
> On Wed, Feb 20, 2019 at 9:07 AM Dario Sanfilippo <
> sanfilippo.da...@gmail.com> wrote:
>
>> Hello, list.
>>
>> I'm currently working with digital resonators for sinusoidal oscillators
>> and I was wondering if you have worked with some design which allows for
>> frequency variations without discontinuities in phase or amplitude.
>>
>> Thank you so much for your help.
>>
>> Dario
>> ___
>> 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
___
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp

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

2019-02-20 Thread Ian Esten
The problem you are experiencing is caused by the fact that after changing
the filter coefficients, the state of the filter produces something
different to the current output. There are several ways to solve the
problem:
- The time varying bilinear transform:
http://www.aes.org/e-lib/browse.cfm?elib=18490
- Every time you modify the filter coefficients, modify the state of the
filter so that it will produce the output you are expecting. Easy to do.

I will also add that some filter structures are less prone to problems like
this. I used a lattice filter structure to allow audio rate modulation of a
biquad without any amplitude problems. I have no idea how it would work for
using the filter as an oscillator.

Best,
Ian

On Wed, Feb 20, 2019 at 9:07 AM Dario Sanfilippo 
wrote:

> Hello, list.
>
> I'm currently working with digital resonators for sinusoidal oscillators
> and I was wondering if you have worked with some design which allows for
> frequency variations without discontinuities in phase or amplitude.
>
> Thank you so much for your help.
>
> Dario
> ___
> 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

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

2019-02-20 Thread Dario Sanfilippo
Hello, list.

I'm currently working with digital resonators for sinusoidal oscillators
and I was wondering if you have worked with some design which allows for
frequency variations without discontinuities in phase or amplitude.

Thank you so much for your help.

Dario
___
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp