pyroomacoustics.utilities module

pyroomacoustics.utilities.angle_from_points(x1, x2)
pyroomacoustics.utilities.autocorr(x, p, biased=True, method='numpy')

Compute the autocorrelation for real signal x up to lag p.

Parameters:
  • x (numpy array) – Real signal in time domain.
  • p (int) – Amount of lag. When solving for LPC coefficient, this is typically the LPC order.
  • biased (bool) – Whether to return biased autocorrelation (default) or unbiased. As there are fewer samples for larger lags, the biased estimate tends to have better statistical stability under noise.
  • method (‘numpy, ‘fft’, ‘time’, pra) – Method for computing the autocorrelation: in the frequency domain with fft or pra (np.fft.rfft is used so only real signals are supported), in the time domain with time, or with numpy’s built-in function np.correlate (default). For p < log2(len(x)), the time domain approach may be more efficient.
Returns:

Autocorrelation for x up to lag p.

Return type:

numpy array

pyroomacoustics.utilities.clip(signal, high, low)

Clip a signal from above at high and from below at low.

pyroomacoustics.utilities.compare_plot(signal1, signal2, Fs, fft_size=512, norm=False, equal=False, title1=None, title2=None)
pyroomacoustics.utilities.convmtx(x, n)

Create a convolution matrix H for the vector x of size len(x) times n. Then, the result of np.dot(H,v) where v is a vector of length n is the same as np.convolve(x, v).

pyroomacoustics.utilities.create_noisy_signal(signal_fp, snr, noise_fp=None, offset=None)

Create a noisy signal of a specified SNR. :param signal_fp: File path to clean input. :type signal_fp: string :param snr: SNR in dB. :type snr: float :param noise_fp: File path to noise. Default is to use randomly generated white noise. :type noise_fp: string :param offset: Offset in seconds before starting the signal. :type offset: float

Returns:
  • numpy array – Noisy signal with specified SNR, between [-1,1] and zero mean.
  • numpy array – Clean signal, untouched from WAV file.
  • numpy array – Added noise such that specified SNR is met.
  • int – Sampling rate in Hz.
pyroomacoustics.utilities.dB(signal, power=False)
pyroomacoustics.utilities.fractional_delay(t0)

Creates a fractional delay filter using a windowed sinc function. The length of the filter is fixed by the module wide constant frac_delay_length (default 81).

Parameters:t0 (float) – The delay in fraction of sample. Typically between -1 and 1.
Returns:A fractional delay filter with specified delay.
Return type:numpy array
pyroomacoustics.utilities.fractional_delay_filter_bank(delays)

Creates a fractional delay filter bank of windowed sinc filters

Parameters:delays (1d narray) – The delays corresponding to each filter in fractional samples
Returns:An ndarray where the ith row contains the fractional delay filter corresponding to the ith delay. The number of columns of the matrix is proportional to the maximum delay.
Return type:numpy array
pyroomacoustics.utilities.goertzel(x, k)

Goertzel algorithm to compute DFT coefficients

pyroomacoustics.utilities.highpass(signal, Fs, fc=None, plot=False)

Filter out the really low frequencies, default is below 50Hz

pyroomacoustics.utilities.levinson(r, b)

Solve a system of the form Rx=b where R is hermitian toeplitz matrix and b is any vector using the generalized Levinson recursion as described in M.H. Hayes, Statistical Signal Processing and Modelling, p. 268.

Parameters:
  • r – First column of R, toeplitz hermitian matrix.
  • b – The right-hand argument. If b is a matrix, the system is solved for every column vector in b.
Returns:

The solution of the linear system Rx = b.

Return type:

numpy array

pyroomacoustics.utilities.low_pass_dirac(t0, alpha, Fs, N)

Creates a vector containing a lowpass Dirac of duration T sampled at Fs with delay t0 and attenuation alpha.

If t0 and alpha are 2D column vectors of the same size, then the function returns a matrix with each line corresponding to pair of t0/alpha values.

pyroomacoustics.utilities.lpc(x, p, biased=True)

Compute p LPC coefficients for a speech segment x.

Parameters:
  • x (numpy array) – Real signal in time domain.
  • p (int) – Amount of lag. When solving for LPC coefficient, this is typically the LPC order.
  • biased (bool) – Whether to use biased autocorrelation (default) or unbiased. As there are fewer samples for larger lags, the biased estimate tends to have better statistical stability under noise.
Returns:

p LPC coefficients.

Return type:

numpy array

pyroomacoustics.utilities.normalize(signal, bits=None)

normalize to be in a given range. The default is to normalize the maximum amplitude to be one. An optional argument allows to normalize the signal to be within the range of a given signed integer representation of bits.

pyroomacoustics.utilities.normalize_pwr(sig1, sig2)

Normalize sig1 to have the same power as sig2.

pyroomacoustics.utilities.prony(x, p, q)

Prony’s Method from Monson H. Hayes’ Statistical Signal Processing, p. 154

Parameters:
  • x – signal to model
  • p – order of denominator
  • q – order of numerator
Returns:

  • a – numerator coefficients
  • b – denominator coefficients
  • err (the squared error of approximation)

pyroomacoustics.utilities.real_spectrum(signal, axis=-1, **kwargs)
pyroomacoustics.utilities.rms(data)

Compute root mean square of input.

Parameters:data (numpy array) – Real signal in time domain.
Returns:Root mean square.
Return type:float
pyroomacoustics.utilities.shanks(x, p, q)

Shank’s Method from Monson H. Hayes’ Statistical Signal Processing, p. 154

Parameters:
  • x – signal to model
  • p – order of denominator
  • q – order of numerator
Returns:

  • a – numerator coefficients
  • b – denominator coefficients
  • err – the squared error of approximation

pyroomacoustics.utilities.spectrum(signal, Fs, N)
pyroomacoustics.utilities.time_dB(signal, Fs, bits=16)

Compute the signed dB amplitude of the oscillating signal normalized wrt the number of bits used for the signal.

pyroomacoustics.utilities.to_16b(signal)

converts float 32 bit signal (-1 to 1) to a signed 16 bits representation No clipping in performed, you are responsible to ensure signal is within the correct interval.

pyroomacoustics.utilities.to_float32(data)

Cast data (typically from WAV) to float32.

Parameters:data (numpy array) – Real signal in time domain, typically obtained from WAV file.
Returns:data as float32.
Return type:numpy array