Exemple #1
0
 def test_lowpass_cheby_2(self):
     """
     Check magnitudes of basic lowpass cheby2
     """
     df = 200  # Hz
     b, a = lowpass_cheby_2(data=None, freq=50, df=df, maxorder=12, ba=True)
     nyquist = 100
     # calculate frequency response
     w, h = sg.freqz(b, a, nyquist)
     freq = w / np.pi * nyquist
     h_db = 20 * np.log10(abs(h))
     # be smaller than -96dB above lowpass frequency
     self.assertGreater(-96, h_db[freq > 50].max())
     # be 0 (1dB ripple) before filter ramp
     self.assertGreater(h_db[freq < 25].min(), -1)
Exemple #2
0
 def test_lowpassCheby2(self):
     """
     Check magnitudes of basic lowpass cheby2
     """
     df = 200  # Hz
     b, a = lowpass_cheby_2(data=None, freq=50,
                            df=df, maxorder=12, ba=True)
     nyquist = 100
     # calculate frequency response
     w, h = sg.freqz(b, a, nyquist)
     freq = w / np.pi * nyquist
     h_db = 20 * np.log10(abs(h))
     # be smaller than -96dB above lowpass frequency
     self.assertGreater(-96, h_db[freq > 50].max())
     # be 0 (1dB ripple) before filter ramp
     self.assertGreater(h_db[freq < 25].min(), -1)
Exemple #3
0
 def test_decimate(self):
     """
     Tests the decimate method of the Trace object.
     """
     # create test Trace
     tr = Trace(data=np.arange(20))
     tr_bkp = deepcopy(tr)
     # some test that should fail and leave the original trace alone
     self.assertRaises(ValueError, tr.decimate, 7, strict_length=True)
     self.assertRaises(ValueError, tr.decimate, 9, strict_length=True)
     self.assertRaises(ArithmeticError, tr.decimate, 18)
     # some tests in place
     tr.decimate(4, no_filter=True)
     np.testing.assert_array_equal(tr.data, np.arange(0, 20, 4))
     self.assertEqual(tr.stats.npts, 5)
     self.assertEqual(tr.stats.sampling_rate, 0.25)
     self.assertIn("decimate", tr.stats.processing[0])
     self.assertIn("factor=4", tr.stats.processing[0])
     tr = tr_bkp.copy()
     tr.decimate(10, no_filter=True)
     np.testing.assert_array_equal(tr.data, np.arange(0, 20, 10))
     self.assertEqual(tr.stats.npts, 2)
     self.assertEqual(tr.stats.sampling_rate, 0.1)
     self.assertIn("decimate", tr.stats.processing[0])
     self.assertIn("factor=10", tr.stats.processing[0])
     # some tests with automatic prefiltering
     tr = tr_bkp.copy()
     tr2 = tr_bkp.copy()
     tr.decimate(4)
     df = tr2.stats.sampling_rate
     tr2.data, fp = lowpass_cheby_2(data=tr2.data,
                                    freq=df * 0.5 / 4.0,
                                    df=df,
                                    maxorder=12,
                                    ba=False,
                                    freq_passband=True)
     # check that iteratively determined pass band frequency is correct
     self.assertAlmostEqual(0.0811378285461, fp, places=7)
     tr2.decimate(4, no_filter=True)
     np.testing.assert_array_equal(tr.data, tr2.data)
Exemple #4
0
 def test_decimate(self):
     """
     Tests the decimate method of the Trace object.
     """
     # create test Trace
     tr = Trace(data=np.arange(20))
     tr_bkp = deepcopy(tr)
     # some test that should fail and leave the original trace alone
     self.assertRaises(ValueError, tr.decimate, 7, strict_length=True)
     self.assertRaises(ValueError, tr.decimate, 9, strict_length=True)
     self.assertRaises(ArithmeticError, tr.decimate, 18)
     # some tests in place
     tr.decimate(4, no_filter=True)
     np.testing.assert_array_equal(tr.data, np.arange(0, 20, 4))
     self.assertEqual(tr.stats.npts, 5)
     self.assertEqual(tr.stats.sampling_rate, 0.25)
     self.assertIn("decimate", tr.stats.processing[0])
     self.assertIn("factor=4", tr.stats.processing[0])
     tr = tr_bkp.copy()
     tr.decimate(10, no_filter=True)
     np.testing.assert_array_equal(tr.data, np.arange(0, 20, 10))
     self.assertEqual(tr.stats.npts, 2)
     self.assertEqual(tr.stats.sampling_rate, 0.1)
     self.assertIn("decimate", tr.stats.processing[0])
     self.assertIn("factor=10", tr.stats.processing[0])
     # some tests with automatic prefiltering
     tr = tr_bkp.copy()
     tr2 = tr_bkp.copy()
     tr.decimate(4)
     df = tr2.stats.sampling_rate
     tr2.data, fp = lowpass_cheby_2(data=tr2.data, freq=df * 0.5 / 4.0,
                                    df=df, maxorder=12, ba=False,
                                    freq_passband=True)
     # check that iteratively determined pass band frequency is correct
     self.assertAlmostEqual(0.0811378285461, fp, places=7)
     tr2.decimate(4, no_filter=True)
     np.testing.assert_array_equal(tr.data, tr2.data)