gpt4 book ai didi

python - 为什么 librosa 图与 matplotlib 和 audacity 不同

转载 作者:行者123 更新时间:2023-12-02 19:55:02 31 4
gpt4 key购买 nike

我正在从文件中读取 pcm 数据,然后绘制它。我注意到 librosa.display.waveplot、plot 和 audacity 之间的绘图有所不同。

这是代码和图像

%matplotlib inline
import matplotlib.pyplot as plt
import librosa.display
import numpy as np
import IPython.display as ipd
import matplotlib.pyplot as plt
import numpy, pylab

# the pcm file is 32le integer with a sampling rate of 16KHz
pcm_data = np.fromfile('someaudio.pcm', dtype=np.int32)

# the sample has the same sound as audacity
ipd.Audio(data=pcm_data, rate=16000)

# all of these give the same resulting plot
plt.figure()
plt.subplot(3, 1, 1)
#librosa.display.waveplot(pcm_data, sr=16000)
#librosa.display.waveplot(pcm_data.astype('double'), sr=16000)
librosa.display.waveplot(pcm_data.astype('float'), max_points=None, sr=16000, max_sr=16000)

这个结果看起来像 enter image description here

# alternatively plot via matplotlib
pylab.plot(pcm_data)
pylab.show()

这个结果看起来像 enter image description here

matplotlib 的结果看起来像 audacity enter image description here

最佳答案

matplotlibAudacity 显示实际信号样本,在记录的后半部分显然都是负值。

另一方面,

librosa 显示绝对信号的包络,如其 documentation 中所述。 :

Plot the amplitude envelope of a waveform.

If y is monophonic, a filled curve is drawn between [-abs(y), abs(y)].

y 是本例中的信号。

这有效地导致了沿 x 轴的镜像效应,这就是为什么 librosa 图是对称的。 matplotlibAudacity 显然没有做这样的事情。

有人可能会说,librosa 的行为有效地隐藏了不对称波形(即正负样本的幅度不相似),这在野外是可能的。来自 soundonsound.com :

This asymmetry is due mainly to two things, the first being the relative phase relationships between the fundamental and different harmonic components in a harmonically complex signal. In combining different frequency signals with differing phase relationships, the result is often a distinctly asymmetrical waveform, and that waveform asymmetry often changes and evolves over time, too. That's just what happens when complex related signals are superimposed.

有人可能还会争辩说,这种不对称性并没有太多有用的信息,因为人类通常无法感知到它。

如果您认为 librosa 的行为是意外或错误的,我建议您填写错误报告,寻求解释。

关于python - 为什么 librosa 图与 matplotlib 和 audacity 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57260065/

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