Пример #1
0
def test_tdoa_delay_frac_phat():

    N = [14, 200, 70, 40, 28]
    M = [3, 78, 12, 10, 12]

    # important to start at zero and only use positive
    # delays due to fractional_delay_filter_bank function
    # subtracting minimum delay
    delays = [0.0, 0.3, 3.5, 10.1, 5.7]

    zero_delay_filter = pra.fractional_delay(0.0)
    frac_filters = pra.fractional_delay_filter_bank(delays)

    # test without explicit sampling frequency
    for n, m, tau, fil in zip(N, M, delays, frac_filters):

        pulse = np.random.randn(m)
        signal = np.zeros(n)
        signal[:m] = pulse
        x1 = fftconvolve(zero_delay_filter, signal)
        x2 = fftconvolve(signal, fil)

        d1 = pra.tdoa(x1, x2, interp=20, phat=True)
        d2 = pra.tdoa(x2, x1, interp=20, phat=True)

        assert np.allclose(d1, -tau)
        assert np.allclose(d2, tau)

        fs = 100
        d3 = pra.tdoa(x1, x2, interp=20, phat=True, fs=fs)
        d4 = pra.tdoa(x2, x1, interp=20, phat=True, fs=fs)

        assert np.allclose(d3, -tau / fs)
        assert np.allclose(d4, tau / fs)
Пример #2
0
def make_filters(n_mics):
    # Location of original source
    azimuth = 61. / 180. * np.pi  # 60 degrees

    # algorithms parameters
    c = 343.
    fs = 16000

    # circular microphone array, 6 mics, radius 15 cm
    R = pra.circular_2D_array([0, 0], n_mics, 0., 0.15)

    # propagation filter bank
    propagation_vector = -np.array([np.cos(azimuth), np.sin(azimuth)])
    delays = np.dot(R.T, propagation_vector) / c * fs  # in fractional samples
    filter_bank = pra.fractional_delay_filter_bank(delays)

    return filter_bank
Пример #3
0
azimuth = 61.0 / 180.0 * np.pi  # 60 degrees
tol = 0.3 / 180.0 * np.pi  # 0.3 degrees tolerance for the test

# algorithms parameters
c = 343.0
fs = 16000
nfft = 256
freq_bins = np.arange(5, 60)

# circular microphone array, 12 mics, radius 15 cm
R = pra.circular_2D_array([0, 0], 12, 0.0, 0.15)

# propagation filter bank
propagation_vector = -np.array([np.cos(azimuth), np.sin(azimuth)])
delays = np.dot(R.T, propagation_vector) / c * fs  # in fractional samples
filter_bank = pra.fractional_delay_filter_bank(delays)

# we use a white noise signal for the source
x = np.random.randn((nfft // 2 + 1) * nfft)

# convolve the source signal with the fractional delay filters
# to get the microphone input signals
mic_signals = np.array(
    [fftconvolve(x, filter, mode="same") for filter in filter_bank])
X = pra.transform.stft.analysis(mic_signals.T,
                                nfft,
                                nfft // 2,
                                win=np.hanning(nfft))
X = np.swapaxes(X, 2, 0)