I read this article here which demonstrates a simulation of a speaker as a simple RLC circuit where the RLC components are in parallel:

enter image description here


I am interested in creating a sample domain C++ script that can take audio input samples at a given sample rate and return the processed audio "output" by the "speaker".

I understand the R1 & L1 in series just create some phase rotation and nothing else (correct?) and if so, I have no interest in these components. Thus what I would want to simulate would be for example with rough values as shown here:

enter image description here

I believe the two capacitors C1 and C2 in parallel simply add together to make a new C value (summed values?), in which case it is then just a Resistor $R$, Inductor $L$, and Capacitor $C$ in parallel.


I would think this would be easy but I can't find any simple example online of this system solved in a Laplace function.

I believe what I need to do is solve the Laplace transfer function. Then I can use a reference like this one for substituting terms of z.

Or I think I'm supposed to do a substitution as I was instructed previously here, substituting one of:

  • Backward Euler: $s≃\frac{1−z^{−1}}{T}$
  • Forward Euler: $s≃\frac{z−1}{T}$
  • Tustin transformation: $s≃\frac{2(z−1)}{T(z+1)}$

where $T$ equals 1/sampleRate.

Then I need to convert this into n domain of samples for C++ coding (or any other simple language I can rewrite to C++), where n is the current sample, n_1 is the last output, and n_2 is the output two samples prior.

I have no formal education in this though and it has been 3-5 years since the last time I did this (and I have only done it a few times).

Do I have the right idea? Any help with how this would work?

  • 1
    $\begingroup$ Your forward Euler is wrong. $s$ is the derivative.. The substitution needs a difference in there. Either $z-1$ or $1-z^{-1}$ . $\endgroup$ Dec 30, 2023 at 19:00
  • $\begingroup$ Thanks. Copied it over wrong. Fixed. Thanks. Any solution or guidance on what steps I need to take or how to do it? Thanks for any help. $\endgroup$
    – mike
    Dec 30, 2023 at 19:03
  • $\begingroup$ Can you analyze the circuit in the $s$ domain? $\endgroup$ Dec 30, 2023 at 19:08
  • 1
    $\begingroup$ If you go through the effort of doing this, why not use the standard Thiele-Small model, which is a better fit and where the parameters are readily available on pretty much every data sheet ? There are also freeware tools like WinISD that will do most of the work for you. $\endgroup$
    – Hilmar
    Dec 30, 2023 at 19:58
  • $\begingroup$ Depending on the speaker, the R1/L1 pair in your first picture may matter -- they'll cause some extra low-pass filtering. Getting a Laplace-domain transfer function from an RLC circuit like this is basic circuit design stuff -- try asking on electronics.stackexchange.com or just search for "transfer function from RLC". Basically the impedance of a capacitor is $\frac{1}{Cs}$ and the impedance of an inductor is $Ls$. Just solve the network symbolically, simplify, and there's your transfer function. $\endgroup$
    – TimWescott
    Dec 30, 2023 at 20:57

2 Answers 2


Do what r b-j suggests: get a Laplace domain equivalent first, and then transform from $s$ to $z$.

The equivalent circuit will be something like:

\begin{align} H(s) &= R_1 + sL_1 + \frac{1}{\frac{1}{\frac{1}{s(C_1+C_2)}} + \frac{1}{s L_2} + \frac{1}{R_2}}\\ &= R_1 + sL_1 + \frac{1}{s(C_1+C_2) + \frac{1}{s L_2} + \frac{1}{R_2}}\\ &= R_1 + sL_1 + \frac{s}{s^2(C_1+C_2) + \frac{s}{R_2}+ \frac{1}{L_2} }\\ \end{align}

and from there, just use your Tustin transformation.

  • 2
    $\begingroup$ Tustin transformation warps the frequency axis to the point where the upper octave becomes more or less useless for this type of simulation. $\endgroup$
    – Hilmar
    Dec 30, 2023 at 19:55

That is an annoyingly difficult problem.

Physical modelling of the transfer function of an electrodynamic loudspeaker in an enclosure is well understood and there is an industry-wide accepted "standard solution" for low frequencies which is the Thiele-Small model (see for example http://www.integracoustics.com/MUG/MUG/articles/woofer/), that's a little more complex than the model you suggest but well worth the extra effort.

All of these models work analog in the frequency domain. Translating those into digital filters is remarkably difficult and I don't know of a "one size fits all" solution.

The main problem here is that the analog model is not bandlimited and direct sampling will result in aliasing.

The most common method for moving poles and zeros from the S-plane to the Z-plane is the Bilinear Transform (Tustin's method). This avoids aliasing by mapping the entire imaginary axis of the S-plane axis onto the unit circle in the z-plane. However that warps the frequency axis quite a bit especially in the higher octave.

You can also just sample in the frequency domain and do an inverse FFT. But that typically results in aliasing and in time-domain pre-ringing, which makes the impulse response non-causal and comprises the transient response.

Here are a few methods that seem to work ok

  1. Cascade the analog transfer function with a steep low-pass (anti-aliasing) filter before going digital.
  2. Same as method #1 but with a high sample rate (e.g. 96 kHz) using a milder low pass filter where most of the filtering artifacts end up in the "don't care" frequency region.
  3. Use a least square IIR filter fitting tool to match the analog response in the frequency range of interest. This does require pretty heavyweight tools and as far as I know none of the good ones is open source or easily available.
  4. Same as method #3 but using a warped FIR filter instead.

All of these have pros and cons and the best choice depends on your specific situation. Even if you do solve the problem, you need to set realistic expectations.

  1. The model is only good for low frequencies. It does not include any cone break up, baffle diffraction, driver interference, etc.
  2. The model is anechoic: it does not include the effects of boundary loading, reverb/diffuse field, early reflections, etc.

So best you can do is the model an omnidirectional speaker in an anechoic chamber which sounds quite a bit different than a real speaker in a real room.

  • $\begingroup$ What about just excessive oversampling if we're not sampling rate limited and then use method of impulse invariance by sampling the impulse response derived from the inverse Laplace Transform directly? $\endgroup$ Jan 1 at 18:22
  • 1
    $\begingroup$ That's what I was suggesting method 2: sampling at 96kHz or 192kHz. It works ok, but can result in a bit of data bloating and another step of sample rate conversion to interface with the rest of your modeling ecosystem or product (which typically run single speed). $\endgroup$
    – Hilmar
    Jan 2 at 2:57

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.