在AudioLazy库中从zfilter对象提取数值

5 投票
1 回答
757 浏览
提问于 2025-04-17 21:48

我正在使用AudioLazy库来提取一些音频特征。

这个lpc函数(线性预测编码)接收一个时间域的信号块,并返回一个叫做白化LPC滤波器(ZFilter)。

filt = lpc(intensity, order=16) # Analysis filter
gain = 1e-2 # Gain just for alignment with DFT
(gain / filt).plot(min_freq=0, max_freq=3.141592653589793/4);

filt是一个ZFilter,具体如下:

1 - 2.47585 * z^-1 + 2.68746 * z^-2 - 1.71373 * z^-3 + 0.383238 * z^-4 + 0.451183 * z^-5 - 0.480446 * z^-6 + 0.304557 * z^-7 + 0.0277818 * z^-8 - 0.280118 * z^-9 + 0.0705354 * z^-10 + 0.0217045 * z^-11 + 0.0456379 * z^-12 - 0.012231 * z^-13 + 0.00986871 * z^-14 + 0.0553664 * z^-15 - 0.0800961 * z^-16

绘图函数会返回一张图像:

我想从幅度曲线中提取数值(以分贝为单位)。你能帮我吗?

谢谢!

1 个回答

4

我用这几行代码解决了这个问题……现在我可以提取(还可以画图 :P)LPC向量了。

samples=2048; #Number of samples (frequency values)
min_freq=0.; #Frequency range
max_freq=3.141592653589793/4; #Frequency range
freq_scale="linear" #Chooses whether plot is "linear" 
mag_scale="dB" #Chooses whether magnitude plot scale.
fscale = freq_scale.lower()
mscale = mag_scale.lower()
mscale = "dB"

fig = plt.figure()
Hz = 3.141592653589793 / 12.

# Sample the frequency range linearly (data scale) and get the data
freqs = list(line(samples, min_freq, max_freq, finish=True))
freqs_label = list(line(samples, min_freq / Hz, max_freq / Hz, finish=True))
data = filt.freq_response(freqs)
mag = { "dB": dB20 }[mscale]
print mag(data);

这个图是这样的:

plot

撰写回答