matlab cwtfilterbank,在Python中为gammatone filterbank实现打开音频信号窗口

我不熟悉编程,尤其是python。我正在尝试用四阶伽玛通滤波器实现听觉模型。我需要把信号分成39个频道。当我使用较小的信号(大约884726位)时,代码运行良好,但我认为缓冲区已满,因此我必须重新启动shell来再次运行代码。尝试使用flush()但没有成功。

所以,我决定用汉宁窗打开信号,但也没成功。为了清楚起见,我需要将一个音频信号分成39个通道,对其进行校正(半波),然后将其传递到第二组四阶滤波器中,这次是10个通道。我试图在信号进入第二组滤波器之前降低信号的采样率。这是通过使用另一个函数生成的系数来实现滤波器组的代码。b的尺寸为39x4096。在def filterbank_application(input, b, verbose = False):

"""

A function to run the input through a bandpass filter bank with parameters defined by the b and a coefficients.

Parameters:

* input (type: array-like matrix of floats) - input signal. (Required)

* b (type: array-like matrix of floats) - the b coefficients of each filter in shape b[numOfFilters][numOfCoeffs]. (Required)

Returns:

* y (type: numpy array of floats) - an array with inner dimensions equal to that of the input and outer dimension equal to

the length of fc (i.e. the number of bandpass filters in the bank) containing the outputs to each filter. The output

signal of the nth filter can be accessed using y[n].

"""

input = np.array(input)

bshape = np.shape(b)

nFilters = bshape[0]

lengthFilter = bshape[1]

shape = (nFilters,) + (np.shape(input))

shape = np.array(shape[0:])

shape[-1] = shape[-1] + lengthFilter -1

y = np.zeros((shape))

for i in range(nFilters):

if(verbose):

sys.stdout.write("\r" + str(int(np.round(100.0*i/nFilters))) + "% complete.")

sys.stdout.flush()

x = np.array(input)

y[i] = signal.fftconvolve(x,b[i])

if(verbose): sys.stdout.write("\n")

return y

samplefreq,input = wavfile.read('sine_sweep.wav')

input = input.transpose()

input = (input[0] + input[1])/2

b_coeff1 = gammatone_filterbank(samplefreq, 39)

Output = filterbank_application(input, b_coeff1)

Rect_Output = half_rectification(Output)

我想把音频分成20秒长的块。如果你能告诉我一个有效的方法来打开我的信号,因为整个音频将比我使用的信号大6倍。提前谢谢。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值