gpt4 book ai didi

python - 音频文件的希尔伯特变换

转载 作者:行者123 更新时间:2023-12-02 23:08:26 24 4
gpt4 key购买 nike

我正在研究声学信号处理,目前我在获取音频文件的希尔伯特变换时遇到问题。
我从数据窗口开始,然后使用每个窗口的希尔伯特变换。下面是我的代码:

import pylab
import scipy.io.wavfile
import numpy as np
import math
import scipy.signal as signal
import sys
sys.setrecursionlimit(10)
def goetrzel(data, target_frequency):
s_prev = 0
s_prev2 = 0
normalized_frequency = 2.0 * np.pi * target_frequency / len(data)
coeff = 2.0 * np.cos(normalized_frequency)
for sample in data:
s = sample + coeff * s_prev - s_prev2
s_prev2 = s_prev
s_prev = s
power = s_prev2 * s_prev2 + s_prev * s_prev - coeff * s_prev * s_prev2
return power

def sliding_window(data, length, skip=None):
if skip is None:
skip = length
n = len(data)
for i in range(0, n - int(length), int(skip)):
yield data[i:i+length]
def hilbert(data):
for sample in data:
analytic_sig= hilbert(data)
amplitude_env = np.abs(analytic_signal)
return analytic_sig , amplitude_env

detect_frequency = 485.0

num=44100
rate, data = scipy.io.wavfile.read('Downloads/ShortWAV.wav')

window_length = 400#2 * detect_frequency # How should I pick this?
window_skip = window_length # How should I pick this?

power = [goetrzel(window, detect_frequency) for window in sliding_window(data, window_length, window_skip)]
analytic_sig, amplitude_env = [hilbert(window) for window in sliding_window(data, window_length, window_skip)]
pylab.figure()
pylab.plot(power)
pylab.show()

我是新的 python 开发人员。程序给出错误:超出最大递归深度。

最佳答案

下面的这个片段是你的问题:你在自身内部调用 hilbert 函数,因为你有很多数据点导致递归限制被击中。

def hilbert(data):
for sample in data:
analytic_sig= hilbert(data)

您可能试图调用 scipy hilbert功能;我建议将代码更改为:
        analytic_sig = scipy.signal.hilbert(data)

您还需要导入正确的模块;添加到顶部:
import scipy.signal

关于python - 音频文件的希尔伯特变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36943479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com