Esempio n. 1
0
 def test_compare_stft_to_numpy(self):
     X_numpy = stft(self.time_signal, size=self.size, shift=self.shift,
                    window_length=self.window_length, window=self.window,
                    fading=self.fading)
     X_numpy = np.concatenate([np.real(X_numpy), np.imag(X_numpy)], axis=-1)
     X_torch = self.stft(self.torch_signal).numpy()
     tc.assert_almost_equal(X_torch, X_numpy)
Esempio n. 2
0
 def test_restore_time_signal_from_torch_stft_and_numpy_istft(self):
     X_torch = self.stft(self.torch_signal).numpy()
     X_numpy = X_torch[..., :self.fbins] + 1j * X_torch[..., self.fbins:]
     x_numpy = istft(X_numpy, size=self.size, shift=self.shift,
                     window_length=self.window_length, window=self.window,
                     fading=self.fading)[..., :self.time_signal.shape[-1]]
     tc.assert_almost_equal(x_numpy, self.time_signal)
Esempio n. 3
0
 def test_restore_time_signal_from_numpy_stft_and_torch_istft(self):
     X_numpy = stft(self.time_signal, size=self.size, shift=self.shift,
                    window_length=self.window_length, window=self.window,
                    fading=self.fading)
     x_torch = self.stft.inverse(torch.from_numpy(X_numpy))
     x_numpy = x_torch.numpy()[..., :self.time_signal.shape[-1]]
     tc.assert_almost_equal(x_numpy, self.time_signal)
Esempio n. 4
0
    def test_restore_time_signal_from_stft_and_istft(self):
        x = self.time_signal
        X = self.stft(self.torch_signal)

        tc.assert_almost_equal(
            self.stft.inverse(X)[..., :x.shape[-1]].numpy(), x)
        tc.assert_equal(X.shape, (154, self.num_features))
Esempio n. 5
0
    def test_restore_time_signal_with_str_window(self):
        x = self.x
        X = stft(x, window='hann')

        tc.assert_almost_equal(
            x, istft(X, 1024, 256, window='hann', num_samples=len(x)))
        tc.assert_equal(X.shape, (154, 513))
Esempio n. 6
0
 def test_compare_with_matlab(self):
     y = self.x
     Y_python = stft(y, symmetric_window=True)
     mlab = Mlab().process
     mlab.set_variable('y', y)
     mlab.run_code('Y = transform.stft(y(:), 1024, 256, @blackman);')
     Y_matlab = mlab.get_variable('Y').T
     tc.assert_almost_equal(Y_matlab, Y_python)
Esempio n. 7
0
 def test_mel2hzandhz2mel(self):
     rand = np.random.rand(5, 5) * 1000
     tc.assert_almost_equal(
         rand,
         transform.module_fbank.mel2hz(transform.module_fbank.hz2mel(rand)))
     tc.assert_almost_equal(
         rand,
         transform.module_fbank.hz2mel(transform.module_fbank.mel2hz(rand)))
Esempio n. 8
0
    def test_preemphasis_with_offcomp(self):
        y = self.x

        y_pre = transform.preemphasis(y)
        y_ref = transform.offset_compensation(y_pre)

        y_both = transform.preemphasis_with_offset_compensation(y)

        tc.assert_almost_equal(y_ref, y_both)
Esempio n. 9
0
 def test_restore_time_signal_from_stft_and_istft_odd_parameter(self):
     x = self.x
     import random
     kwargs = dict(
         # size=np.random.randint(100, 200),
         size=151,  # Test uneven size
         shift=np.random.randint(40, 100),
         window=random.choice(['blackman', 'hann', 'hamming']),
         fading='full',
     )
     X = stft(x, **kwargs)
     x_hat = istft(X, **kwargs, num_samples=x.shape[-1])
     assert x_hat.dtype == np.float64, (x_hat.dtype, x.dtype)
     tc.assert_almost_equal(x, x_hat, err_msg=str(kwargs))
Esempio n. 10
0
 def test_compare_stft_to_numpy(self):
     X_numpy = stft(self.time_signal, size=self.size, shift=self.shift,
                    window_length=self.window_length, window=self.window,
                    fading=self.fading)
     X_torch = self.stft(self.torch_signal).numpy()
     tc.assert_almost_equal(X_torch, X_numpy)
Esempio n. 11
0
    def test_restore_time_signal_from_stft_and_istft(self):
        x = self.x
        X = stft(x)

        tc.assert_almost_equal(x, istft(X, 1024, 256)[:len(x)])
        tc.assert_equal(X.shape, (154, 513))
Esempio n. 12
0
    def test_restore_time_signal_from_stft_and_istft_kaldi_params(self):
        x = self.x
        X = stft(x, size=400, shift=160)

        tc.assert_almost_equal(x, istft(X, 400, 160)[:len(x)])
        tc.assert_equal(X.shape, (243, 201))
Esempio n. 13
0
    def test_restore_time_signal_from_stft_and_istft_with_num_samples(self):
        x = self.x
        X = stft(x)

        tc.assert_almost_equal(x, istft(X, 1024, 256, num_samples=len(x)))
        tc.assert_equal(X.shape, (154, 513))