beamform
Builtin index · Signal processing
beamform(signals, positions, angle_degrees, [c=343], [method="nearest"])
Input: signals, positions, angle_degrees, c, method · Output: no output
What it is
Delay-and-sum beamformer. signals: a list of Signals, one per array element, all at the same Fs and the same length; positions: a matching-length vector of element coordinates (metres, measured along the array from its origin); angle_degrees: the steering direction in degrees off broadside (the same degrees-in convention imrotate/bode_phase use, not radians); c (optional): propagation speed in m/s, default 343 (air — use ~1500 for water), also spellable c=; method (optional): the interpolation kernel used to apply each delay, interpolate_at's own three, default "nearest". Steers each channel by its geometric delay x_m*sin(theta)/c (exactly steer_delays, shared code) and averages, returning a Signal at the inputs' own Fs — which is honest here, unlike interpolate_at's plain-vector return, because every query time is the uniform axis shifted by one constant per channel. method defaults to "nearest" rather than interpolate_at's "linear" on purpose: linear interpolation averages neighbouring samples, which low-pass-filters the noise and inflates the measured array gain (7.25 dB with "nearest" vs 8.58 dB with "linear" on the 5-element example below, against 10*log10(5) = 6.99 dB of theory) — the default must report what the geometry bought, not add denoising of its own. Added in v0.3.0.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
beamform(signals, positions, angle_degrees, [c=343], [method="nearest"]) | signals Signalsignals: a list of Signals, one per array element, all at the same Fs and the same length.positions vectorpositions: a matching-length vector of element coordinates (metres, measured along the array from its origin).angle_degrees —angle_degrees: the steering direction in degrees off broadside (the same degrees-in convention imrotate/bode_phase use, not radians).c optional (default 343)c (optional): propagation speed in m/s, default 343 (air — use ~1500 for water), also spellable c=.method optional (default "nearest")method (optional): the interpolation kernel used to apply each delay, interpolate_at's own three, default "nearest". | not documented yet | Delay-and-sum beamformer. Added in v0.3.0. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
fs = 48000
d = 0.08
th = 30
c = 343
mics = [-2, -1, 0, 1, 2] * d # positions, metres, origin-centred
taus = steer_delays(mics, th, c) # per-element delay, seconds
t = linspace(0, 4799, 4800) / fs # 0.1 s of record
function channel(m)
tone = sin(2 * pi * 1000 * (t - taus[m]))
return signal(tone + 0.8 * randn(1, 4800, seed=m), fs)
end function
chans = [channel(0), channel(1), channel(2), channel(3), channel(4)]
beam = beamform(chans, mics, th) # c=343, method="nearest" by default
print("beamformed {beam.len} samples at {fs} Hz")
beamformed 4800 samples at 48000 Hz
from signal-processing
How it works
beamform(signals, positions, angle_degrees, [c=343], [method="nearest"]) (§ signal builtins, v0.3.0) — classic delay-and-sum: steer each channel by its own geometric delay, then average. Built ON steer_delays + the existing interp1_eval kernel interpolate_at uses, not on a private copy of either, so a hand-written interpolate_at(sig_m, t + delays[m], method) loop and this call are the same arithmetic. WHY method DEFAULTS TO "nearest" RATHER THAN interpolate_at's OWN "linear": Linear interpolation between two samples is a (crude) low-pass filter — it averages neighbours, which attenuates the broadband noise sitting between them. On the verified 5-element / 0.08 m 1 kHz / 30°-off-broadside audio case, that alone moves the measured array gain from 7.25 dB ("nearest", against 10*log10(5) = 6.99 dB of theory) to 8.58 dB — i.e. "linear" reports 1.6 dB of "array gain" that the ARRAY did not produce. A beamformer's whole purpose is to measure what the geometry buys, so the default must not quietly add denoising of its own; "linear"/"spline" remain available for a caller who wants sub-sample steering accuracy and knows to account for it. Returns a Value::Signal at the inputs' own Fs — unlike interpolate_at, which must NOT (its query times are arbitrary instants). Here every query is t_i + tau_m, the signal's own uniform axis shifted by one constant per channel, so the output is still uniformly sampled at exactly Fs; the sample rate it claims is real.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.