从AudioLazy库中的python中的zfilter对象中提取数值

时间:2014-03-11 14:37:00

标签: python matplotlib filtering signal-processing frequency

我正在使用AudioLazy Library来提取某些音频功能。

lpc function(线性预测编码)在时域中接收一个块,并返回白化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

绘图功能,返回图像:

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

由于

1 个答案:

答案 0 :(得分: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