Thursday, June 14, 2012

A computational model of sound waves in 3 dimensional space


In order to construct a 3 dimensional visual sound waves, we employed the Vpython. The following is the sample of our code.
________________________________________________________________________

from visual import*
import pylab as p
import mpl_toolkits.mplot3d.axes3d as p3

t= 0.03
xs= 0
ys= 0
N= 40
speed_sound=344
dt= t/N

Xcoords= arange(0,t+dt,dt) #(start,stop,step)
Ycoords= arange(0,t+dt,dt)
[xd,yd]= meshgrid(Xcoords,Ycoords)
Xcoords=sqrt((xd-xs)**2+(yd-ys)**2)

wavelength1= 2.1328
omega=-2*3.141592*speed_sound/(wavelength1)
P_max1= 0.05730
Phase_shift1=0
Offset1=0
SP1=P_max1*sin(omega*Xcoords+Phase_shift1)+Offset1

wavelength2=1.995
omega=-2*3.142*speed_sound/(wavelength2)
P_max2= 0.2894
Phase_shift2=0
Offset2=0
SP2=P_max2*sin(omega*Xcoords+Phase_shift2)+Offset2

Random_f=0.005*sin(1.8*omega*Xcoords)+0.5*cos(1.67*omega*Xcoords)
SP3=SP2+Random_f

fig=p.figure()
SPgraph=p3.Axes3D(fig)
SPgraph.plot_wireframe(xd,yd,SP1)
SPgraph.plot_wireframe(xd,yd,SP2)
#SPgraph.plot_wireframe(xd,yd,SP3)
#SPgraph.plot_wireframe(xd,yd,Random_f)
SPgraph.set_xlabel('Xd')
SPgraph.set_ylabel('Yd')
SPgraph.set_zlabel('SP')

fig2=p.figure()
p.contour(xd,yd,SP1)
p.show()

_______________________________________________________________________
Model 1: 3-dimensional model of sound waves (ideal)
Model 1: 3-dimensional model of sound waves (ideal+random signals)

In model 1, the smaller amplitude corresponds to the sound pressure 1, which is from direct voice signals, and the larger corresponds to the sound pressure waves output by the speaker. Since this model was an ideal case, the sound waves are very smooth, and they have same amplitude. In model 2, random signals were added to the sound waves from the speaker. As a result, the amplitude keeps changing.

2 comments:

  1. you should check out my blog... we thrive on the same love of the atmosphere, and audio

    ReplyDelete