Simulating a Speaker (and it's frequency Response) in Python

Hello all,

I am trying to figure out how to simulate a speaker in python.
My basic understanding of this topic is that I should use the Thiele-Small Parameter to calculate values of an electrical network which represents the Speaker (electrical and mechanical part).
Then this network needs to be expressed as an function so we can use it to generate the output for a given input. For example a simple sine wave should show up with some harmonic distortion at the output.

As I am not a scientist, I have no idea how to calculate the values of the electrical network and I couldn't find a good source on the internet that explains it so I can understand it. I hope (and think) that it should be relatively easy to calculate those values from the Thiele-Small-Paramters once you have the right formulars at hand. If someone could point them out to me that would be a great help for making this first step.
 
Hello all,

I am trying to figure out how to simulate a speaker in python.
My basic understanding of this topic is that I should use the Thiele-Small Parameter to calculate values of an electrical network which represents the Speaker (electrical and mechanical part).
Then this network needs to be expressed as an function so we can use it to generate the output for a given input. For example a simple sine wave should show up with some harmonic distortion at the output.

As I am not a scientist, I have no idea how to calculate the values of the electrical network and I couldn't find a good source on the internet that explains it so I can understand it. I hope (and think) that it should be relatively easy to calculate those values from the Thiele-Small-Paramters once you have the right formulars at hand. If someone could point them out to me that would be a great help for making this first step.

A typical simple lumped model using Thiele-Small parameters will be linear and will not predict any distortion. Nor will it predict the effects of cone resonances, sound radiation patterns, etc... More complete models exist which including more of the physics but they obviously require the writing of many more lines of code.

What problem are you trying to solve and how accurate does your model need to be?

A few years ago I wrote a python script to simulate a woofer in a sealed box to provide boundary conditions for a vibration analysis of a speaker cabinet. It was about 300 lines long but most of it was input and various kinds of plots with the main calculation being about 30 lines long. My notes include the derivation of the equations for the python script. The model was simple enough to write down by inspection without the need to solve via a network. If interested I could post the derivation here (if I knew how).
 
Model what? The crossover, the radiated sound, the magnet flux in the driver,...?

Do you want to write code to solve the governing equations for whatever it is you want to know in python (not particularly wise) or do you want to write a top level script in python that calls functions written in more appropriate and efficient languages (wiser)? If the latter and you want to solve sound radiation then bempp might be an option. But without knowing more about what you want to know and the role of python it is hard to advise.
 
  • Like
Reactions: 1 user
I want to model the frequency response of different shape horns with different drivers, basically to test the expansion is correct and find a suitable driver like one would with roe resp. I'd prefer to stay in python, but fairly flexible about languages, are the existing libraries in any language?
 
So you want a programme in python that does a physical 3D mechanical time-domain simulation of a speaker cone alone with a simultaneous electromagnetic simulation of driver and maybe the the air resistance too?

This is extremely complicated.

I would start by finding if there is any literature that published analytical expression for simple geometries. You could plot those uses Python.

But this type of simulation is in the domain of multi-physics solvers like COMSOL. Maybe there are software tool that can help - it’s not my area.
 
As far as I can gather, and I may be wrong on this, but hornresp only makes 1d calculations. So, for 3d horns the basic results would likely be slightly wrong, as the wave-front expanding out from the cone has a different path length in the middle (on axis) vs the angled path diffracting around the horn curve.

Rather than modeling reflections based on a 1d string of impedances, the software could generate a series of curved 3d surfaces, kind-of like tree rings, so the actual horn shape is reverse engineered from the expansion rate of the rings that float on top of one another.

My best guess would be that experimental algorithms would be done in C++, and any more elaborate graphical integration with something like Unity or some rendering engine to save yourself from having to learn 3d graphics from the ground up.
 
Just figuring out a strong algorithm would be challenging in itself, let alone taking it to a level where it's actually useful. You could model the air like a spray of particles with mass, which repel each other. I think some commerical software already does this, but I'd be damned if I could anything that's actually free and usable.
 
  • Like
Reactions: 1 user
I want to model the frequency response of different shape horns with different drivers, basically to test the expansion is correct and find a suitable driver like one would with roe resp. I'd prefer to stay in python, but fairly flexible about languages, are the existing libraries in any language?

The bempp python package mentioned above will handle sound propagation given a 3d mesh of the speaker surface and appropriate velocities specified on the driver cones+surrounds. The mesh can be generated from python using the gmsh package. The velocities on the driver cones can be determined from a either a simple network model of the drivers or directly from inspection given the simplicity of such models. If I recall correctly it took me less than 100 lines of python to implement a model for a subwoofer to provide the forcing for a model speaker cabinet and it's sound radiation.

If one is familiar with the packages, python and basic acoustics it might take a couple of afternoons to generate the initial simulations. If not it will take longer depending on what one needs to learn. There are alternative packages for the geometry, mesh, acoustics, network solvers, etc... but they are nearly all research packages rather than easy to use commercial engineering packages like COMSOL.
 
  • Like
Reactions: 1 user