API Reference

This section covers the core classes and functions of the robot.

Audio Processing

This class handles all audio processing and DOA estimation.

class AudioProcessor.AudioProcessor(fs, channels, radius, shift, block_size, analyzed_buffer_time, data, args, trigger_level, critical_level, mic_spacing, ref, highpass_freq, lowpass_freq, theta_das, N_peaks, soundcard_index, subtype, interp_sensitivity, tgtmic_relevant_freqs, filename, rec_samplerate, sos)

AudioProcessor class for real-time audio signal processing and analysis.

Parameters

fsint

Sampling frequency in Hz.

channelsint

Number of audio channels.

block_sizeint

Size of each audio block in samples.

analyzed_buffer_timefloat

Duration of buffer to analyze in seconds.

datanp.ndarray

Audio data array.

argsobject

Command-line arguments or configuration object.

trigger_levelfloat

Sound pressure level (dB SPL) threshold to trigger detection.

critical_levelfloat

Critical sound pressure level (dB SPL) for avoiding collisions.

mic_spacingfloat

Physical spacing between microphones in meters.

refint

Index of the reference microphone channel.

highpass_freqfloat

High-pass filter frequency in Hz.

lowpass_freqfloat

Low-pass filter frequency in Hz.

theta_dasnp.ndarray

Array of angles for beamforming in radians.

N_peaksint

Number of peaks to detect in the spatial response.

soundcard_indexint

Index of the soundcard device to use.

interp_sensitivitynp.ndarray

Frequency-wise sensitivity interpolation values.

tgtmic_relevant_freqsnp.ndarray

Indices of relevant frequency bands for target microphone.

filenamestr

Path to the output audio file for recording.

rec_samplerateint

Sample rate for recording in Hz.

sosnp.ndarray

Second-order sections coefficients for the IIR filter.

Attributes

shared_audio_queuequeue.Queue

Thread-safe queue for audio buffer exchange.

ts_queuequeue.Queue

Thread-safe queue for timestamp exchange.

current_frameint

Current frame position in playback.

buffernp.ndarray

Current audio buffer with shape (block_size, channels).

callback_in(indata, frames, time, status)

Process incoming audio data from the audio stream.

Parameters

indatandarray

Audio data buffer containing the input samples for this block.

framesint

Number of frames (samples) in the current audio block.

timeCData

Time information for the audio block (from PortAudio).

statusCallbackFlags

Status flags indicating any errors or special conditions (e.g., input overflow, buffer underflow).

Attributes Used

self.shared_audio_queuequeue.Queue

Thread-safe queue for storing incoming audio buffers.

self.stacknumpy.ndarray

LIFO stack to store incoming audio buffers for processing.

Notes

Execution time is approximately 0.00013 seconds per operation.

callback_out(outdata, frames, time, status)

Audio output callback for streaming audio data.

Parameters

outdatanumpy.ndarray

Output buffer where audio samples should be written. Shape is (frames, channels).

framesint

Number of audio frames requested by the audio stream.

timeCData

Time information structure containing current playback time and hardware time.

statussd.CallbackFlags

Status flags indicating any issues with the audio stream (e.g., underflow). If non-zero, indicates a problem occurred.

Attributes Used

self.datanumpy.ndarray

Audio data array to be played back.

self.current_frameint

Current position in the audio data array for playback.

Raises

sd.CallbackStop

Raised when all audio data has been played to signal the audio stream to stop.

continuos_recording()

Continuously records audio from the specified sound device and writes it to a file.

Attributes Used

self.filenamestr

Path to the output audio file where the recording will be saved.

self.rec_samplerateint

Sample rate (Hz) for writing to the output file.

self.channelsint

Number of audio channels to record.

self.fsint

Sample rate (Hz) for input stream acquisition.

self.soundcard_indexint

Index of the sound device to record from.

self.callback_incallable

Callback function for handling input stream data.

self.block_sizeint

Size of audio blocks processed per callback.

self.shared_audio_queuequeue.Queue

Thread-safe queue containing audio buffers from the input stream.

self.bufferndarray

Current audio buffer retrieved from the queue.

input_stream()

Continuously captures audio from the specified sound device.

Attributes Used

self.channelsint

Number of audio channels to record.

self.fsint

