def test_coherency_multi_taper(): """Tests that the coherency algorithm runs smoothly, using the multi_taper csd routine and that the resulting matrix is symmetric""" t = np.linspace(0,16*np.pi,1024) x = np.sin(t) + np.sin(2*t) + np.sin(3*t) + np.random.rand(t.shape[-1]) y = x + np.random.rand(t.shape[-1]) method = {"this_method":'multi_taper_csd', "Fs":2*np.pi} f,c = tsa.coherency(np.vstack([x,y]),csd_method=method) np.testing.assert_array_almost_equal(c[0,1],c[1,0].conjugate()) np.testing.assert_array_almost_equal(c[0,0],np.ones(f.shape))
def test_coherency_cached(): """Tests that the cached coherency gives the same result as the standard coherency""" t = np.linspace(0,16*np.pi,1024) x = np.sin(t) + np.sin(2*t) + np.sin(3*t) + np.random.rand(t.shape[-1]) y = x + np.random.rand(t.shape[-1]) f1,c1 = tsa.coherency(np.vstack([x,y])) ij = [(0,1),(1,0)] f2,cache = tsa.cache_fft(np.vstack([x,y]),ij) c2 = tsa.cache_to_coherency(cache,ij) np.testing.assert_array_almost_equal(c1[1,0],c2[1,0]) np.testing.assert_array_almost_equal(c1[0,1],c2[0,1])
def test_coherency_mlab(): """Tests that the coherency algorithm runs smoothly, using the mlab csd routine, that the resulting matrix is symmetric and that the frequency bands in the output make sense""" t = np.linspace(0,16*np.pi,1024) x = np.sin(t) + np.sin(2*t) + np.sin(3*t) + np.random.rand(t.shape[-1]) y = x + np.random.rand(t.shape[-1]) method = {"this_method":'mlab', "NFFT":256, "Fs":2*np.pi} f,c = tsa.coherency(np.vstack([x,y]),csd_method=method) np.testing.assert_array_almost_equal(c[0,1],c[1,0].conjugate()) np.testing.assert_array_almost_equal(c[0,0],np.ones(f.shape)) f_theoretical = ut.get_freqs(method['Fs'],method['NFFT']) np.testing.assert_array_almost_equal(f,f_theoretical)