Forums

Audio localization in MATLAB

Started by John May 10, 2004
Hey,
 The question I have is that how do u apply localization to a sound
file in MATLAB. What i have to do is shift a wav file (100 Hz sine)
from direct center stage 45 degrees to the left, 45 degrees to the
right, 135 degrees to the left and 135 degrees to the right. If anyone
could provide me with example MATLAB code to do this. Thanks
John wrote:
> Hey, > The question I have is that how do u apply localization to a sound > file in MATLAB. What i have to do is shift a wav file (100 Hz sine) > from direct center stage 45 degrees to the left, 45 degrees to the > right, 135 degrees to the left and 135 degrees to the right.
Well, take your speaker and move it 45 degrees to the left, then 45 degrees to the right, then ... (sorry, couldn't resist :) If you can't move your speaker, tell us what kind of speaker setup you have (LR, LCR, LR RL RR, LCR R, etc.). If it is simply LR (left right), you can do amplitude panning - this keeps a constant signal power when dividing the signal up for left and right speaker. Left_Signal = sin^2 (alpha) * Mono_Signal Right_Signal = cos^2 (alpha) * Mono_Signal and alpha is the panning angle: 0� = complete right, 90� = complete left. Regards, Andor
I wrote
...
> Left_Signal = sin^2 (alpha) * Mono_Signal > Right_Signal = cos^2 (alpha) * Mono_Signal
Did I really write that? It should of course be simply sin and cos without the square, otherwise you don't get Left_Signal^2 + Right_Signal^2 = Mono_Signal^2.
> and alpha is the panning angle: 0� = complete right, 90� = complete > left.
Perhaps I should have written that alpha is the panning parameter. The actual angle depends on where the two speakers are situated.
> > Regards, > Andor
John wrote:

> Hey, > The question I have is that how do u apply localization to a sound > file in MATLAB. What i have to do is shift a wav file (100 Hz sine) > from direct center stage 45 degrees to the left, 45 degrees to the > right, 135 degrees to the left and 135 degrees to the right. If anyone > could provide me with example MATLAB code to do this. Thanks
If you use Headphones, you can localize the sound by changing the time difference of arrival between both ears. This is called Interaural time difference ITD. There is a formula based on a rigid sphere with ears disposed diametrically. ITD = a/c * (sin(theta)+theta), theta corresponds to the degrees, a is the radius of the sphere (you can try with 82 mm), and c is the speed of the sound (you can use 340 m/s). Then you can add this delay to either left or right signal depending to which side you want to move the sound. regards, Pablo F. Hoffmann