Sample rate (Hz) for input stream acquisition.

self.soundcard_indexint

Index of the sound device to record from.

self.callback_incallable

Callback function for handling input stream data.

self.block_sizeint

Size of audio blocks processed per callback.

self.shared_audio_queuequeue.Queue

Thread-safe queue containing audio buffers from the input stream.

self.bufferndarray

Current audio buffer retrieved from the queue.

pop_stack_chunk()

Pops a variable LIFO chunk from the stack based on a time duration.

update_CC()

Calculates DOA using Cross-Correlation (CC) method.

The processing pipeline includes: 1. Applies a highpass filter using second-order sections to the input buffer 2. Calculates frequency-wise RMS values for the reference channel 3. Normalizes by mic sensitivity (from loaded calibration data) 4. Computes total RMS across relevant frequency bands 5. Converts to dB SPL level 6. Calculates multi-channel time delays relative to the reference channel 7. Estimates average angle from the calculated delays

Attributes Used

self.buffernumpy.ndarray

Input audio buffer containing the latest audio samples.

self.sosnumpy.ndarray

Second-order sections for the highpass filter.

self.fsint

Sampling frequency of the audio data.

self.refint

Index of the reference microphone channel.

self.interp_sensitivitynumpy.ndarray

Interpolated sensitivity values for frequency normalization.

self.tgtmic_relevant_freqslist or numpy.ndarray

Indices of relevant frequency bands for the target microphone.

self.trigger_levelfloat

Threshold level for triggering angle calculation.

self.critical_levelfloat

Critical threshold level for angle calculation.

self.channelsint

Number of audio channels.

self.mic_spacingfloat

Spacing between microphones for delay calculation.

Returns

tuple

A tuple containing: - avar_theta : float or None

The average angle (in degrees) of the sound source direction. Returns None if the sound level is below both trigger and critical levels.

  • dB_SPL_levelfloat

    The sound pressure level in dB SPL calculated from the frequency-weighted RMS across relevant frequency bands for the reference channel.

update_das()

Calculates DOA using Delay And Sum (DAS) method.

The processing pipeline includes: 1. High-pass filtering of the input buffer 2. Max detection using Hilbert transform on the reference channel 3. Full signal trimming around the maximum envelope peak 4. Calculates frequency-wise RMS values for the reference channel 5. Normalizes by mic sensitivity (from loaded calibration data) 6. Computes total RMS across relevant frequency bands 7. Converts to dB SPL level 8. DAS beamforming (only in the filtered bandwidth) for spatial response and direction estimation 9. Peak detection and angle extraction

Attributes Used

self.buffernumpy.ndarray

Input audio buffer containing the latest audio samples.

self.fsint

Sampling frequency of the audio data.

self.refint

Index of the reference microphone channel.

self.sosnumpy.ndarray

Second-order sections for the highpass filter.

self.analyzed_buffer_timefloat

Duration (in seconds) of the buffer to analyze.

self.interp_sensitivitynumpy.ndarray

Interpolated sensitivity values for frequency normalization.

self.tgtmic_relevant_freqslist or numpy.ndarray

Indices of relevant frequency bands for the target microphone.

self.trigger_levelfloat

Threshold level for triggering angle calculation.

self.critical_levelfloat

Critical threshold level for angle calculation.

self.channelsint

Number of audio channels.

self.mic_spacingfloat

Spacing between microphones for delay calculation.

self.highpass_freqfloat

High-pass filter cutoff frequency.

self.lowpass_freqfloat

Low-pass filter cutoff frequency.

self.theta_dasnumpy.ndarray

Array of angles (in degrees) for DAS beamforming.

self.N_peaksint

Number of peaks to detect in the spatial response.

Returns

tuple
If the detected dB SPL level exceeds the trigger level or critical level:
(float, float): A tuple containing:
  • peak_angle (float): The angle (in degrees) of the strongest detected acoustic source

  • dB_SPL_level (float): The sound pressure level in dB SPL of the detected event

Otherwise:
(None, float): A tuple containing:
  • None: No direction detected

  • dB_SPL_level (float): The sound pressure level in dB SPL

Notes

  • The trimming window of self.analyzed_buffer_time seconds is centered on the maximum envelope amplitude

  • The DAS beamforming is performed only within the specified highpass and lowpass bandwidth

  • Only the top N peaks (defined by N_peaks) sorted by their height are considered for direction estimation

