Example #1
0
    def test_FindWavKurt(self):
        from scipy.io.matlab import loadmat

        N = 16
        fcut = 0.4
        level_index = 11
        freq_index = 24
        lev = self.level_w[level_index]

        base_path = os.getenv("WAVELOC_PATH")
        matlab_file = os.path.join(base_path, "test_data", "c.mat")
        c_dict = loadmat(matlab_file)
        c_exp = c_dict["c"]

        matlab_file = os.path.join(base_path, "test_data", "S.mat")
        S_dict = loadmat(matlab_file)
        S_exp = S_dict["S"]

        # get bw and frequency (Hz)
        bw_hz, fc_hz, fi, l1 = getBandwidthAndFrequency(
            self.nlevel, self.Fs, self.level_w, self.freq_w, level_index, freq_index
        )

        # get basic filter parameters
        h, g, h1, h2, h3 = get_h_parameters(N, fcut)
        c, s, threshold, Bw, fc = Find_wav_kurt(self.x, h, g, h1, h2, h3, self.nlevel, lev, fi, Fs=self.Fs)
        S = getFTSquaredEnvelope(c)

        # do tests
        self.assertAlmostEqual(Bw * self.Fs, bw_hz)
        self.assertAlmostEqual(fc * self.Fs, fc_hz)
        np.testing.assert_allclose(c.flatten(), c_exp.flatten(), atol=1e-3)
        np.testing.assert_allclose(S.flatten(), S_exp.flatten(), atol=1e-6)
Example #2
0
    def test_BandwidthFrequency(self):

        level_index = 11
        freq_index = 24
        level_exp = 6
        bw_exp = 0.78125
        fc_exp = 1.953125

        # get the bandwith and central frequency
        bw, fc, fi, l1 = getBandwidthAndFrequency(
            self.nlevel, self.Fs, self.level_w, self.freq_w, level_index, freq_index
        )
        # do test
        self.assertAlmostEqual(bw, bw_exp)
        self.assertAlmostEqual(fc, fc_exp)
        self.assertEqual(self.level_w[level_index], level_exp)
Example #3
0
    def test_BandwidthFrequency(self):

        level_index = 11
        freq_index = 24
        level_exp = 6
        bw_exp = 0.78125
        fc_exp = 1.953125

        # get the bandwith and central frequency
        bw, fc, fi, l1 = \
            getBandwidthAndFrequency(self.nlevel, self.Fs, self.level_w,
                                     self.freq_w, level_index, freq_index)
        # do test
        self.assertAlmostEqual(bw, bw_exp)
        self.assertAlmostEqual(fc, fc_exp)
        self.assertEqual(self.level_w[level_index], level_exp)
Example #4
0
    def test_FindWavKurt(self):
        from scipy.io.matlab import loadmat

        N = 16
        fcut = 0.4
        level_index = 11
        freq_index = 24
        lev = self.level_w[level_index]

        base_path = os.getenv('WAVELOC_PATH')
        matlab_file = os.path.join(base_path, 'test_data', 'c.mat')
        c_dict = loadmat(matlab_file)
        c_exp = c_dict['c']

        matlab_file = os.path.join(base_path, 'test_data', 'S.mat')
        S_dict = loadmat(matlab_file)
        S_exp = S_dict['S']

        # get bw and frequency (Hz)
        bw_hz, fc_hz, fi, l1 = \
            getBandwidthAndFrequency(self.nlevel, self.Fs, self.level_w,
                                     self.freq_w, level_index, freq_index)

        # get basic filter parameters
        h, g, h1, h2, h3 = get_h_parameters(N, fcut)
        c, s, threshold, Bw, fc = Find_wav_kurt(self.x,
                                                h,
                                                g,
                                                h1,
                                                h2,
                                                h3,
                                                self.nlevel,
                                                lev,
                                                fi,
                                                Fs=self.Fs)
        S = getFTSquaredEnvelope(c)

        # do tests
        self.assertAlmostEqual(Bw * self.Fs, bw_hz)
        self.assertAlmostEqual(fc * self.Fs, fc_hz)
        np.testing.assert_allclose(c.flatten(), c_exp.flatten(), atol=1e-3)
        np.testing.assert_allclose(S.flatten(), S_exp.flatten(), atol=1e-6)