Making a better oscillator

I was playing around with oscillator this morning and I realised that we don’t actually have a method for making an oscillator at a desired frequency. For example, given this code:

import nengo

period = 0.5

with nengo.Network() as model:
    osc = nengo.Network()
    osc.config[nengo.Ensemble].neuron_type = nengo.LIFRate()
    nengo.networks.Oscillator(0.1, 1/period, 300, net=osc)
    bump = nengo.Node(lambda t: 1 if t < 0.1 else 0)
    nengo.Connection(bump, osc.ensemble[0])
    
    p_osc = nengo.Probe(osc.ensemble, synapse=0.01)

I don’t actually get an oscillator with a frequency of 2Hz, as shown below.

Consequently, is it possible to make a more accurate oscillator? I think one way would be to create a frequency controlled oscillator and decrease/increase the gain based off an error, but that feels a bit hacky. Is there some offline/analytical way to do this that avoids having to run the model twice?

Hmmm. I think the problem here is that the frequency is not in terms of $\omega$. To do that, you’ll need to divide the period by $2\pi$, and that should give you a more accurate frequency.

You’re totally right and I’m going to update the documentation to reflect this.

I’ve updated my comment. It should read ‘the frequency is not…’ instead of ‘the period is not…’.
Also, instead of dividing the period number by $2\pi$, one can use $2\pi / period$ as the input to the frequency parameter in the oscillator function call.