• 14
• 12
• 9
• 10
• 9

# Sound Collision

This topic is 4693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok. Lets say I have a wave at a certain frequency, with a certain amplitude. W(f,a). Lets say that at a point in the system, A lot of waves collide. How can I take the average of all waves? Would I just say do something like sum(a*f,1,n)/(maxAmplitude * maxFrequency), where there are n waves?

##### Share on other sites
Why do you want to take the average? Waves combine by simple addition. And if you really want the average, you have to divide by the number of waves, not maxAmplitude * maxFrequency'.

##### Share on other sites
It is for an AI Simulation I am writing. Basically, say I have something like
struct Wave{     int frequency;     int strength;}`

Lets say I have wave[10], which holds all 10 waves at a certain point. How would I do this? Would I just add frequencies and strengths?

##### Share on other sites
to get the average power?

I'm not a sound expert, but from my short lived engineering days, It's more complicated than that.

You can't really add up waves like that. If you play a C and a E on a piano together, you don't get a D.

For amplitudes, I guess you can sum up the amplitudes and divide by the number of waves. However, that's also very questionable.

Frequency response, and you also have to consider the natural decay of the sound as it travels through a medium. Higher frequency waves usually die out a lot quicker than the lower frequency waves.

##### Share on other sites
The combined amplitude of the waves will depend on the phase of the two (or more) components. If the phase is the same you add the amplitude, if they are exactly opposite you substract the amplitude. Depending on what you want to do with it you could take the statistics approach, and assume that on avarage these two cases will cancel each other out. Then you need to take the avarage of the amplitudes. Alternativly you could of course also store the phase.

It all becomes a bit more difficult if the two waves have a different frequency, in that case you will end up with 'perceived' frequencies of the sum, and the difference of the two frequencies.

##### Share on other sites
What exactly does your AI need to know? The power of the combined wave? I have never seen a situation where the AI actually needs to know anything about sounds. Usually you just simulate sounds using a message that is passed to the AI entities in some radius of the point where the sound was generated.

##### Share on other sites
Quote:
 Original post by Sagar_IndurkhyaIt is for an AI Simulation I am writing. Basically, say I have something like*** Source Snippet Removed ***Lets say I have wave[10], which holds all 10 waves at a certain point. How would I do this? Would I just add frequencies and strengths?

You need to know more about your wave. I'm also assuming we're talking sinusoidal waves.

To work out the displacement at a particular point in space, we need to know -
Wavelength=w
Phase angle=a
Start position=O
Amplitude=A
Attenuation function= At(x)
Position=P

For each given wave, the displacement (dy) at point P is given by -
dy=At(O-P)*sin(((O-P/w)*(2*PI))+a)*A

For multiple waves, we use superposition and just add the displacements for each given wave.

I don't know why you would want to produce the average other than to prevent clipping, but if you want a mixing function you would use something like -

Td=sum(dy[wave]*MixValue[wave])

A true average would be given by making each MixValue=1/NumWaves

A better solution would be to add in a compressor or expander to reduce any clipping.