Background
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) {
//SOLVE DRIVING FORCE BEING PUT INTO IT FROM EXCITER SIGNAL
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
//PROTECT AGAINST HIGH FREQUENCIES DUE TO INSTABILITY
if (springFreq > 21000 || springFreq > 0.08 * sampleRate) {
return 0;
}
//SOLVE MOTION OF DAMPED MASS-SPRING OSCILLATOR
double F_dampedSpring = (springK * currentPos) + (dampCoeff * currentVel);
currentForce = F_input - F_dampedSpring;
currentVel += currentForce * deltaTime;
currentPos += currentVel * deltaTime;
return currentPos;
Similarities/Differences
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.
Questions
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.
EDIT
Based on replies and comments so far that the harmonic oscillator should certainly be identical to the bandpass, 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 some 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.