update_das_UCA()

Calculates DOA using Delay And Sum (DAS) method.

The processing pipeline includes: 1. High-pass filtering of the input buffer 2. Max detection using Hilbert transform on the reference channel 3. Full signal trimming around the maximum envelope peak 4. Calculates frequency-wise RMS values for the reference channel 5. Normalizes by mic sensitivity (from loaded calibration data) 6. Computes total RMS across relevant frequency bands 7. Converts to dB SPL level 8. DAS beamforming (only in the filtered bandwidth) for spatial response and direction estimation 9. Peak detection and angle extraction

Attributes Used

self.buffernumpy.ndarray

Input audio buffer containing the latest audio samples.

self.fsint

Sampling frequency of the audio data.

self.refint

Index of the reference microphone channel.

self.sosnumpy.ndarray

Second-order sections for the highpass filter.

self.analyzed_buffer_timefloat

Duration (in seconds) of the buffer to analyze.

self.interp_sensitivitynumpy.ndarray

Interpolated sensitivity values for frequency normalization.

self.tgtmic_relevant_freqslist or numpy.ndarray

Indices of relevant frequency bands for the target microphone.

self.trigger_levelfloat

Threshold level for triggering angle calculation.

self.critical_levelfloat

Critical threshold level for angle calculation.

self.channelsint

Number of audio channels.

self.mic_spacingfloat

Spacing between microphones for delay calculation.

self.highpass_freqfloat

High-pass filter cutoff frequency.

self.lowpass_freqfloat

Low-pass filter cutoff frequency.

self.theta_dasnumpy.ndarray

Array of angles (in degrees) for DAS beamforming.

self.N_peaksint

Number of peaks to detect in the spatial response.

Returns

tuple
If the detected dB SPL level exceeds the trigger level or critical level:
(float, float): A tuple containing:
  • peak_angle (float): The angle (in degrees) of the strongest detected acoustic source

  • dB_SPL_level (float): The sound pressure level in dB SPL of the detected event

Otherwise:
(None, float): A tuple containing:
  • None: No direction detected

  • dB_SPL_level (float): The sound pressure level in dB SPL

Notes

  • The trimming window of self.analyzed_buffer_time seconds is centered on the maximum envelope amplitude

  • The DAS beamforming is performed only within the specified highpass and lowpass bandwidth

  • Only the top N peaks (defined by N_peaks) sorted by their height are considered for direction estimation

Robot Movement

This class handles all physical actions of the robot.

class RobotMove.RobotMove(forward_speed, turn_speed, left_sensor_threshold, right_sensor_threshold, critical_level, trigger_level, ground_sensors_bool=True)

This class manages robot motor control, LED indicators, ground sensors, and implements various behavioral modes

Parameters

forward_speedint

Target speed for forward motor movement.

turn_speedint

Target speed for rotational motor movement.

left_sensor_thresholdint

Threshold value for left ground sensor to detect white lines.

right_sensor_thresholdint

Threshold value for right ground sensor to detect white lines.

trigger_levelfloat

Sound pressure level (dB SPL) threshold to trigger detection.

critical_levelfloat

Critical sound pressure level (dB SPL) for avoiding collisions.

ground_sensors_boolbool, optional

If True, initializes and monitors ground sensor values at start.

Attributes

runningbool

Flag indicating if the robot’s main loop is running.

turning_angleint

Default fixed turning angle in degrees (10 degrees).

stop_boolbool

Flag indicating if robot should stop motion.

robotobject

Thymio robot instance for motor and sensor control.

angle_to_time(angle, speed)

Calculate the time needed to turn the robot by a specified angle.

Parameters

anglefloat

The rotation angle in degrees.

speedfloat

The rotational speed parameter.

Returns

float

The time required to turn by the specified angle, in seconds.

Notes

A = 612.33 and B = -0.94 are empirically determined constants.

attraction_only()

Attraction-based movement control loop for the robot.

Fixed angle attraction by self.turning_angle degrees turning. No reaction to critical level.

Attributes Used

self.runningbool

Flag indicating if the robot’s main loop is running.

trigger_levelfloat

Sound pressure level (dB SPL) threshold to trigger detection.

