如何在librosa spectompomm上显示更多频率

发布于 2025-01-27 12:12:13 字数 783 浏览 5 评论 0原文

我正在尝试使用日志尺度绘制44.1 kHz音频谱图。但是天秤座仅显示 2^14 (16384)Hz,但这应该是 2^15 2^16 Hz之间的东西。我如何绘制全尺度光谱图?

import matplotlib.pyplot as plt
import librosa.display

import numpy as np
import pandas as pd
import librosa


y, sr1 = librosa.load('sample01.wav', duration=10,sr=44100)

S = np.abs(librosa.stft(y))

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
img = librosa.display.specshow(librosa.amplitude_to_db(S,ref=np.max), y_axis='log',sr=sr1, x_axis='time', ax=ax)
ax.set_title('Log')
fig.colorbar(img, ax=ax, format="%+2.0f dB")
plt.show()

I'm trying to plot 44.1 kHz audio spectrogram with log-scale. But librosa shows only 2^14 (16384) Hz, but it should be something between 2^15 and 2^16 Hz. How I can plot full-scale spectrogram?

import matplotlib.pyplot as plt
import librosa.display

import numpy as np
import pandas as pd
import librosa


y, sr1 = librosa.load('sample01.wav', duration=10,sr=44100)

S = np.abs(librosa.stft(y))

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
img = librosa.display.specshow(librosa.amplitude_to_db(S,ref=np.max), y_axis='log',sr=sr1, x_axis='time', ax=ax)
ax.set_title('Log')
fig.colorbar(img, ax=ax, format="%+2.0f dB")
plt.show()

Example

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉溺在你眼里的海 2025-02-03 12:12:13

天秤座工作正常,显示频率高达FS/2。很难在日志刻度上看到。您可以使用Zoom-In到顶部,您会发现它达到了21.05kHz左右。

我修改了您的示例,下面添加了设置yticks,以证明这些频率在那里(OFC必须发出一些随机信号)

import matplotlib.pyplot as plt
import librosa.display
import numpy as np
import librosa

y = np.random.randn(44100)
sr1 = 44100
S = np.abs(librosa.stft(y))

fig, ax = plt.subplots()
img = librosa.display.specshow(librosa.amplitude_to_db(S,ref=np.max), y_axis='log',sr=sr1, x_axis='time', ax=ax)
ax.set_title('Log')
ax.set_yticks([1,10,100,1000,10000,22000])
fig.colorbar(img, ax=ax, format="%+2.0f dB")
plt.show()

“在此处输入图像说明”

Librosa works correctly and shows frequencies up to fs/2. It is hard to see on log scale. You can either use zoom-in to top part and you will see that it gets to around 21.05kHz.

I modified your example, added below setting yticks, to prove those frequencies are there (and ofc had to make some random signal)

import matplotlib.pyplot as plt
import librosa.display
import numpy as np
import librosa

y = np.random.randn(44100)
sr1 = 44100
S = np.abs(librosa.stft(y))

fig, ax = plt.subplots()
img = librosa.display.specshow(librosa.amplitude_to_db(S,ref=np.max), y_axis='log',sr=sr1, x_axis='time', ax=ax)
ax.set_title('Log')
ax.set_yticks([1,10,100,1000,10000,22000])
fig.colorbar(img, ax=ax, format="%+2.0f dB")
plt.show()

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文