【发布时间】:2020-09-25 23:03:27
【问题描述】:
我在 DSP 和生成音频文件的频谱图方面相当陌生。我的频谱图不平滑,它显示的是带有像素值的非常原始的图像,像这样
虽然我正在寻找这样的平滑频谱图
我在哪里做错了?是因为窗口大小的大小吗?我生成梅尔谱图的代码是
def readData(file):
origData,origSampFreq = librosa.load(file, sr=None)
return origData, origSampFreq
def resample(originalData, origSampFreq, targetSampFreq):
resampledData = librosa.resample(originalData, origSampFreq, targetSampFreq)
return resampledData
def normalizeSound(resampledData, axis):
""" Axis is 0 for row-wise and 1
for column wise"""
normalizedData = normalize(resampledData, axis)
return normalizedData
def calculateMelSpectogram(normalizedData, hop_length, win_length, sr):
#newSamplingFreq = 16000
S=librosa.feature.melspectrogram(normalizedData, sr=sr, hop_length=hop_length, win_length=win_length)
return S
#Plot melspectogram
def plotMelSpectogram(S, sr, name, ref=np.max):
plt.figure(figsize=(10,3))
S_dB = librosa.power_to_db(S, ref=np.max)
librosa.display.specshow(S_dB, x_axis='time',y_axis='mel', sr=16000,)
plt.colorbar(format='%+2.0f dB')
plt.title('Mel-frequency spectrogram')
plt.savefig('./chunk_images/' + name + "mel.png",dpi=(300), bbox_inches='tight')
plt.tight_layout()
plt.show()
def featureExtraction(audioFile, name, targetSampFreq = 16000,
axis =0 ,
hop_length= 256,
win_length=512):
y, y_sr = readData(file=audioFile)
print(y, y_sr)
resampledData = resample(originalData=y, origSampFreq=y_sr, targetSampFreq=targetSampFreq)
normalizedData = normalizeSound(resampledData, axis=axis)
S = calculateMelSpectogram(normalizedData=normalizedData, hop_length=hop_length, win_length=win_length, sr=targetSampFreq)
plotSound(soundData=normalizedData, sr=targetSampFreq,x_axis_string='time' , name = name)
plotMelSpectogram(S, sr=targetSampFreq, name = name, ref=np.max)
return S
# plot orginal time domain data
def plotSound(soundData, sr, x_axis_string, name):
plt.figure(figsize=(10,3))
waveplot(soundData, sr, x_axis=x_axis_string)
plt.savefig('./chunk_images/' + name + "sound.png",dpi=(300), bbox_inches='tight')
【问题讨论】:
-
我真的很熟悉DSP,但我不知道问题是什么。顶部图像是否显示了未经过任何平滑处理的下部图像的放大版本?你能用我们可以处理的一小部分数据(或随机值)重现这个问题吗?在任何情况下,平滑梅尔谱图都会改变它的外观。
-
你的两张图片的时间尺度完全不同,所以很难比较它们的平滑度。
标签: python matplotlib signal-processing librosa spectrogram