critical_levelfloat

Critical sound pressure level (dB SPL) for avoiding collisions.

angle_queuequeue.Queue

Inter-thread queue for sharing detected angles from AudioProcessor.

level_queuequeue.Queue

Inter-thread queue for sharing SPL levels from AudioProcessor.

self.robotobject

Thymio robot instance for motor and sensor control.

Notes

  • The robot’s yellow LEDs indicate DOA direction in 22 degrees steps

  • When no angle data is available, Top and bottom LEDs illuminate green and the robot moves forward

  • Top and bottom LEDs turn blue when sound is above trigger level and red at critical level

audio_move()

Execute attraction and repulsion-based movement behaviour for the robot.

Attributes Used

self.runningbool

Flag indicating if the robot’s main loop is running.

critical_levelfloat

Critical sound pressure level (dB SPL) for avoiding collisions.

trigger_levelfloat

Sound pressure level (dB SPL) threshold to trigger detection.

angle_queuequeue.Queue

Inter-thread queue for sharing detected angles from AudioProcessor.

level_queuequeue.Queue

Inter-thread queue for sharing SPL levels from AudioProcessor.

self.robotobject

Thymio robot instance for motor and sensor control.

self.turning_angleint

Fixed turning angle in degrees.

Notes

  • The robot’s circular yellow LEDs indicate DOA direction in 22 degrees steps

  • When no angle data is available, Top and bottom LEDs illuminate green and the robot moves forward

  • Top and bottom LEDs turn blue when sound is above trigger level and red at critical level

audio_move_360()

Execute attraction and repulsion-based movement behaviour for the robot. Based on given angles over 360 degrees.

Attributes Used

self.runningbool

Flag indicating if the robot’s main loop is running.

critical_levelfloat

Critical sound pressure level (dB SPL) for avoiding collisions.

trigger_levelfloat

Sound pressure level (dB SPL) threshold to trigger detection.

angle_queuequeue.Queue

Inter-thread queue for sharing detected angles from AudioProcessor.

level_queuequeue.Queue

Inter-thread queue for sharing SPL levels from AudioProcessor.

self.robotobject

Thymio robot instance for motor and sensor control.

self.turning_angleint

Fixed turning angle in degrees.

Notes

  • The robot’s circular yellow LEDs indicate DOA direction in 22 degrees steps

  • When no angle data is available, Top and bottom LEDs illuminate green and the robot moves forward

  • Top and bottom LEDs turn blue when sound is above trigger level and red at critical level

avoid_white_line()

Avoid white line detection and response.

If both ground sensors detect a white line, the robot performs a random turn. If only the left sensor detects a white line, the robot turns right. If only the right sensor detects a white line, the robot turns left.

Attributes Used

self.left_sensor_thresholdint

Threshold value for left ground sensor to detect white lines.

self.right_sensor_thresholdint

Threshold value for right ground sensor to detect white lines.

self.robotobject

Thymio robot instance for motor and sensor control.

self.stop_boolbool

Set to True when stop condition is met

check_stop_all_motion()

Check if the robot should stop all motion based on ground proximity sensors.

Attributes Used

self.robotobject

Thymio robot instance for motor and sensor control.

Returns

bool

True if the robot is lifted (proximity delta < 10 on either sensor), False if robot object is None (after calling stop()).

move_back()

Move the robot backward when an obstacle is detected in front.

Attributes Used

self.robotobject

Thymio robot instance for motor and sensor control.

move_forward()

Move the robot forward at the specified forward speed.

Attributes Used

self.forward_speedint

Target speed for forward motor movement.

self.robotobject

Thymio robot instance for motor and sensor control.

Notes

-Top and bottom LEDs illuminate green and the robot moves forward

random_turn(angle)

Perform a random movement of the robot in a random direction.

Parameters

anglefloat

The rotation angle in degrees

Attributes Used

self.robotobject

Thymio robot instance for motor and sensor control.

self.stop_boolbool

Set to True when stop condition is met

repulsion_only()

Execute repulsion-based movement behaviour for the robot.

Fixed angle repulsion by self.turning_angle degrees turning.

Attributes Used

self.runningbool

Flag indicating if the robot’s main loop is running.

critical_levelfloat

