def test_stdft(): """Test stdft by comparing to Octave""" x = np.random.randn(2 * FS) spec_m = octave.feval('octave/stdft.m', x, float(N_FRAME), float(N_FRAME / 2), float(NFFT)) spec_m = spec_m[:, 0:(NFFT // 2 + 1)].transpose() spec = stft(x, N_FRAME, NFFT, overlap=2).transpose() assert_allclose(spec, spec_m, atol=ATOL)
def test_stdft(): x = np.random.randn(2 * FS, ) x_m = matlab.double(list(x)) spec_m = eng.stdft(x_m, float(N_FRAME), float(N_FRAME / 2), float(NFFT)) spec_m = np.array(spec_m) spec_m = spec_m[:, 0:(NFFT / 2 + 1)].transpose() spec = stft(x, N_FRAME, NFFT, overlap=2).transpose() assert_allclose(spec, spec_m, atol=ATOL)
def test_apply_OBM(): """Test apply_OBM by comparing to Octave""" obm_m, _ = octave.feval('octave/thirdoct.m', float(FS), float(NFFT), float(NUMBAND), float(MINFREQ), nout=2) x = np.random.randn(2 * FS) x_tob_m = octave.feval('octave/applyOBM', x, obm_m, float(N_FRAME), float(NFFT), float(NUMBAND)) x_tob_m = np.array(x_tob_m) x_spec = stft(x, N_FRAME, NFFT, overlap=2).transpose() x_tob = np.zeros((NUMBAND, x_spec.shape[1])) for i in range(x_tob.shape[1]): x_tob[:, i] = np.sqrt(np.matmul(OBM, np.square(np.abs(x_spec[:, i])))) assert_allclose(x_tob, x_tob_m, atol=ATOL)
def test_apply_OBM(): obm_m, cf_m = eng.thirdoct(float(FS), float(NFFT), float(NUMBAND), float(MINFREQ), nargout=2) x = np.random.randn(2 * FS, ) x_m = matlab.double(list(x)) x_tob_m = eng.applyOBM(x_m, obm_m, float(N_FRAME), float(NFFT), float(NUMBAND)) x_tob_m = np.array(x_tob_m) x_spec = stft(x, N_FRAME, NFFT, overlap=2).transpose() x_tob = np.zeros((NUMBAND, x_spec.shape[1])) for i in range(x_tob.shape[1]): x_tob[:, i] = np.sqrt(np.matmul(OBM, np.square(np.abs(x_spec[:, i])))) assert_allclose(x_tob, x_tob_m, atol=ATOL)