I am using resonant bandpass filters as musical oscillators. One can excite an array of them at harmonic frequencies and given Q values for a note by, for example, running a burst of noise through them.

I thought intuitively that an array of damped mass-spring oscillators tuned to the same Q and frequencies should perform the same as the resonant bandpass array.

The result is they behave similarly but also differently in some ways.

Damped Mass-Spring Oscillator

I set up some with the following code, where instead of running the audio input through the bandpasses directly as input samples, I converted the input exciter audio into force and then used that to drive the mass-spring oscillators.

I thought this would be the Newtonian way to handle this in theory. (Correct?)

double processNextSample(double sampleInput) {

    in_1 = in_0;
    in_0 = sampleInput;

    inVel_1 = inVel_0;
    inVel_0 = (in_0 - in_1) * sampleRate;

    inAcc_0 = (inVel_0 - inVel_1) * sampleRate;
    F_input = inAcc_0 * oscMass; //use imaginary mass as 1 kg to keep amplitude the same

    if (springFreq > 21000 || springFreq > 0.08 * sampleRate) {
        return 0;

    double F_dampedSpring = (springK * currentPos) + (dampCoeff * currentVel);
    currentForce = F_input - F_dampedSpring;
    currentVel += currentForce * deltaTime;
    currentPos += currentVel * deltaTime;
    return currentPos;


This creates a similar effect in that I can get the expected resonances of frequencies and the musical note comes through the same at the same amplitude. There are two main differences:

1) Stability

It is far less stable. I have to limit the frequencies relative to the sample rate as at higher frequencies it is failing. I believe it is going into NaN and inf territory easily. I am not sure why.

Perhaps the input force or stepwise position/velocity solution is too crude and discontinuities are resulting in massive forces randomly? Whereas the filter (using this one) handles this with better math somehow?

Or perhaps it is because as in point (2) below, it is letting high freqs through, and being forced into very rapid motion obviously then, the damping term is getting too big and becoming problematic at the sample rate with these high freqs as it is not parametized for this purpose, and pushing it into error.

2) Frequency Response

It sounds like it lets all the high frequencies from my exciter noise bursts through it completely, whereas the resonant bandpass filters these out. ie. If I have a single mode (bandpass or oscillator) at 80 hz, with the bandpass, I only hear ever sound around 80 hz (it filters above and below). With the oscillator, I hear the full high frequency spectrum of the burst of sound as it goes through. Not sure about the lows, but the highs are obviously passing through.


Based on this experiment, it seems the damped harmonic oscillator is not equivalent to the resonant bandpass.

What is the harmonic oscillator equivalent to then? Is it a resonant high pass filter?

What would be the mechanical/Newtonian equivalent to the resonant bandpass if one exists?

Why also (in layman's terms) is the harmonic oscillator so unstable compared to the filter?

Thanks for any thoughts or ideas.


Based on replies and comments so far that the harmonic oscillator should either be certainly be identical to the bandpass or work as a resonant low pass filter (not sure which one for sure still), then I must presume the burst of noise I am getting out of the harmonic oscillator on excitation is not the exciter noise passing through (not a high pass filter), but rather a sample rate related quantization error in my force conversion code which is creating a new noise burst.

I didn't think of that possibility. Thanks for the feedback.

  • \$\begingroup\$ I found this site which may be worth a skim. \$\endgroup\$ Commented Jan 21 at 8:29
  • \$\begingroup\$ When you introduce sampleRate and deltaTime to a linear system, complications ensue. \$\endgroup\$
    – glen_geek
    Commented Jan 21 at 13:35
  • 1
    \$\begingroup\$ Your implementation of the spring simulation is basically Euler's method, which is known to have rather poor numerical stability. \$\endgroup\$
    – jpa
    Commented Jan 21 at 18:38

2 Answers 2


You are working in the domain of DSP (digital signal processing), where time is quantized, and usually value as well. The value quantization of a double is pretty modest, of course.

Typically, DSP equations are developed without having to apply value quantization, then adding it in later, as a normally-distributed noise due to rounding error. Rounding errors have the distinction of being consistent based on input plus state values, which can result in instability, whether dithering between adjacent values, or divergence outright, so this does still need to be accounted for. It's probably fine here.

Anyway, the domain of quantized-time systems, is the Z transform, analogous to the Fourier transform of continuous-time systems. In the Z domain, stability is expressed as poles laying within the unit circle; which indeed maps to the equivalent stability criterion in the Fourier domain, poles in the left half-plane.

Put most simply, your problem is most likely that, by pushing the resonant frequency too close to the sample rate (or rather the Nyquist rate Fs/2), poles are pushed outside of the unit circle and divergence ensues.

I say "simply", but analytical control theory is a rather high-level topic. I don't intend to go into an explanation or derivation of this here -- more to say, an explanation exists, and these are the keywords and topics you will find it in.

There is also, somewhat separately, the matter of numerical stability; we can model a physical system, having some (continuous-time) differential equations, as some (quantized-time) difference equations, basically substituting \$dt \mapsto \Delta t\$; but the exact way in which we do that, affects the stability of the system, particularly as we vary the dynamics of the system with respect to its sample rate (or when the sample rate itself is variable). The trivial substitution is more-or-less Newton integration, but other rules can be applied: the trapezoidal rule; Adams-Bashforth; Runge-Kutta methods; etc. When \$\Delta t\$ is fixed, we can apply these back to DSP systems, and get a somewhat different mapping of differential to difference equations, and different stability based on the initial parameters; though the stability criterion of the final, actual, time-stepping equations is still necessarily present of course.

Numerical stability applies when doing general-purpose simulations of these systems; when we approximate an RLC circuit in SPICE, we're applying discrete-time approximations (specifically, SPICE uses a variable timestep, and trapezoidal or R-K methods), and we get consequences such as anomalous energy loss -- or gain -- in a high-Q LC resonator, for example, depending on integration method and tolerances.

  • \$\begingroup\$ Based on replies, I suspect it is a quantization error that is triggering a NEW burst of noise in my force conversion when running the simulation at audio sample rates. So I was not hearing the excitation noise passing through (not high pass filter) but rather it was creating a NEW burst of noise that made me think it was passing through. Just last point to clarify: Is the damped mass-spring harmonic oscillator a resonant low pass filter or resonant bandpass filter? I have received comments saying both. Thanks. \$\endgroup\$
    – mike
    Commented Jan 21 at 8:58
  • \$\begingroup\$ Depends how you wire it, but generally one would describe it as bandpass. It can be both, for example a mismatched low-pass with a strong peak in the transition band. \$\endgroup\$ Commented Jan 21 at 9:53

Damped harmonic oscillators are completely equivalent to RLC circuits, see https://en.m.wikipedia.org/wiki/Harmonic_oscillator.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.