pyroomacoustics.beamforming module

class pyroomacoustics.beamforming.Beamformer(R, fs, N=1024, Lg=None, hop=None, zpf=0, zpb=0)

Bases: pyroomacoustics.beamforming.MicrophoneArray

At some point, in some nice way, the design methods should also go here. Probably with generic arguments.

Parameters:
  • R (numpy.ndarray) – Mics positions
  • fs (int) – Sampling frequency
  • N (int, optional) – Length of FFT, i.e. number of FD beamforming weights, equally spaced. Defaults to 1024.
  • Lg (int, optional) – Length of time-domain filters. Default to N.
  • hop (int, optional) – Hop length for frequency domain processing. Default to N/2.
  • zpf (int, optional) – Front zero padding length for frequency domain processing. Default is 0.
  • zpb (int, optional) – Zero padding length for frequency domain processing. Default is 0.
far_field_weights(phi)

This method computes weight for a far field at infinity phi: direction of beam

filters_from_weights(non_causal=0.0)

Compute time-domain filters from frequency domain weights. :param non_causal: ratio of filter coefficients used for non-causal part :type non_causal: float, optional

plot(sum_ir=False, FD=True)
plot_beam_response()
plot_response_from_point(x, legend=None)
process(FD=False)
rake_delay_and_sum_weights(source, interferer=None, R_n=None, attn=True, ff=False)
rake_distortionless_filters(source, interferer, R_n, delay=0.03, epsilon=0.005)

Compute time-domain filters of a beamformer minimizing noise and interference while forcing a distortionless response towards the source.

rake_max_sinr_filters(source, interferer, R_n, epsilon=0.005, delay=0.0)

Compute the time-domain filters of SINR maximizing beamformer.

rake_max_sinr_weights(source, interferer=None, R_n=None, rcond=0.0, ff=False, attn=True)

This method computes a beamformer focusing on a number of specific sources and ignoring a number of interferers.

Parameters:
  • source (array_like) – source locations
  • interferer (array_like) – interferer locations
rake_max_udr_filters(source, interferer=None, R_n=None, delay=0.03, epsilon=0.005)

Compute directly the time-domain filters maximizing the Useful-to-Detrimental Ratio (UDR). This beamformer is not practical. It maximizes the UDR ratio in the time domain directly without imposing flat response towards the source of interest. This results in severe distortion of the desired signal.

Parameters:
  • source (pyroomacoustics.SoundSource) – the desired source
  • interferer (pyroomacoustics.SoundSource, optional) – the interfering source
  • R_n (ndarray, optional) – the noise covariance matrix, it should be (M * Lg)x(M * Lg) where M is the number of sensors and Lg the filter length
  • delay (float, optional) – the signal delay introduced by the beamformer (default 0.03 s)
  • epsilon (float) –
rake_max_udr_weights(source, interferer=None, R_n=None, ff=False, attn=True)
rake_mvdr_filters(source, interferer, R_n, delay=0.03, epsilon=0.005)

Compute the time-domain filters of the minimum variance distortionless response beamformer.

rake_one_forcing_filters(sources, interferers, R_n, epsilon=0.005)

Compute the time-domain filters of a beamformer with unit response towards multiple sources.

rake_one_forcing_weights(source, interferer=None, R_n=None, ff=False, attn=True)
rake_perceptual_filters(source, interferer=None, R_n=None, delay=0.03, d_relax=0.035, epsilon=0.005)

Compute directly the time-domain filters for a perceptually motivated beamformer. The beamformer minimizes noise and interference, but relaxes the response of the filter within the 30 ms following the delay.

response(phi_list, frequency)
response_from_point(x, frequency)
snr(source, interferer, f, R_n=None, dB=False)
steering_vector_2D(frequency, phi, dist, attn=False)
steering_vector_2D_from_point(frequency, source, attn=True, ff=False)

Creates a steering vector for a particular frequency and source :param frequency: :param source: location in cartesian coordinates :param attn: include attenuation factor if True :param ff: uses far-field distance if true

Returns:A 2x1 ndarray containing the steering vector.
udr(source, interferer, f, R_n=None, dB=False)
weights_from_filters()
pyroomacoustics.beamforming.H(A, **kwargs)

Returns the conjugate (Hermitian) transpose of a matrix.

class pyroomacoustics.beamforming.MicrophoneArray(R, fs, directivity=None)

Bases: object

Microphone array class.

M
append(locs)

Add some microphones to the array.

Parameters:locs (numpy.ndarray (2 or 3, n_mics)) – Adds n_mics microphones to the array. The coordinates are passed as a numpy.ndarray with each column containing the coordinates of a microphone.
record(signals, fs)

