def test_coherence_mlab(): """Tests that the code runs 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":'mlab', "NFFT":256, "Fs":2*np.pi} f,c = tsa.coherence(np.vstack([x,y]),csd_method=method) np.testing.assert_array_almost_equal(c[0,1],c[1,0]) f_theoretical = ut.get_freqs(method['Fs'],method['NFFT']) np.testing.assert_array_almost_equal(f,f_theoretical)
def test_coherence_partial(): """ Test partial coherence""" 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]) z = x + np.random.rand(t.shape[-1]) method = {"this_method":'mlab', "NFFT":256, "Fs":2*np.pi} f,c = tsa.coherence_partial(np.vstack([x,y]),z,csd_method=method) f_theoretical = ut.get_freqs(method['Fs'],method['NFFT']) np.testing.assert_array_almost_equal(f,f_theoretical) np.testing.assert_array_almost_equal(c[0,1],c[1,0])
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)