コード例 #1
0
ファイル: test_filter.py プロジェクト: ganlubbq/urh
    def test_fft_convolution(self):
        x = np.array([1, 2, 3])
        h = np.array([0, 1, 0.5])
        expected_result = np.array([1., 2.5, 4.])
        result_np = np.convolve(x, h, 'same')
        self.assertTrue(np.array_equal(result_np, expected_result))

        result_fft = Filter.fft_convolve_1d(x, h)
        self.assertTrue(np.array_equal(result_fft, expected_result))

        x = np.linspace(0, 1, num=10**3).astype(np.complex64)
        h = Filter.design_windowed_sinc_bandpass(0.1, 0.4, 0.01)
        # fft convolve is faster if IR is round about 400 samples or windowed sinc has bandwidth of 0.01
        print(len(h))

        t_np = time.time()
        result_np = np.convolve(x, h, mode="same")
        t_np = time.time() - t_np

        t_fft = time.time()
        result_fft = Filter.fft_convolve_1d(x, h)
        t_fft = time.time() - t_fft

        np.testing.assert_array_almost_equal(result_np, result_fft)
        print("fft convolve time", t_fft, "np convolve time", t_np)
コード例 #2
0
    def test_fft_convolution(self):
        x = np.array([1, 2, 3])
        h = np.array([0, 1, 0.5])
        expected_result = np.array([1., 2.5, 4.])
        result_np = np.convolve(x, h, 'same')
        self.assertTrue(np.array_equal(result_np, expected_result))

        result_fft = Filter.fft_convolve_1d(x, h)
        self.assertEqual(len(expected_result), len(result_fft))
        for i in range(len(expected_result)):
            self.assertAlmostEqual(expected_result[i], result_fft[i], places=8, msg=str(i))

        x = np.linspace(0, 1, num=10 ** 3).astype(np.complex64)
        h = Filter.design_windowed_sinc_bandpass(0.1, 0.4, 0.01)
        # fft convolve is faster if IR is round about 400 samples or windowed sinc has bandwidth of 0.01

        result_np = np.convolve(x, h, mode="same")
        result_fft = Filter.fft_convolve_1d(x, h)

        np.testing.assert_array_almost_equal(result_np, result_fft)
コード例 #3
0
ファイル: test_filter.py プロジェクト: jopohl/urh
    def test_fft_convolution(self):
        x = np.array([1, 2, 3])
        h = np.array([0, 1, 0.5])
        expected_result = np.array([1., 2.5, 4.])
        result_np = np.convolve(x, h, 'same')
        self.assertTrue(np.array_equal(result_np, expected_result))

        result_fft = Filter.fft_convolve_1d(x, h)
        self.assertEqual(len(expected_result), len(result_fft))
        for i in range(len(expected_result)):
            self.assertAlmostEqual(expected_result[i], result_fft[i], places=8, msg=str(i))

        x = np.linspace(0, 1, num=10 ** 3).astype(np.complex64)
        h = Filter.design_windowed_sinc_bandpass(0.1, 0.4, 0.01)
        # fft convolve is faster if IR is round about 400 samples or windowed sinc has bandwidth of 0.01

        result_np = np.convolve(x, h, mode="same")
        result_fft = Filter.fft_convolve_1d(x, h)

        np.testing.assert_array_almost_equal(result_np, result_fft)