import librosa
def get_spectrogram(waveform, fs, nfft=128, overlap_pct=0.8):
"""
Get the spectrogram of a single channel
Inputs:
:param waveform: single channel temporal signal
:param fs: the sampling frequency (Hz)
:param nfft: number of time samples used for the STFT. Default 128
:param overlap_pct: percentage of overlap in the spectrogram. Default 0.8
Outputs:
:return: a spectrogram and associated time & frequency vectors
"""
spectrogram = np.abs(librosa.stft(
y=waveform, n_fft=nfft,
hop_length=int(np.floor(nfft * (1 - overlap_pct)))))
# Axis
height = spectrogram.shape[0]
width = spectrogram.shape[1]
tt = np.linspace(0, len(waveform)/fs, num=width)
ff = np.linspace(0, fs / 2, num=height)
p = 10 * np.log10(spectrogram * 10 ** 9)
return p, tt, ff
2023-05-04 librosa的spectrogram
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 第一战名称“群雄讨董:璀璨纷杂的时代” 这一章内容很多,从关键点开始吧。这一章讲的主要人物有曹操、孙坚、袁绍、公孙...