What I am doing:

In short, I want to write a program that is fed a song as a wav file, and spits out an animated contour plot indicating the relative pressure/loudness/quantity indicating amplitude at various points in a plane. Each speaker is modeled as a point source a set distance from each other hanging in an infinite void. My weapon of choice is Matlab.

How I am doing it:

Poorly. Song is read and split into channels, then cut into little slices. Each slice is FFT'd and the amplitudes and phases are split. For each point in the simulation space every frequency is taken, wavelength calculated and used in combination with the phase to determine the contribution of that frequency to the dimensionless loudness/pressure/sound intensity indicating quantity in that cell (the exact unit isn't that important - explained in next section). Do this for each slice of song, draw contour plots for each slice, and animate!

What my problem is:

The above seems kinda clumsy, and my preliminary results tell me I'm likely neglecting something huge or making some kind of fundamental error. Please note the idea here isn't to make a simulation for speaker setup or any kind of real physical use, I want to draw pretty pictures of what songs do with some basis in reality (specific application: psytrance). This is why the units are not that important, whether I use the normalised voltages in the wav file or convert it to dB or pressure... apart from looking a bit different in lin or log space the relative difference should be the same, at least for my pretty-picture-drawing-purposes. Once the program works as planned some number-fudging will occur to make it look better.

My Questions

1) Can someone suggest a better way of doing this? I feel like I'm doing this in a too complex manner, but I don't even know where to begin looking for a different method to accomplish my goals.

2) Am I right in doing phase corrections with the values given in the FFT? Gut says the error is here - Fourier coefficients are returned as complex numbers a+bi - for the use I have described here, how would I use this to yield "amplitude" and phase angle? It's a simple question... but humour me, self-kicking might follow your answer.

Edit: On second thought this may not be the most appropriate place to post this (at least for part 1 of the question), if someone can suggest a better place, please do.

  • $\begingroup$ so you want to make something like falstad.com/ripple but with a wav file as the signal source? $\endgroup$
    – endolith
    Apr 20, 2015 at 21:09
  • $\begingroup$ Yeah, basically. Made a render of it in action: youtu.be/4M-LSChEBD8 $\endgroup$
    – teatime
    Apr 20, 2015 at 22:13

2 Answers 2


I think your method is kind of over kill. All you really need is the instantaneous power for each point (or each block) in your music.

You can use the hilbert function to get the instantaneous amplitude of your signal, which will do as a representation of the instaneous power. Split your signal into blocks (cells, as you called them) then do abs(hilbert(x)) where x is a cell. Average if the length of a cell is all the time resolution you need, or use each value in the sequence as the amplitude at a single sample.

Now, for your display.

A flat surface, with a center point that show the amplitude for the current sample (or cell,) with rings around it representing the amplitudes for the last samples (cells) - each ring is one sample (cell) into the past.

Alternatively, use the distance from your point source to the surface to determine how far into the past each point displayed should be. Straight ahead (angle 0 degrees) is shortest, and represents now. At ten degrees off center, you would have 1/(cos(10)) = distance of 1.015 times the straight ahead distance. Use the speed of sound and your simulated distance from speaker to the surface to figure out how much time (in samples or cells) that relates to. That will produce a ring on your surface representing the amplitude for a certain time in the past.

For 1 meter, the ten degrees would be 3 milliseconds or 135 samples at 44100 samples per second (typical CD sampling rate.) 70 Degrees at one meter would be about 8.8 milliseconds or 389 samples.

Simulating the distance from the speaker to the surface will tend to produce relatively smooth gradients in the center that get sharper the further out you go. Simply plotting rings based on cells would give you an image with more jumps in the gradient. Either method gives you room to play around and make things more interesting.

  • 1
    $\begingroup$ The method you suggest might give a nice looking visualisation, but has nothing to do with the physics of sound propagation. Where would the instantaneous power come from? Or what component of the speaker-field system performs a Hilbert transform? If you read the OPs question so that he wants the mean field pressure instead of the actual microscopic oscillating pressure changes, then averaging the pressure over a finite spatial region would be the way to go. $\endgroup$
    – Jazzmaniac
    Apr 20, 2015 at 14:49
  • $\begingroup$ When the sound hits the flat surface, the sound pressure exerts a force on the surface which results in a deformation of that surface. This can be likened to determining the instantaneous power at that spot at that moment, hence the use of the hilbert transform to get the instantaneous amplitude. The simple ring display (obviously) isn't a good simulation. The calculated time of arrival for various angles is more realistic, though probably not really all that accurate. Since the OP's ultimate goal is "pretty picture drawing," inaccurate physics/mathematics need not be a hindrance. $\endgroup$
    – JRE
    Apr 20, 2015 at 14:58
  • 1
    $\begingroup$ Your physics is way off, as is the suggestion that average power and instantaneous Hilbert envelope magnitude have any relation. The OP also explicitly asked for a model of a point like source. Such a geometry inevitably does produce spherical shells of constant pressure or displacement. The accurate answer to his question is so simple that I really wonder what point you try to convey by making the answer so complicated and also physically wrong. $\endgroup$
    – Jazzmaniac
    Apr 20, 2015 at 15:06
  • $\begingroup$ Yes, it doesn produce the shells you are discussing. No argument. If you now place a plane across your shells, you will get the rings I've been trying to describe, which the OP specifically mentions. I did, however, miss that the OP wants to use multiple speakers. That only means that you have to do sums from each speaker at each point on the plane. The Hilbert doesn't give you average power (or amplitude,) though you can get it from averaging the results. It gives you instantaneous amplitude for specific samples, which I think should give you better time and space resolution. $\endgroup$
    – JRE
    Apr 20, 2015 at 15:16
  • $\begingroup$ You are aware that Hilbert envelopes are fundamentally acausal? $\endgroup$
    – Jazzmaniac
    Apr 20, 2015 at 15:21

For a perfect isotropic point source the pressure or air displacement at a point is just the pressure/displacement stimulating signal delayed by the time it took the disturbance to travel to that point.

That means you get spherical shells of constant displacement, and the displacement is the signal at the time $t-d/c$ where $d$ is the distance from the source and $c$ is the propagation speed.


If you do not require the full resolution of the pressure field that would allow you to actually reconstruct the sound from the field then you may want to average the pressure over spatial volumes of constant size. That is not equivalent to a time average of the power, because the influence of spatial coarse graining on the pressure history depends on where you are. Only in the far field where the radius of the constant pressure sphere is much larger than the typical coarse graining scale, time averaging ans spatial averaging become equivalent.

So it depends on what you want exactly and what you need it for. The physics involved is very simple for a perfect point source, but gets very complicated as soon as you have participating objects. Maybe you can give a more detailed description of what you are trying to achieve with this.

  • $\begingroup$ What I want it for is covered by the section titled "What my problem is:". In essence I want to make a visual representation of a song. Your answer helped, but I can only select one, and this being a new account means I can't give you a point. If you put your hand out the window palm facing the sun a high-5 should be arriving some time in the next 12 minutes. $\endgroup$
    – teatime
    Apr 20, 2015 at 16:16

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.