This simulates the recording of the signals by the microphones. In particular, if the microphones and the room simulation do not use the same sampling frequency, down/up-sampling is done here. :param signals: An ndarray with as many lines as there are microphones. :param fs: the sampling frequency of the signals.

set_directivity(directivities)

This functions sets self.directivity as a list of directivities with n_mics entries, where n_mics is the number of microphones :param directivities: single directivity for all microphones or a list of directivities for each microphone

to_wav(filename, mono=False, norm=False, bitdepth=<MagicMock id='139980181280208'>)

Save all the signals to wav files.

Parameters:
  • filename (str) – the name of the file
  • mono (bool, optional) – if true, records only the center channel floor(M / 2) (default False)
  • norm (bool, optional) – if true, normalize the signal to fit in the dynamic range (default False)
  • bitdepth (int, optional) – the format of output samples [np.int8/16/32/64 or np.float (default)]
pyroomacoustics.beamforming.circular_2D_array(center, M, phi0, radius)

Create an array of uniformly spaced circular points in 2D.

Parameters:
  • center (array_like) – The center of the array
  • M (int) – The number of points
  • phi0 (float) – The counterclockwise rotation of the first element in the array (from the x-axis)
  • radius (float) – The radius of the array
Returns:

The array of points

Return type:

ndarray (2, M)

pyroomacoustics.beamforming.circular_microphone_array_xyplane(center, M, phi0, radius, fs, directivity=None, ax=None)

Create a microphone array with directivities pointing outwards (if provided).

Parameters:
  • center (array_like) – The center of the microphone array. 2D or 3D.
  • M (int) – The number of microphones.
  • phi0 (float) – The counterclockwise rotation (in degrees) of the first element in the microphone array (from the x-axis).
  • radius (float) – The radius of the microphone array.
  • fs (int) – The sampling frequency.
  • directivity (Directivity object, optional.) – Directivity pattern for each microphone which will be re-oriented to face outward. If not provided, microphones are omnidirectional.
  • ax (axes object, optional) – Axes on which to plot microphone array with its directivities.
Returns:

Return type:

MicrophoneArray object

pyroomacoustics.beamforming.distance(x, y)

Computes the distance matrix E. E[i,j] = sqrt(sum((x[:,i]-y[:,j])**2)). x and y are DxN ndarray containing N D-dimensional vectors.

pyroomacoustics.beamforming.fir_approximation_ls(weights, T, n1, n2)
pyroomacoustics.beamforming.linear_2D_array(center, M, phi, d)

Creates an array of uniformly spaced linear points in 2D :param center: The center of the array :type center: array_like :param M: The number of points :type M: int :param phi: The counterclockwise rotation of the array (from the x-axis) :type phi: float :param d: The distance between neighboring points :type d: float

Returns:The array of points
Return type:ndarray (2, M)
pyroomacoustics.beamforming.mdot(*args)

Left-to-right associative matrix multiplication of multiple 2D ndarrays.

pyroomacoustics.beamforming.poisson_2D_array(center, M, d)

Create array of 2D positions drawn from Poisson process. :param center: The center of the array :type center: array_like :param M: The number of points in the first dimension :type M: int :param M: The number of points in the second dimension :type M: int :param phi: The counterclockwise rotation of the array (from the x-axis) :type phi: float :param d: The distance between neighboring points :type d: float

Returns:The array of points
Return type:ndarray (2, M * N)
pyroomacoustics.beamforming.spiral_2D_array(center, M, radius=1.0, divi=3, angle=None)

Generate an array of points placed on a spiral :param center: location of the center of the array :type center: array_like :param M: number of microphones :type M: int :param radius: microphones are contained within a cirle of this radius (default 1) :type radius: float :param divi: number of rotations of the spiral (default 3) :type divi: int :param angle: the angle offset of the spiral (default random) :type angle: float

Returns:The array of points
Return type:ndarray (2, M * N)
pyroomacoustics.beamforming.square_2D_array(center, M, N, phi, d)

Creates an array of uniformly spaced grid points in 2D :param center: The center of the array :type center: array_like :param M: The number of points in the first dimension :type M: int :param M: The number of points in the second dimension :type M: int :param phi: The counterclockwise rotation of the array (from the x-axis) :type phi: float :param d: The distance between neighboring points :type d: float

Returns:The array of points
Return type:ndarray (2, M * N)
pyroomacoustics.beamforming.sumcols(A)

Sums the columns of a matrix (np.array). The output is a 2D np.array of dimensions M x 1.

pyroomacoustics.beamforming.unit_vec2D(phi)