def test_xcorr(): x = array([1, 2, 3, 4, 5]) corr, l = xcorr(x, x, maxlags=4, norm='coeff') corr_coeff = array([ 0.09090909, 0.25454545, 0.47272727, 0.72727273, 1., 0.72727273, 0.47272727, 0.25454545, 0.09090909 ]) assert_array_almost_equal(corr, corr_coeff) corr, l = xcorr(x, x, maxlags=4, norm='biased') corr_biased = array([1., 2.8, 5.2, 8., 11., 8., 5.2, 2.8, 1.]) assert_array_almost_equal(corr, corr_biased) corr, l = xcorr(x, x, maxlags=4, norm='unbiased') corr_unbiased = array( [5., 7., 8.66666667, 10., 11., 10., 8.66666667, 7., 5.]) assert_array_almost_equal(corr, corr_unbiased) corr, l = xcorr(x, x, maxlags=4, norm=None) corr_none = array([5, 14, 26, 40, 55, 40, 26, 14, 5]) assert_array_almost_equal(corr, corr_none) # check default behaviour of maxlags corr1, l = xcorr(x, x) corr2, l = xcorr(x, x, maxlags=4) assert_array_almost_equal(corr1, corr2) # check default behaviour of maxlags corr1, l = xcorr(x) corr2, l = xcorr(x, x) assert_array_almost_equal(corr1, corr2)
def test_xcorr(): x = array([1,2,3,4,5]) corr,l = xcorr(x, x, maxlags=4, norm='coeff') corr_coeff = array([ 0.09090909, 0.25454545, 0.47272727, 0.72727273, 1. , 0.72727273, 0.47272727, 0.25454545, 0.09090909]) assert_array_almost_equal(corr, corr_coeff) corr,l = xcorr(x, x, maxlags=4, norm='biased') corr_biased = array([ 1. , 2.8, 5.2, 8. , 11. , 8. , 5.2, 2.8, 1. ]) assert_array_almost_equal(corr, corr_biased) corr,l = xcorr(x, x, maxlags=4, norm='unbiased') corr_unbiased = array([ 5. , 7. , 8.66666667, 10. , 11. , 10. , 8.66666667, 7. , 5. ]) assert_array_almost_equal(corr, corr_unbiased) corr,l = xcorr(x, x, maxlags=4, norm=None) corr_none = array([ 5, 14, 26, 40, 55, 40, 26, 14, 5]) assert_array_almost_equal(corr, corr_none) # check default behaviour of maxlags corr1,l = xcorr(x, x) corr2,l = xcorr(x, x, maxlags=4) assert_array_almost_equal(corr1, corr2) # check default behaviour of maxlags corr1,l = xcorr(x) corr2,l = xcorr(x, x) assert_array_almost_equal(corr1, corr2)
def _test_xcorr_versus_CORRELATION_imag_data(): from spectrum.tools import twosided as func x = array([1, 2, 3, 4, 5 + 1.j]) for norm in ['biased', 'unbiased', 'coeff', None]: corr1, l = xcorr(x, x, maxlags=4, norm=norm) corr2 = CORRELATION(x, x, maxlags=4, norm=norm) assert_array_almost_equal(corr1, func(corr2))
def _test_xcorr_versus_CORRELATION_imag_data(): from spectrum.tools import twosided as func x = array([1,2,3,4,5+1.j]) for norm in ['biased', 'unbiased', 'coeff',None]: corr1,l = xcorr(x, x, maxlags=4, norm=norm) corr2 = CORRELATION(x, x, maxlags=4, norm=norm) assert_array_almost_equal(corr1, func(corr2))
if __name__ == '__main__': Speech = Speech("bluesky3.wav") x, Fs =Speech.audioread(8000) # x = x / np.max(np.abs(x)) inc = 80 # frame shift wlen = 200 # frame length win = np.hanning(wlen) # window function N = len(x) # data length X = Speech.enframe(x, list(win), inc).T fn = X.shape[1] # frame number time = [i / Fs for i in range(N)] R = np.zeros(X.shape) for i in range(fn): u = X[:, i] R0, _ = xcorr(u) R[:, i] = R0[wlen - 1 : 2 * wlen - 1] i = input("Which frame do you want to plot") i = int(i) frameTime = Speech.FrameTime(fn, wlen, inc, Fs) fig = plt.figure(figsize=(9, 16)) plt.subplot(3, 1, 1) plt.plot(time, x) plt.xlabel('Time/s') plt.ylabel('Amplitude') plt.title('Speech Waveform')