Advanced Audio Recording

A Virtual Analog Oscillator in C

This page shows an example of replacing an analog circuit with digital equations.


classical analog sine circuit

The following image shows an interesting analog circuit to produce accurate sine waves with, presented in the LINEAR design journal 10 years ago. It has a remarkable distortion of less than 0,025%. Funnily it uses lamps to smoothly control the current in the path and linearize its behavior especially for low frequencies. Never tried to build it but WIEN bridge circuits generally come with high quality sine waves indeed.


Wien Brücke Sinus Generator



a self oscillating circuit

Such an oscillator equivalent can easily be built using two accumulators with a feedback and scaled factors in the path, realized with simple mathematical functions (dy/dt and dy/dt2):

analog modelling

The adders accumulate the incoming scaled values and thus act as integrators. While the first accumulated value represents a kind of "speed", the second is the "position" / "tension" in the system and thus determines directly the inverted acceleration. The resulting equations for this case are a classical differential equation system and lead to a sine wave - the known solution for oscillating mechanical and electrical systems. To use this directly in C language it is necessary to use the REAL type for the variables when performing the calculation. Doing this accuracy of better than 0,002% can be achieved for audio signals using processor frequencies of 10MHz and above.


virtual oscillating circuit in integer

For INTEGER calculation see this page here: One has to use intelligent rounding techniques to obtain a sufficient accuracy and avoid issues caused by vector cropping: Virtual Analog Oscillator



 Read more about Virtual Analog Modeling


© 2002 J.S.