0
$\begingroup$

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.

$\endgroup$
8
  • $\begingroup$ The title asks about comparing spring mass oscillator to band pass filter. These are essentially the same. But the question is then asking about arrays of oscillators. This could bring in complication. $\endgroup$
    – Jagerber48
    Commented Jan 21 at 8:33
  • $\begingroup$ Also reviewing the code is out of scope for physics stack exchange I think this question needs to be focused down $\endgroup$
    – Jagerber48
    Commented Jan 21 at 8:34
  • $\begingroup$ This is really about numerical integration for all I can tell. Naive numerical integration schemes like the Euler method have problems. They tend to cause instabilities, don't conserve energy etc.. The same applies to filters. As soon as you go closer to the sampling frequency the naive filter will have a very different cutoff/resonance frequency than expected. The correct design procedures are explained in the literature. With regards to the physics question... what physicists call a harmonic oscillator is, as you point out correctly, known as a resonant bandpass in electrical engineering. $\endgroup$ Commented Jan 21 at 8:35
  • $\begingroup$ @FlatterMann, based on my experience, I don't think a resonant bandpass is the same as a harmonic oscillator. Sure there might be stability issues, but I have already now simulated a harmonic oscillator. Even when running stable, it is letting the full or at least high freq noise burst through. This suggests to me that it is more of a resonant high pass filter. ie. A damped mass-spring harmonic oscillator can be forced into rapid higher frequency oscillations in a way a resonant bandpass can't. Unless I made an error in my code? I don't think I did. It's pretty simple. $\endgroup$
    – mike
    Commented Jan 21 at 8:38
  • 1
    $\begingroup$ If you are applying a periodic force to a mass (without spring) it automatically acts like a low pass. The behavior you are describing is an implementation issue. $\endgroup$ Commented Jan 21 at 8:43

1 Answer 1

2
$\begingroup$

Fast look into your code. It looks like you're using a time-explicit numerical method (Explicit Euler, $1^{st}$ order explicit method), that is very likely to make your simulation diverge. My suggestion: use some routine from some numerical library to perform the numerical integration with the numerical scheme you need/like the most: maybe some Runge-Kutta method is ok for you (high order could help in avoiding extra numerical damping, common of low order schemes), I don't know if you need some stiff integrator; but if you use some numerical library you can change the numerical method by changing only one or few lines of the code.

Damped spring-mass system. I won't go into lines of code here, but I'll answer that a damped spring-mass system \begin{equation} m \ddot{x}(t) + c \dot{x}(t) + k x(t) = f(t) \ , \end{equation} or in its "non-dimensional" form (with $\frac{k}{m} = \omega_n^2$, $\frac{c}{m} = 2 \xi \omega_n$), \begin{equation} \ddot{x}(t) + 2 \xi \omega_n \dot{x}(t) + \omega_n^2 x(t) = \dfrac{1}{m} f(t) \ , \end{equation} is a low pass filter, with a range of frequency of amplification approximately around the natural frequency $\omega_n$, if not damped enough.

You can easily realize that, transforming in Laplace or Fourier domain, \begin{equation} \begin{aligned} x(s) & = \dfrac{1}{m} \dfrac{1}{s^2 + s \, 2\xi\omega_n + \omega_n^2 } f(s) = G(s) f(s) \qquad \qquad \text{(Laplace)} \\ x(j\omega) & = \dfrac{1}{m} \dfrac{1}{\omega_n^2 - \omega^2 + j 2\xi\omega_n \omega} f(j\omega) = G(j\omega) f(j\omega) \qquad \text{(Fourier)} \ , \end{aligned} \end{equation} and plotting Bode diagram for a graphical description of the harmonic response of the system.

enter image description here

$\endgroup$
3
  • $\begingroup$ That's very interesting. Many people have commented/replied saying they think it is a resonant bandpass. So would you say a damped mass-spring harmonic oscillator is NOT a resonant bandpass, but rather a resonant low pass filter? Thanks. I suspect from replies and comments so far the noise burst I am getting is not the noise excitation signal passing through (ie. not resonant high pass filter), but rather some new burst of noise being created by my force conversion being too crude at the typical audio sample rate. $\endgroup$
    – mike
    Commented Jan 21 at 8:54
  • 1
    $\begingroup$ You're using an integration scheme that is explicit in time. This could lead to instability and explosion of the simulation, since this method is very likely unstable $\endgroup$
    – basics
    Commented Jan 21 at 9:06
  • $\begingroup$ @mike did you solve it? If so, and this answer is ok, please mark it as the accepted answer, so that we could considered this problem as fixed $\endgroup$
    – basics
    Commented Jan 21 at 11:45

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.