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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 第一战名称“群雄讨董:璀璨纷杂的时代” 这一章内容很多,从关键点开始吧。这一章讲的主要人物有曹操、孙坚、袁绍、公孙...