コード例 #1
0
 def test_bandpass(self):
     """Band pass filtering."""
     # bandpass around the middle frequency
     fn = self.dat.fs / 2
     b, a = butter(4, [6 / fn, 8 / fn], btype='band')
     ans = filtfilt(self.dat, b, a)
     # check if the desired band is not damped
     dat = spectrum(ans)
     mask = dat.axes[0] == 7
     self.assertTrue((dat.data[mask] > 6.5).all())
     # check if the outer freqs are damped close to zero
     mask = (dat.axes[0] <= 6) & (dat.axes[0] > 8)
     self.assertTrue((dat.data[mask] < .5).all())
コード例 #2
0
 def test_spectrum(self):
     """Calculate the spectrum."""
     dat = spectrum(self.dat)
     # check that the amplitudes are almost correct
     for idx, freq in enumerate(self.freqs):
         for chan in range(dat.data.shape[1]):
             self.assertAlmostEqual(dat.data[dat.axes[0] == freq, chan], self.amps[idx], delta=.15)
     # check the amplitudes for the remaining freqs are almost zero
     mask = (dat.axes[0] != self.freqs[0]) & (dat.axes[0] != self.freqs[1]) & (dat.axes[0] != self.freqs[2])
     self.assertFalse((dat.data[mask] > .8).any())
     # check that the max freq is < self.dat.fs / 2, and min freq > 0
     self.assertGreater(min(dat.axes[0]), 0)
     self.assertLess(max(dat.axes[0]), self.dat.fs / 2)
コード例 #3
0
 def test_spectrum_swapaxes(self):
     """spectrum must work with nonstandard timeaxis."""
     dat = spectrum(swapaxes(self.dat, 0, 1), timeaxis=1)
     dat = swapaxes(dat, 0, 1)
     dat2 = spectrum(self.dat)
     self.assertEqual(dat, dat2)
コード例 #4
0
 def test_spectrum_copy(self):
     """spectrum must not modify argument."""
     cpy = self.dat.copy()
     spectrum(self.dat)
     self.assertEqual(cpy, self.dat)
コード例 #5
0
 def test_spectrum_has_no_fs(self):
     """A spectrum has no sampling freq."""
     dat = spectrum(self.dat)
     self.assertFalse(hasattr(dat, 'fs'))