test_filter.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:urh 作者: jopohl 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号