def test_window_rms(self): data = num.random.randn(5000) ws = data.size / 5 t0 = time() data_stds = utility.running_window_rms(data, window_size=ws) t1 = time() data_stds2 = num.array([ num.sqrt((data[i:i + ws] ** 2).sum() / ws) for i in range(data.size - ws + 1)]) t2 = time() print('Convolution %f [s], loop %f [s]' % (t1 - t0, t2 - t1)) num.testing.assert_allclose(data_stds, data_stds2, rtol=0., atol=1e-6) data_stds = utility.running_window_rms( data, window_size=ws, mode='same') print(data_stds.shape)
def toeplitz_covariance(data, window_size): """ Get Toeplitz banded matrix for given data. Returns ------- toeplitz : :class:`numpy.ndarray` 2-d, (size data, size data) stds : :class:`numpy.ndarray` 1-d, size data of running windows """ stds = running_window_rms(data, window_size=window_size, mode='same') coeffs = autocovariance(data / stds) return toeplitz(coeffs), stds