def hilbert(signal):
# construct the Hilbert transform of the signal via the FFT
# in essense, we just want to set negative frequency components to zero
spectrum = np.fft.fft(signal)
n = len(signal)
midpoint = int(np.ceil(n/2))
kernel = np.zeros(n)
kernel[0] = 1
if n%2 == 0:
kernel[midpoint] = 1
kernel[1:midpoint] = 2
return np.fft.ifft(kernel * spectrum)
评论列表
文章目录