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

2019-03-04 Thread Olli Niemitalo
A simple way to stabilize most quadrature oscillators including
Martin's quadrature oscillator is to multiply each state variable by a
temporary variable:

  g = 1.5 - 0.5*(u*u + v*v)

where u and v are unit-amplitude quadrature oscillator outputs. The
correction does not need to be done very often, but this depends on
the oscillator algorithm and the precision of its state variables. The
variable g is a Taylor approximation of the exact normalization factor
1/sqrt(u*u + v*v) about u*u + v*v = 1. The Taylor approximation can
only lead to oscillator blow-up if u*u + v*v >= 4, and otherwise
corrects the sinusoid amplitude to 1 or below. For u*u + v*v < 2 the
correction brings the amplitude closer to 1. An amplitude error of -92
dB or less will already be corrected to below the quantization error
of double precision floating point state variables, so the
stabilization method need not be more complicated.

-olli
___
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-03-03 Thread Olli Niemitalo
On Thu, Feb 21, 2019 at 11:16 PM robert bristow-johnson
 wrote:

> But Martin, if you let this thing run for days on end, would not eventually 
> the amplitude of the output change a bit?

Short answer: yes, sometimes significantly for audio purposes when
using 32-bit float state variables, but not significantly when using
64-bit doubles.

Even as poles lie exactly on the unit circle, limited precision in the
state variables leads to rounding errors. Because of the recursive
nature of the algorithm, rounding errors accumulate in manner of a
(pseudo)random walk. Almost always a past state will be encountered
again, and the system enters a limit cycle, locking the error into a
range of error values close to what was accumulated thus far. With
32-bit floating point state variables, sometimes significant numerical
error is accumulated before a limit cycle is entered, depending on
pseudo-luck with the sinusoid frequency. With 64-bit floating point
state variables the problem seems to be almost never significant even
though entering a limit cycle becomes a rare occasion.

The error accumulation and limit cycles can be visualized by plotting
the magnitude of the quadrature pair output of Martin's algorithm
(red), and the same for a Goertzel algorithm based quadrature
oscillator (blue) for comparison, as function of output sample number:

  https://imgur.com/a/cE5R50d

For this plot, 32-bit float variables were used, and rounding mode was
set to round-to-nearest, and angular frequency arbitrarily to (float)
sqrt(2.0) radians to get visible and somewhat lengthy limit cycles.
For the Goertzel algorithm, about 4 periods of a limit cycle, and for
Martin's algorithm, about 2 periods of a limit cycle are visible, for
the first one million output samples.

Based on testing with random frequencies and single (32-bit) and
double (64-bit) precision floating point numbers, compared to
Goertzel, Martin's algorithm tends to have faster error accumulation
(due to a longer cascade of rounded operations per iteration), giving
a larger error, measured as absolute log magnitude, for about 62 % of
random frequencies, both for floats and doubles (tested over 10^4
replications, measured at 10^4 samples generated).

At one million samples generated, the root mean square magnitude error
was roughly 0.0002 for Goertzel and 0.002 for Martin's algorithm using
single precision state variables, and roughly 7*10^-13 for Goertzel
and 3*10^-12 for Martin's algorithm using double precision floating
point state variables (tested over 1000 replications).

C++ test code below.

-olli

// Compile with: g++ -std=c++0x -O3 -ffloat-store -fno-unsafe-math-optimizations
#define _USE_MATH_DEFINES
typedef float FLOAT_TYPE; // float or double
const bool printStats = true; // Print statistics
const bool printData = false; // Print (last) data
#include 
#include 
#include 
#include 
#include 

