ギター弦の音色特性を比較するために、matplotlib の Magnitude_spectrum を使用しています。Magnitude_spectrum は、「マグニチュード (エネルギー)」の単位を持つ y 軸を示します。2 つの異なる「プロセス」を使用して 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 をグラフにすると、次のようになります。