【发布时间】:2015-07-22 12:05:56
【问题描述】:
我正在使用 matplotlib 的 magnitude_spectrum 来比较吉他弦的音调特性。 Magnitude_spectrum 将 y 轴显示为具有“幅度(能量)”单位。我使用两个不同的“过程”来比较 FFT。过程 2(由于缺乏更好的描述)更容易解释——下面的代码和图表
我的问题是:
- 就单位而言,“幅度(能量)”是什么意思,它与 dB 有何关系?
- 使用#Process 2(参见下面的代码和图表),我查看的是什么类型的单位,dB?
- 如果 #Process 2 不是 dB,那么将其缩放到 dB 的最佳方法是什么?
我下面的代码(简化)显示了我正在谈论/查看的示例。
import numpy as np
from scipy.io.wavfile import read
from pylab import plot
from pylab import plot, psd, magnitude_spectrum
import matplotlib.pyplot as plt
#Hello Signal!!!
(fs, x) = read('C:\Desktop\Spectral Work\EB_AB_1_2.wav')
#Remove silence out of beginning of signal with threshold of 1000
def indices(a, func):
#This allows to use the lambda function for equivalent of find() in matlab
return [i for (i, val) in enumerate(a) if func(val)]
#Make the signal smaller so it uses less resources
x_tiny = x[0:100000]
#threshold is 1000, 0 is calling the first index greater than 1000
thresh = indices(x_tiny, lambda y: y > 1000)[1]
# backs signal up 20 bins, so to not ignore the initial pluck sound...
thresh_start = thresh-20
#starts at threshstart ends at end of signal (-1 is just a referencing thing)
analysis_signal = x[thresh_start-1:]
#Split signal so it is 1 second long
one_sec = 1*fs
onesec = x[thresh_start-1:one_sec+thresh_start-1]
#process 1
(spectrum, freqs, _) = magnitude_spectrum(onesec, Fs=fs)
#process 2
spectrum1 = spectrum/len(spectrum)
我不知道如何批量处理多个 .wav 文件,所以我在一大堆不同的 .wav 文件上分别运行此代码,然后将它们放入 excel 中进行比较。但是为了不看难看的图,我用 Python 画了图。以下是绘制时#process1 和#process2 的样子:
流程 1
流程 2
【问题讨论】:
标签: python unit-testing matplotlib signal-processing acoustics