main() {
  long int numReps = 1000;
  long int numSamples = 1000;
  long int decimate = 1; // Decimate results by this ratio (useful if
huge numReps)
  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
  std::mt19937 rng(seed);
  std::uniform_real_distribution uniform(0.0, 1.0);
  int numDecimated = numSamples/decimate + 1;
  long double *magGoertzel = new long double[numDecimated];
  long double *magMartin = new long double[numDecimated];
  long double *sseGoertzel = new long double[numDecimated];
  long double *sseMartin = new long double[numDecimated];
  for (long int count = 0; count < numDecimated; count++) {
sseGoertzel[count] = 0;
sseMartin[count] = 0;
  }
  fesetround(FE_TONEAREST); // FE_TONEAREST, FE_UPWARD, FE_DOWNWARD,
or FE_TOWARDZERO
  long int numGoertzelWorse = 0;
  long int numMartinWorse = 0;
  for (long int rep = 0; rep < numReps; rep++) {
FLOAT_TYPE w = M_PI*uniform(rng);
// Goertzel
FLOAT_TYPE coef = 2*cos(w);
FLOAT_TYPE outHistory1 = 0, outHistory2 = 0;
FLOAT_TYPE input = 1; // First input value
FLOAT_TYPE cosw = cos(w);
FLOAT_TYPE sinw = sin(w);
// Martin
FLOAT_TYPE k1 = tan(w/2);
FLOAT_TYPE k2 = 2*k1/(1 + k1*k1);
FLOAT_TYPE u = 1;
FLOAT_TYPE v = 0;
numDecimated = 0;
for (long int count = 0; count < numSamples; count++) {
  // Goertzel
  FLOAT_TYPE out = input + coef*outHistory1 - outHistory2;
  outHistory2 = outHistory1;
  outHistory1 = out;
  input = 0;
  FLOAT_TYPE re = outHistory1 - outHistory2*cosw;
  FLOAT_TYPE im = outHistory2*sinw;
  // Martin
  FLOAT_TYPE tmp = u - k1*v;
  v = v + k2*tmp;
  u = tmp - k1*v;
  // Results
  if (count % decimate == 0) {
magGoertzel[numDecimated] = sqrt(re*(long double)re + im*(long
double)im);
magMartin[numDecimated] = (FLOAT_TYPE)sqrt(u*(long double)u +
v*(long double)v);
sseGoertzel[numDecimated] += pow(magGoertzel[numDecimated] - 1, 2);
sseMartin[numDecimated] += pow(magMartin[numDecimated] - 1, 2);
numDecimated++;
  }
   

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

2019-02-26 Thread STEFFAN DIEDRICHSEN
Martin, 

thanks for (re-)posting this. I had a look at your website and found some 
articles, which are very interesting. The idea of the reverse IIR filter is 
super brilliant.

Best,

Steffan 



> On 21.02.2019|KW8, at 19:33, Martin Vicanek  wrote:
> 
> You can have both: A (hyper)stable quadrature oscillator without the need to 
> adjust states upon frequency modulation, and without the need to counteract 
> amplitude runaway:
> https://vicanek.de/articles/QuadOsc.pdf 
> 
> 



___
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-23 Thread Andrew Simper
When evaluating polynomials although Horner's method is shorter to code,
and has the fewest actual operations used, on modern architectures with
deep pipelines I would recommend giving Estrin's scheme a go and let the
profiler / accurate cpu meter logging tell you which one is best:

https://en.wikipedia.org/wiki/Horner%27s_method
vs
https://en.wikipedia.org/wiki/Estrin%27s_scheme

Andy





On Sat, 23 Feb 2019 at 07:31, robert bristow-johnson <
r...@audioimagination.com> wrote:

>
>
> this is just a guess at what the C code might look like to calculate one
> sample.  this uses Olli's 7th-order with continuous derivative.  f0 is the
> oscillator frequency which can vary but it must be non-negative.  1/T is
> the sample rate.
>
>
>
> float sine_osc(float f0, float T)
> {
>static float phase = 1.0;// this is the only state.  -2.0 <= phase
> < +2.0
>
>phase += 4.0*f0*T;
>if (phase >= 2.0)
>{
>   phase -= 4.0;
>}
>
>if (phase < 0.0)
>{
>   triangle = -phase - 1.0;
>}
>else
>{
>   triangle = phase - 1.0;
>}
>
>x2 = triangle*triangle;
>return triangle*(1.570781972 - x2*(0.6458482979 - x2*(0.07935067784 -
> x2*0.004284352588)));
> }
>
> i haven't run this code nor checked it for syntax.  but it's conceptually
> so simple that i'll bet it works.
>
> r b-j
>
>  Original Message 
> Subject: Re: [music-dsp] Time-variant 2nd-order sinusoidal resonator
> From: "Olli Niemitalo" 
> Date: Thu, February 21, 2019 11:58 pm
> To: "A discussion list for music-related DSP" <
> music-dsp@music.columbia.edu>
> --
>
> > On Fri, Feb 22, 2019 at 9:08 AM robert bristow-johnson <
> > r...@audioimagination.com> wrote:
> >
> >> i just got in touch with Olli, and this "triangle wave to sine wave"
> >> shaper polynomial is discussed at this Stack Exchange:
> >>
> >>
> >>
> >>
> https://dsp.stackexchange.com/questions/46629/finding-polynomial-approximations-of-a-sine-wave/46761#46761
> >>
> > I'll just summarize the results here. The polynomials f(x) approximate
> > sin(pi/2*x) for x=-1..1 and are solutions with minimum peak harmonic
> > distortion compared to the fundamental frequency. Both solutions with
> > continuous and discontinuous derivative are given. In summary:
> >
> > Shared polynomial approximation properties and constraints:
> > x = -1..1, f(-1) = -1, f(0) = 0, f(1) = 1, and f(-x) = -f(x).
> >
> > If continuous derivative:
> > f'(-1) = 0 and f'(1) = 0 for the anti-periodic extension f(x + 2) =
> -f(x).
> >
> > 5th order, continuous derivative, -78.99 dB peak harmonic distortion:
> > f(x) = 1.569778813*x - 0.6395576276*x^3 + 0.06977881382*x^5
> >
> > 5th order, discontinuous derivative, -91.52 dB peak harmonic distortion:
> > f(x) = 1.570034357*x - 0.6425216143*x^3 + 0.07248725712*x^5
> >
> > 7th order, continuous derivative, -123.8368 dB peak harmonic distortion:
> > f(x) = 1.570781972*x - 0.6458482979*x^3 + 0.07935067784*x^5
> > - 0.004284352588*x^7
> >
> > 7th order, discontinuous derivative, -133.627 dB peak harmonic
> distortion:
> > f(x) = 1.5707953785726114835*x -
> > 0.64590724797262922190*x^3 + 0.079473610232926783079*x^5
> > - 0.0043617408329090447344*x^7
> >
> > Also the exact coefficients that are rational functions of pi are given
> in
> > the answer, in case anyone needs more precision.
> >
> > -olli
> > ___
> > dupswapdrop: music-dsp mailing list
> > music-dsp@music.columbia.edu
> > https://lists.columbia.edu/mailman/listinfo/music-dsp
>
>
>
>
>
>
>
>
> --
>
> 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

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

2019-02-22 Thread robert bristow-johnson



�
this is just a guess at what the C code might look like to calculate one 
sample.� this uses Olli's 7th-order with continuous derivative.� f0 is the 
oscillator frequency which can vary but it must be non-negative.� 1/T is the 
sample rate.
�
float
sine_osc(float f0, float T)
{

� �static float phase = 1.0;� � // this is the only state.� -2.0 <= phase < +2.0



� �phase += 4.0*f0*T;

� �if (phase >= 2.0)

� �{

� � � phase -= 4.0;

� �}



� �if (phase < 0.0)

� �{

� � � triangle = -phase - 1.0;

� �}

� �else

� �{

� � � triangle = phase - 1.0;

� �}



� �x2 = triangle*triangle;

� �return triangle*(1.570781972 - x2*(0.6458482979 - x2*(0.07935067784 - 
x2*0.004284352588)));

}
i haven't run this code nor checked it for syntax.� but it's conceptually so 
simple that i'll bet it works.



r b-j



 Original Message ----------------

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

From: "Olli Niemitalo" 

Date: Thu, February 21, 2019 11:58 pm

To: "A discussion list for music-related DSP" 

--



> On Fri, Feb 22, 2019 at 9:08 AM robert bristow-johnson <

> r...@audioimagination.com> wrote:

>

>> i just got in touch with Olli, and this "triangle wave to sine wave"

>> shaper polynomial is discussed at this Stack Exchange:

>>

>>

>>

>> https://dsp.stackexchange.com/questions/46629/finding-polynomial-approximations-of-a-sine-wave/46761#46761

>>

> I'll just summarize the results here. The polynomials f(x) approximate

> sin(pi/2*x) for x=-1..1 and are solutions with minimum peak harmonic

> distortion compared to the fundamental frequency. Both solutions with

> continuous and discontinuous derivative are given. In summary:

>

> Shared polynomial approximation properties and constraints:

> x = -1..1, f(-1) = -1, f(0) = 0, f(1) = 1, and f(-x) = -f(x).

>

> If continuous derivative:

> f'(-1) = 0 and f'(1) = 0 for the anti-periodic extension f(x + 2) = -f(x).

>

> 5th order, continuous derivative, -78.99 dB peak harmonic distortion:

> f(x) = 1.569778813*x - 0.6395576276*x^3 + 0.06977881382*x^5

>

> 5th order, discontinuous derivative, -91.52 dB peak harmonic distortion:

> f(x) = 1.570034357*x - 0.6425216143*x^3 + 0.07248725712*x^5

>

> 7th order, continuous derivative, -123.8368 dB peak harmonic distortion:

> f(x) = 1.570781972*x - 0.6458482979*x^3 + 0.07935067784*x^5

> - 0.004284352588*x^7

>

> 7th order, discontinuous derivative, -133.627 dB peak harmonic distortion:

> f(x) = 1.5707953785726114835*x -

> 0.64590724797262922190*x^3 + 0.079473610232926783079*x^5

> - 0.0043617408329090447344*x^7

>

> Also the exact coefficients that are rational functions of pi are given in

> the answer, in case anyone needs more precision.

>

> -olli

> ___

> dupswapdrop: music-dsp mailing list

> music-dsp@music.columbia.edu

> https://lists.columbia.edu/mailman/listinfo/music-dsp
�
�
�


--



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-21 Thread Olli Niemitalo
On Fri, Feb 22, 2019 at 9:08 AM robert bristow-johnson <
r...@audioimagination.com> wrote:

> i just got in touch with Olli, and this "triangle wave to sine wave"
> shaper polynomial is discussed at this Stack Exchange:
>
>
>
> https://dsp.stackexchange.com/questions/46629/finding-polynomial-approximations-of-a-sine-wave/46761#46761
>
I'll just summarize the results here. The polynomials f(x) approximate
sin(pi/2*x) for x=-1..1 and are solutions with minimum peak harmonic
distortion compared to the fundamental frequency. Both solutions with
continuous and discontinuous derivative are given. In summary:

Shared polynomial approximation properties and constraints:
x = -1..1, f(-1) = -1, f(0) = 0, f(1) = 1, and f(-x) = -f(x).

If continuous derivative:
f'(-1) = 0 and f'(1) = 0 for the anti-periodic extension f(x + 2) = -f(x).

5th order, continuous derivative, -78.99 dB peak harmonic distortion:
f(x) = 1.569778813*x - 0.6395576276*x^3 + 0.06977881382*x^5

5th order, discontinuous derivative, -91.52 dB peak harmonic distortion:
f(x) = 1.570034357*x - 0.6425216143*x^3 + 0.07248725712*x^5

7th order, continuous derivative, -123.8368 dB peak harmonic distortion:
f(x) = 1.570781972*x - 0.6458482979*x^3 + 0.07935067784*x^5
- 0.004284352588*x^7

7th order, discontinuous derivative, -133.627 dB peak harmonic distortion:
f(x) = 1.5707953785726114835*x -
0.64590724797262922190*x^3 + 0.079473610232926783079*x^5
- 0.0043617408329090447344*x^7

Also the exact coefficients that are rational functions of pi are given in
the answer, in case anyone needs more precision.

-olli
___
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-21 Thread robert bristow-johnson



�
i just got in touch with Olli, and this "triangle wave to sine wave" shaper 
polynomial is discussed at this Stack Exchange:



https://dsp.stackexchange.com/questions/46629/finding-polynomial-approximations-of-a-sine-wave/46761#46761




 Original Message 

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

From: "robert bristow-johnson" 

Date: Thu, February 21, 2019 1:33 pm

To: "A discussion list for music-related DSP" 

--



>

>

>

>�

> yup. that's a good way to do it, too. i've done this with a 5th-order 
> odd-symmetry polynomial (so there were only 3 non-zero coefficients) and had 
> harmonics suppressed down 70 dB below the fundamental.

> first generate sawtooth (at your fundamental frequency) with

> limits of -1 and +1 using a simple phase accumulator.

> second, perform abs value (the sawtooth turns into a triangle from 0 to +1).

> third, subtract 1/2 from the triangle, now the limits are from -1/2 to +1/2

> lastly run that into the 5th-order (or higher odd-order, if you like)

> polynomial to get something very close to a sinusoid.

> i thought, years ago, we were discussing this and Olli Niemetalo had 
> optimized coefficients for the polynomial.

> r b-j

>

> ---------------- Original Message ----

>

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

>

>

From: "Phil Burk" 

>

> Date: Thu, February 21, 2019 9:25 am

>

> To: "robert bristow-johnson" 

>

> "A discussion list for music-related DSP" 

>

> --

>

>> Another approach is to use a Taylor Expansion. It's pretty accurate in the

>> first quadrant. One advantage over the resonator is that it does not drift.

>> Another advantage is that you can do FM without paying the penalty of

>> recalculating the coefficients.

>>

>> Here is some free Java source.

>>

>> https://github.com/philburk/jsyn/blob/master/src/com/jsyn/unitgen/SineOscillator.java

>>

>> Phil Burk

>>

>>

>> On Wed, Feb 20, 2019, 4:12 PM robert bristow-johnson <

>> r...@audioimagination.com> wrote:

>>

>>> personally, i think that phase accumulator and wavetable lookup and

>>> intersample interpolation is the best way to do a time-varying sinusoidal

>>> oscillator,

>


--



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-21 Thread Andrew Simper
Thanks Robert, much appreciated for adding this to my code :)

With double precision I've noticed that even when undergoing drastic
frequency modulation it all works pretty accurately still, so any
correction term could probably be applied with a very long time constant
and linear interpolation to reduce the cpu load something along the lines
of (have not compiled or tested so could contain errors):

pre loop:
new_gain = 1 + adaptationspeed*(1 - c*c - s*s)
gain_inc = (new_gain - gain)/blocklength

loop blocklength:
t0 = g0*c - g1*s
t1 = g1*c + g0*s
c = gain*t0
s = gain*t1
gain += gain_inc




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

>
>
>  Original Message --------
> Subject: Re: [music-dsp] Time-variant 2nd-order sinusoidal resonator
> From: "Andrew Simper" 
> Date: Wed, February 20, 2019 9:20 pm
> To: "Robert Bristow-Johnson" 
> "A discussion list for music-related DSP" 
> --
>
> > 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

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

2019-02-21 Thread robert bristow-johnson



�
yup.� that's a good way to do it, too.� i've done this with a 5th-order 
odd-symmetry polynomial (so there were only 3 non-zero coefficients) and had 
harmonics suppressed down 70 dB below the fundamental.
first generate sawtooth (at your fundamental frequency) with
limits of -1 and +1 using a simple phase accumulator.
second, perform abs value (the sawtooth turns into a triangle from 0 to +1).
third, subtract 1/2 from the triangle, now the limits are from -1/2 to +1/2
lastly run that into the 5th-order (or higher odd-order, if you like)
polynomial to get something very close to a sinusoid.
i thought, years ago, we were discussing this and Olli Niemeto had optimized 
coefficients for the polynomial.
r b-j

 Original Message 

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

From: "Phil Burk" 

Date: Thu, February 21, 2019 9:25 am

To: "robert bristow-johnson" 

"A discussion list for music-related DSP" 

--



> Another approach is to use a Taylor Expansion. It's pretty accurate in the

> first quadrant. One advantage over the resonator is that it does not drift.

> Another advantage is that you can do FM without paying the penalty of

> recalculating the coefficients.

>

> Here is some free Java source.

>

> https://github.com/philburk/jsyn/blob/master/src/com/jsyn/unitgen/SineOscillator.java

>

> Phil Burk

>

>

> On Wed, Feb 20, 2019, 4:12 PM robert bristow-johnson <

> r...@audioimagination.com> wrote:

>

>> personally, i think that phase accumulator and wavetable lookup and

>> intersample interpolation is the best way to do a time-varying sinusoidal

>> oscillator,

>>

>
�
�
�


--



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-21 Thread robert bristow-johnson







 Original Message 

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

From: "Martin Vicanek" 

Date: Thu, February 21, 2019 10:33 am

To: music-dsp@music.columbia.edu

--



> /Ian wrote:

> 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.

>

> /Ethan wrote:

> A very simple oscillator recipe is [the coupled form]. However, it's not 
> stable as is, so you periodically have to make an adjustment to make sure 
> that a^2 + b^2 = 1.

>

> You can have both: A (hyper)stable quadrature oscillator without the need to 
> adjust states upon frequency modulation, and without the need to counteract 
> amplitude runaway:

> https://vicanek.de/articles/QuadOsc.pdf

>

�
this is Martin's quadrature oscillator alg:
�

// initialize u and v

at start do{

u = 1;

v = 0;

}

�

// update coefficients

if frequency changes do{

update w;

k1 = tan(0.5*w);

k2 = 2*k1/(1 + k1*k1);

}

�

// iterate filter

for every sample do{

tmp = u - k1*v;

v = v + k2*tmp;

u = tmp - k1*v;

}

�

and it looks very interesting and efficient.� i am still concerned about long 
term amplitude stability, since, like the other quadrature osc, there are two 
poles resting precisely on the unit circle (assuming infinite precision).� this 
is clear because no scaler multiples u or v or tmp
in the assignments to those same lvalue quantities.
with finite precision these poles will either be slightly inside the unite 
circle which will cause the output to slowly die off (but it might take a 
couple days of continuous running to notice) or they will be slightly outside 
the unit circle
and the amplitude will rise slowly.
the gain adjustment that i suggested in one way, but a simple method to make 
this "stable" is to round the coefficients, k1 and k2, up (in magnitude) very 
slightly (making the output grow slowly) and *clipping* or limiting the outputs 
u and
v.� that is what i originally did with the 56K (an ancient 24-bit fixed point 
DSP) long ago.
i'm gonna fiddle with Martin's interesting variant of the quadrature 
oscillator.� i am happy to learn better and more efficient ways of doing things.
But Martin, if you let this thing
run for days on end, would not eventually the amplitude of the output change a 
bit?

--



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-21 Thread Dario Sanfilippo
This looks great.

Thanks, Martin.

Dario




On Thu, 21 Feb 2019 at 19:33, Martin Vicanek  wrote:

> *Ian wrote:
> 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.
>
> *Ethan wrote:
> A very simple oscillator recipe is [the coupled form]. However, it's not 
> stable as is, so you periodically have to make an adjustment to make sure 
> that a^2 + b^2 = 1.
>
> You can have both: A (hyper)stable quadrature oscillator without the need to 
> adjust states upon frequency modulation, and without the need to counteract 
> amplitude runaway:https://vicanek.de/articles/QuadOsc.pdf
>
> ___
> 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-21 Thread Phil Burk
Another approach is to use a Taylor Expansion. It's pretty accurate in the
first quadrant. One advantage over the resonator is that it does not drift.
Another advantage is that you can do FM without paying the penalty of
recalculating the coefficients.

Here is some free Java source.

https://github.com/philburk/jsyn/blob/master/src/com/jsyn/unitgen/SineOscillator.java

Phil Burk


On Wed, Feb 20, 2019, 4:12 PM robert bristow-johnson <
r...@audioimagination.com> wrote:

> personally, i think that phase accumulator and wavetable lookup and
> intersample interpolation is the best way to do a time-varying sinusoidal
> oscillator,
>
___
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-21 Thread Ethan Fenn
You probably won't need to correct the amplitude every sample because the
error introduced every tick should be tiny. You can do it every N samples
and just see what value of N introduces an acceptable amount of noise. Or
just fold the amplitude management in as Robert suggests, that way you get
amplitude envelopes and stability as a natural consequence.

You don't necessarily need to use a real sqrt() for this, you could use the
fast inverse square root that Evan linked to. Something even simpler like
approximating 1/sqrt(x) as 0.5*(3-x) might work fine too -- you just need
to keep the amplitude nudged in the right direction after all.

-Ethan


On Thu, Feb 21, 2019 at 8:34 AM STEFFAN DIEDRICHSEN 
wrote:

> If an update on a zero-crossing is enough, you might want to take a look
> at the wave guide oscillator:
> https://ccrma.stanford.edu/~jos/pasp/Digital_Waveguide_Oscillator.html
>
> It does like updates at zero-crossings, but needs some history
> corrections.
>
> The coupled-form oscillator, as discussed in the thread, has an issue, if
>  the sum of the squares of the coefficients is not exactly 1.0. I’m not
> sure, if a small controlled contamination with noise of the coefficients
> might help.
> just an idea. Like switching between 2 coefficient sets to meet the above
> condition in a time interval. Just a weird idea.
>
> Best,
>
> Steffan
>
>
> On 21.02.2019|KW8, at 13:58, Dario Sanfilippo 
> wrote:
>
> 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.
>
>
> ___
> 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-21 Thread STEFFAN DIEDRICHSEN
If an update on a zero-crossing is enough, you might want to take a look at the 
wave guide oscillator:
https://ccrma.stanford.edu/~jos/pasp/Digital_Waveguide_Oscillator.html

It does like updates at zero-crossings, but needs some history corrections. 

The coupled-form oscillator, as discussed in the thread, has an issue, if  the 
sum of the squares of the coefficients is not exactly 1.0. I’m not sure, if a 
small controlled contamination with noise of the coefficients might help. 
just an idea. Like switching between 2 coefficient sets to meet the above 
condition in a time interval. Just a weird idea. 

Best,

Steffan 


> On 21.02.2019|KW8, at 13:58, Dario Sanfilippo  
> wrote:
> 
> 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.
> 

___
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-21 Thread Dario Sanfilippo
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" 
> Date: Wed, February 20, 2019 9:20 pm
> To: "Robert Bristow-Johnson" 
> "A discussion list for music-related DSP" 
> --
>
> > 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

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

2019-02-21 Thread robert bristow-johnson







 Original Message 

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

From: "Andrew Simper" 

Date: Wed, February 20, 2019 9:20 pm

To: "Robert Bristow-Johnson" 

"A discussion list for music-related DSP" 

--



> 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

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