【发布时间】:2020-12-22 01:28:39
【问题描述】:
我想通过 scipy 内置的低通滤波器发送一些数据。我正在用下面的一些 numpy 数据数组对其进行测试。它工作正常并在使用 numpy 时输出过滤后的值。然后我想看看我是否可以使用 GPU 并加快速度,并听说了与 numpy 类似的 CuPy。但是,当我将 numpy 数组替换为 cupy 数组时,出现以下错误ValueError: could not convert b, a, and x to a common type
from scipy.signal import butter, lfilter, freqz
import cupy as cp
import time
import numpy as np
def butter_lowpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='low', analog=False)
return b, a
def butter_lowpass_filter(data, cutoff, fs, order=5):
b, a = butter_lowpass(cutoff, fs, order=order)
y = lfilter(b, a, data)
return y
order = 1
fs = 30.0
cutoff = 0.3
new_frame_np = np.ones(100)*3
new_frame_cp = cp.ones(100)*3
y = butter_lowpass_filter(new_frame_np, cutoff, fs, order) #WORKS
y = butter_lowpass_filter(new_frame_cp, cutoff, fs, order) #DOES NOT WORK
如何让cupy数组在上面的例子中工作?
Scipy 似乎适用于 CPU 任务,因此它可能不适用于 GPU 的 Cupy 数组。我找不到任何为cupy阵列提供低通或带通滤波器的库。
【问题讨论】:
-
您不能将 GPU 阵列与 scipy.signal 一起使用。对于基于 GPU 的信号处理,您应该查看 cuSignal 或 torch.audio (pytorch)
-
我查看了 cuSignal 并确认, firwin() 是什么可以进行过滤的?没有任何明确称为低通滤波器的东西
标签: python arrays numpy scipy cupy