Critical sound pressure level (dB SPL) for avoiding collisions.

angle_queuequeue.Queue

Inter-thread queue for sharing detected angles from AudioProcessor.

level_queuequeue.Queue

Inter-thread queue for sharing SPL levels from AudioProcessor.

self.robotobject

Thymio robot instance for motor and sensor control.

self.turning_angleint

Fixed turning angle in degrees.

Notes

  • The robot’s circular yellow LEDs indicate DOA direction in 22 degrees steps

  • When no angle data is available, Top and bottom LEDs illuminate green and the robot moves forward

  • Top and bottom LEDs turn blue when sound is above trigger level and red at critical level

rotate_left(angle)

Rotate the robot to the left by a specified angle.

Parameters

anglefloat

The angle in degrees to rotate the robot.

Attributes Used

self.robotobject

Thymio robot instance for motor and sensor control.

self.turn_speedint

Target speed for rotational motor movement.

Notes

  • Gives priority to the line detection to avoid the robot exiting the arena

rotate_right(angle)

Rotate the robot to the right by a specified angle.

Parameters

anglefloat

The angle in degrees to rotate the robot.

Attributes Used

self.robotobject

Thymio robot instance for motor and sensor control.

self.turn_speedint

Target speed for rotational motor movement.

Notes

  • Gives priority to the line detection to avoid the robot exiting the arena

smooth_rotate_left(angle)

Rotate the robot to the left by a specified angle but keeps some forward speed while turning.

Parameters

anglefloat

The angle in degrees to rotate the robot to the right.

Attributes Used

self.robotobject

Thymio robot instance for motor and sensor control.

self.turn_speedint

Target speed for rotational motor movement.

Notes

  • Gives priority to the line detection to avoid the robot exiting the arena

smooth_rotate_right(angle)

Rotate the robot to the right by a specified angle but keeps some forward speed while turning.

Parameters

anglefloat

The angle in degrees to rotate the robot to the right.

Attributes Used

self.robotobject

Thymio robot instance for motor and sensor control.

self.turn_speedint

Target speed for rotational motor movement.

Notes

  • Gives priority to the line detection to avoid the robot exiting the arena

stop()

Stop all robot movement and turn off all LEDs.

This method stops the robot by setting both motor targets to zero and disables all LED indicators by setting them to off (black color).

Utilities module

This module contains all the functions for DOA estimation and audio processing.

Created: 2025-12-16 Author: Alberto Doimo email: alberto.doimo@uni-konstanz.de

Description Utility functions used to run SonoRo_swarm.py

utilities.avar_angle(delay_set, nchannels, mic_spacing, ref_channel)

Calculate the mean angle of arrival to the array with respect to reference channel.

Parameters

delay_setarray-like

The time delay between signals

nchannelsint

Number of mics in the array

mic_spacingfloat

Inter-distance between the mics

ref_channelint

Reference channel

Returns

avar_thetafloat

The mean angle of arrival to the array in radians

utilities.bandpass(rec_buffer, highpass_freq, lowpass_freq, fs)

Applies a bandpass filter to the input buffer.

Parameters

rec_bufferndarray

Input buffer to be filtered.

highpass_freqfloat

Highpass frequency in Hz.

lowpass_freqfloat

Lowpass frequency in Hz.

fsfloat

Sampling frequency in Hz.

Returns

rec_buffer_bpndarray

Bandpass filtered buffer with the same shape as the input.

utilities.calc_dBrms(one_channel_buffer)

Calculate the dB RMS of a single channel buffer.

Parameters

one_channel_buffer1D np.array.

Single channel buffer.

Returns

dB_rmsfloat.

dB RMS value of the buffer.

utilities.calc_delay(two_ch, fs)

Calculate the delay between two channels using cross-correlation.

Parameters

two_ch(Nsamples, 2) np.array

Input audio buffer with 2 channels

fsfloat

Sampling frequency in Hz

Returns

delayfloat

The time-delay in seconds between the arriving audio across the channels

utilities.calc_multich_delays(multich_audio, ref_sig, fs, ref_channel)

Calculate delays between channels using GCC-PHAT with a reference signal.

Parameters

multich_audio(Nsamples, Nchannels) np.ndarray

Multichannel audio signal

ref_sig(Nsamples,) np.ndarray

