Given the time differences of arrival of a sound between the microphones of an array, and the positions of those microphones, estimates the direction the sound arrived from.
Arguments
- delays
Time differences of arrival in seconds, one per microphone, as returned by
tdoa(). Either the data frametdoa()returns, or a numeric vector in channel order. Channels with a delay of NA are ignored.- positions
Positions of the microphones in metres, as a matrix or data frame with one row per microphone (in the same order as
delays) and either two or three columns.- speed
The speed of sound in metres per second. The default is the value
soundSpeed()gives for air, a value for the conditions of a recording can be obtained with e.g.soundSpeed(method="cramer", temp=14, RH=80).- output.unit
Unit for the returned angles, either "degrees" (the default) or "radians".
- unit
Deprecated, use output.unit instead.
Value
A list holding:
azimuth The direction the sound arrived from, or two directions where the array leaves an ambiguity (see Details), or NA where no direction can be recovered.
elevation The angle above the horizontal, for positions given in three dimensions. NA otherwise.
direction A matrix holding the unit vector of each direction in the coordinates the positions were given in.
cone For microphones in a line with positions given in three dimensions, the angle between the direction of the sound and the axis of the array, measured from the first microphone towards the last. NA otherwise.
residual The root mean square difference, in metres, between the path length differences the estimate implies and those the delays give.
magnitude The length of the direction vector the fit produced, before it was scaled to a unit vector, which is 1 for delays that are exactly consistent with a plane wave (see Details). Where the array leaves an ambiguity this is the length of the part of the direction the array can see, which is at most 1.
speed The speed of sound used.
unit The unit the angles are given in.
ambiguous Whether the array leaves more than one possible direction.
Details
The sound is assumed to be far enough away that the wavefront reaching the array is flat, in which case the delay at each microphone depends on the direction the sound came from but not on how far away it was. "Far enough" is relative to the size of the array: a few array widths is usually sufficient. No distance to the source is estimated, and none can be from a single array under this assumption.
The direction is returned as an azimuth measured anticlockwise from the
positive x axis of the coordinates the microphone positions were given in. If
those coordinates have x pointing east and y pointing north, the compass
bearing of the source is (90 - azimuth) %% 360 degrees.
Arrays that cannot give a single answer
Two microphones, or any number of microphones in a straight line, determine only the angle between the direction of the sound and the axis of the array: every direction on a cone around that axis gives the same delays. For an array lying in a line in two dimensions this leaves two possible bearings, mirrored about the array axis, and both are returned. Microphones lying in a plane, with positions given in three dimensions, likewise leave two possible directions mirrored about that plane. For microphones in a line with positions given in three dimensions no bearing can be recovered, and only the angle from the array axis is returned.
Checking the result
A set of delays that is consistent with a plane wave has a magnitude of 1
and a residual of 0. A magnitude far from 1, or a residual that is an
appreciable fraction of the size of the array, means the delays are not
consistent with any single direction and the bearing should not be trusted.
Common causes are a correlation peak found on the wrong cycle of a tonal
sound, a source too close to the array for the plane wave assumption, and two
sounds overlapping in the window correlated.
Neither check is available from every array. The residual is only meaningful where there are more microphones than one more than the number of dimensions the positions are given in, as fewer leave the delays exactly enough to fit a direction to. The magnitude is only meaningful for an array that determines the direction fully, as one that does not fits only the part of the direction it can see. For a pair of microphones neither is available, and delays that are not physically possible are all that can be detected.
The speed of sound
Where the array determines the direction fully the bearing does not depend on the speed of sound, which only scales the delays: getting it wrong moves the magnitude away from 1 but leaves the direction alone. Where the array leaves an ambiguity the bearing does depend on it, so a pair of microphones is worth giving a speed calculated for the conditions of the recording.
See also
tdoa(), which produces the delays this function takes.
Examples
# Three microphones in a right angled triangle, 1m apart
mics <- rbind(c(0, 0), c(1, 0), c(0, 1))
# A sound arriving from the east reaches the eastern microphone first
bearing(c(0, -1/343, 0), mics)
#> $azimuth
#> [1] -3.020411e-14
#>
#> $elevation
#> [1] NA
#>
#> $direction
#> [,1] [,2]
#> [1,] 1 -5.271612e-16
#>
#> $cone
#> [1] NA
#>
#> $residual
#> [1] 3.220923e-16
#>
#> $magnitude
#> [1] 1
#>
#> $speed
#> [1] 343
#>
#> $unit
#> [1] "degrees"
#>
#> $ambiguous
#> [1] FALSE
#>
# A stereo pair leaves two possible bearings
bearing(c(0, -0.5/343), rbind(c(0, 0), c(1, 0)))
#> $azimuth
#> [1] 60 -60
#>
#> $elevation
#> [1] NA NA
#>
#> $direction
#> [,1] [,2]
#> [1,] 0.5 0.8660254
#> [2,] 0.5 -0.8660254
#>
#> $cone
#> [1] NA
#>
#> $residual
#> [1] 8.326673e-17
#>
#> $magnitude
#> [1] 0.5
#>
#> $speed
#> [1] 343
#>
#> $unit
#> [1] "degrees"
#>
#> $ambiguous
#> [1] TRUE
#>
