[PD-dev] van der Pol oscillator external

Alexandros Drymonitis adrcki at gmail.com
Tue Aug 19 22:09:40 CEST 2014


I'm trying to translate CSound code from the FLOSS manuals for a van der
Pol oscillator to make a Pd external. The CSound code is here
http://en.flossmanuals.net/csound/g-physical-modelling/ (you have to scroll
down till you reach the van der Pol section). I think I get what's going on
there, but the results I get when writing the output to an array, are not
the same as the ones provided in th FLOSS manuals.

Here's my perform routine:
t_int *vanDerPol_perform(t_int *w)
{
    // Copy the object pointer
    t_vanDerPol *x = (t_vanDerPol *) (w[1]);

    // Copy signal vector pointers
    t_float *frequency = (t_float *) (w[2]);
    t_float *factor = (t_float*) (w[3]);
    t_float *excitor_freq = (t_float*) (w[4]);
    t_float *excitor_amp = (t_float*) (w[5]);
    t_float *output = (t_float *) (w[6]);

    // Copy the signal vector size
    t_int n = w[7];

    // Dereference components from the object structure
    float twopi = x->x_twopi;
    float sr = x->x_sr;
    float si = x->x_si;
    float si_factor = x->x_sifactor;
    float phase = x->x_phase;
    float step = (float) EXCITOR_STEPSIZE;

    // Local variables
    float phase_local;
    float drive_sine; // sinewave to excite the oscillator
    // van der Pol samples
    float aa;
    float av = 0;
    float ax = 0;
    // damping factor
    float c;

    // Perform the DSP loop
    while(n--){
        // excitor code
        si = *excitor_freq++ * si_factor;
        phase_local = phase / step;
        drive_sine = cos(phase_local * twopi) * *excitor_amp++;

        // van der Pol code
        c = 2 - 2 * cos(*frequency++ * twopi / sr);
        aa = (-c) * ax + *factor++ * (1 - ax * ax) * av;
        av += aa;
        ax = ax + av + drive_sine;
        *output++ = av;

        // update phase
        phase += si;
        while(phase > step) phase -= step;
        while(phase < 0) phase += step;
        }

    // Update object's variables
    x->x_phase = phase;
    x->x_si = si;

    // Return the next address in the DSP chain
    return w + 8;
}

In the FLOSS manuals it says that it is excited by a sine wave oscillator,
so this is what I do in the code above, but I don't know what I'm doing
wrong. Are there specific values I should set for frequency, excitation
frequency, excitation amplitude and damping? The math is over my head to be
honest, so I'm trying to copy an applied example and this code looks much
like the CSound's code...Can someone give some insight?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20140819/dcc12649/attachment.html>


More information about the Pd-dev mailing list