Reference signal

fsfloat

Sampling frequency in Hz

ref_channelint

Reference channel index

Returns

delay_setnp.ndarray

Array of time delays in seconds for each channel relative to reference

utilities.calc_native_freqwise_rms(X, fs)

Converts the FFT spectrum into a band-wise rms output. The frequency-resolution of the spectrum/audio size decides the frequency resolution in general.

Parameters

Xnp.array

Audio

fsint

Sampling rate in Hz

Returns

fftfreqs, freqwise_rmsnp.array

fftfreqs holds the frequency bins from the RFFT freqwise_rms is the RMS value of each frequency bin.

utilities.check_if_above_level(mic_inputs, trigger_level, critical_level)

Checks if the dB rms level of the input recording buffer is above threshold. If any of the microphones are above the given level then recording is initiated.

Parameters

mic_inputs(Nsamples, Nchannels) np.ndarray

Data from soundcard

trigger_levelfloat

If the input data buffer has a dB rms >= this value then True will be returned

critical_levelfloat

Critical level threshold

Returns

trigger_boolbool

True if the buffer dB rms is >= the trigger_level

critical_boolbool

True if the buffer dB rms is >= the critical_level

dBrms_channelnp.ndarray

dB RMS values for each channel

utilities.das_filter(y, fs, nch, d, bw, theta, c=343, wlen=64, show=False)

Simple multiband Delay and Sum spatial filter implementation.

Parameters

y(Nsamples, Nchannels) np.ndarray

Mic array signals

fsfloat

Sampling rate in Hz

nchint

Number of mics in the array

dfloat

Mic spacing in meters

bwtuple

Frequency band (low_freq, high_freq) in Hz

thetanp.ndarray

Angle vector in degrees

cfloat, optional

Sound speed in m/s. Defaults to 343

wlenint, optional

Window length for STFT. Defaults to 64

showbool, optional

Plot the pseudospectrum for each band. Defaults to False

Returns

thetanp.ndarray

Angle axis in degrees

mag_pnp.ndarray

Magnitude of average spatial energy distribution estimation across bands

f_spec_axisnp.ndarray

Frequency axis from STFT

spectrumnp.ndarray

STFT spectrum

bandsnp.ndarray

Frequency bands within the specified bandwidth

utilities.das_filter_CA(y, fs, nch, r, shift, bw, theta, c=343, wlen=64, show=False)

Multiband Delay and Sum for a Uniform Circular Array (UCA).

Parameters: r : float

Radius of the circular array in meters.

thetanp.ndarray

Scanning angles (azimuth) in degrees [0, 360].

utilities.das_filter_UCA(y, fs, nch, r, shift, bw, theta, c=343, wlen=64, show=False)

Multiband Delay and Sum for a Uniform Circular Array (UCA).

Parameters: r : float

Radius of the circular array in meters.

thetanp.ndarray

Scanning angles (azimuth) in degrees [0, 360].

utilities.detect_peaks(filtered_output, sample_rate, prominence, distance)

Detect peaks in the matched filter output.

Parameters

filtered_outputnp.ndarray

The output of the matched filter.

sample_rateint

The sample rate of the audio signal.

prominencefloat

Minimum prominence of peaks to be detected.

distancefloat

Minimum distance between peaks in seconds.

Returns

peaksnp.ndarray

Indices of detected peaks in the filtered output.

utilities.dmas_filter_UCA(y, fs, nch, r, shift, bw, theta, c=343, wlen=64, show=False)

Multiband Delay Multiply and Sum (DMAS) for a Uniform Circular Array (UCA).

Parameters: r : float

Radius of the circular array in meters.

thetanp.ndarray

Scanning angles (azimuth) in degrees [0, 360].

utilities.gcc_phat(sig, refsig, fs)

Compute the cross-correlation between two signals using GCC-PHAT.

Parameters

sig(Nsamples, Nchannels) np.ndarray

First signal

refsig(Nsamples,) np.ndarray

Reference signal

fsfloat

Sampling frequency in Hz

Returns

float

Time delay in seconds between the two signals

utilities.get_card(device_list, device_name)

Get the index of the ASIO card in the device list.

Parameters

device_listlist

List of devices (usually from sd.query_devices())

Returns

int or None

