1

I'm using matplotlib's magnitude_spectrum to compare the tonal characteristics of guitar strings. Magnitude_spectrum shows the y axis as having units of "Magnitude (energy)". I use two different 'processes' to compare the FFT. Process 2 (for lack of a better description) is much easier to interpret- code & graphs below

My questions are:

  • In terms of units, what does "Magnitude (energy)" mean and how does it relate to dB?
  • Using #Process 2 (see code & graphs below), what type of units am I looking at, dB?
  • If #Process 2 is not dB, then what is the best way to scale it to dB?

My code below (simplified) shows an example of what I'm talking about/looking at.

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)

I don't know how to bulk process on multiple .wav files so I run this code separately on a whole bunch of different .wav files and i put them into excel to compare. But for the sake of not looking at ugly graphs, I graphed it in Python. Here's what #process1 and #process2 look like when graphed:

Process 1

#Process 1

Process 2

#Process 2

4

2 回答 2

2

磁力只是频谱的绝对值。正如您在过程 1 中所标记的那样,“能量”是一种很好的思考方式。

过程 1 和过程 2 都在同一个单元中。唯一的区别是过程 2 中的值已除以数组的总长度(一个标量,因此单位没有变化)。通常这会作为 FFT 的一部分发生,但有时不会(例如 numpy.FFT 不包括除以长度)。

将其缩放到 dB 的最简单方法是:

(频谱,频率,_)=幅度谱(onesec,Fs=fs,scale='dB')

如果您想自己执行此操作,则需要执行以下操作:spectrum2 = 20*numpy.log10(spectrum)

**值得注意的是,我不确定您是否应该应用 /len(spectrum)。我建议使用 scale='dB' !

于 2015-05-12T14:42:05.487 回答
1

要转换为 dB,请在绘制之前记录任何非零频谱幅度的对数,并进行缩放(缩放以匹配校准的麦克风和声源,如果可用,或使用任意缩放以使电平看起来很熟悉)。

对于零幅度值,也许只需用您想要在对数图底部的任何内容替换或钳制对数(当然不是负无穷大)。

于 2015-05-11T21:40:06.060 回答