Index of the MCHStreamer card in the device list, or None if not found

utilities.get_rms_from_fft(freqs, spectrum, **kwargs)

Use Parseval’s theorem to get the RMS level of each frequency component This only works for RFFT spectrums!!!

Parameters

freqs : (Nfreqs,) np.array >0 values spectrum : (Nfreqs,) np.array (complex) freq_range : (2,) array-like

Min and max values

Returns

root_mean_squaredfloat

The RMS of the signal within the min-max frequency range

utilities.higher_order_dmas_UCA(y, fs, nch, r, shift, bw, theta, c=343, wlen=64, order=3, apply_cf=True, show=False)

Multiband Higher-Order Delay Multiply and Sum (p-DMAS) for a Uniform Circular Array, with optional Standard Coherence Factor (CF) weighting.

Parameters: r : float

Radius of the circular array in meters.

thetanp.ndarray

Scanning angles (azimuth) in degrees [0, 360].

orderfloat, optional

The dimensionality order (p). order=2 is standard DMAS. order > 2 is higher-order.

apply_cfbool, optional

Whether to calculate and apply the Standard Coherence Factor (CF). Defaults to True.

utilities.interpolate_freq_response(mic_freq_response, new_freqs)

Parameters

mic_freq_responsetuple/list

A tuple/list with two entries: (centrefreqs, centrefreq_RMS).

new_freqslist/array-like

A set of new centre frequencies that need to be interpolated to.

Returns

tgtmicsens_interp :

Note

Any frequencies outside of the calibration range will automatically be assigned to the lowest sensitivity values measured in the input centrefreqs

utilities.matched_filter(recording, chirp_template)

Apply a matched filter to the signal using the provided template.

Parameters

recordingnp.ndarray

The audio signal to be filtered.

chirp_templatenp.ndarray

The chirp template used for filtering.

Returns

np.ndarray

The filtered output, which is the envelope of the matched filter response.

utilities.music(y, fs, nch, d, bw, theta=array([-90., -87.5, -85., -82.5, -80., -77.5, -75., -72.5, -70., -67.5, -65., -62.5, -60., -57.5, -55., -52.5, -50., -47.5, -45., -42.5, -40., -37.5, -35., -32.5, -30., -27.5, -25., -22.5, -20., -17.5, -15., -12.5, -10., -7.5, -5., -2.5, 0., 2.5, 5., 7.5, 10., 12.5, 15., 17.5, 20., 22.5, 25., 27.5, 30., 32.5, 35., 37.5, 40., 42.5, 45., 47.5, 50., 52.5, 55., 57.5, 60., 62.5, 65., 67.5, 70., 72.5, 75., 77.5, 80., 82.5, 85., 87.5, 90.]), c=343, wlen=64, ns=1, show=False)

Simple multiband MUltiple SIgnal Classification spatial filter implementation.

Parameters

y(Nsamples, Nchannels) np.ndarray

Mic array signals

fsfloat

Sampling rate in Hz

nchint

Number of mics in the array

dfloat

Mic spacing in meters

bwtuple

Frequency band (low_freq, high_freq) in Hz

thetanp.ndarray, optional

Angle axis in degrees. Defaults to 2.5[deg] resolution

cfloat, optional

Sound speed in m/s. Defaults to 343

wlenint, optional

Window length for STFT. Defaults to 64

nsint, optional

Expected number of sources. Defaults to 1

showbool, optional

Plot the pseudospectrum for each band. Defaults to False

Returns

thetanp.ndarray

Angle axis in degrees

mag_pnp.ndarray

Magnitude of spatial energy distribution estimate, averaged across bands

utilities.pascal_to_dbspl(X)

Converts Pascals to dB SPL re 20 uPa

utilities.pow_two_pad_and_window(vec, fs, show=True)

Pad a vector with zeros to the next power of two and apply a Tukey window.

Parameters

vecnp.ndarray

Input vector

fsfloat

Sampling rate in Hz

showbool, optional

If True, plot the windowed vector and its spectrogram (default: True)

Returns

padded_windowed_vecnp.ndarray

Padded and windowed vector normalized by its maximum value

utilities.rms(X)

Calculates the root mean square of the input signal X

Parameters

Xnp.array

Input signal

Returns

rms_value :

The RMS value of the input signal