Matplotlib Magnitude_spectrum Units in Python for Comparing Guitar Strings -


i'm using matplotlib's magnitude_spectrum compare tonal characteristics of guitar strings. magnitude_spectrum shows y axis having units of "magnitude (energy)". use 2 different 'processes' compare fft. process 2 (for lack of better description) easier interpret- code & graphs below

my questions are:

  • in terms of units, "magnitude (energy)" mean , how relate db?
  • using #process 2 (see code & graphs below), type of units looking at, db?
  • if #process 2 not db, best way scale db?

my code below (simplified) shows example of i'm talking about/looking at.

import numpy np scipy.io.wavfile import read pylab import plot pylab import plot, psd, magnitude_spectrum import matplotlib.pyplot plt  #hello signal!!! (fs, x) = read('c:\desktop\spectral work\eb_ab_1_2.wav')   #remove silence out of beginning of signal threshold of 1000  def indices(a, func): #this allows use lambda function equivalent of find() in matlab return [i (i, val) in enumerate(a) if func(val)]  #make signal smaller uses less resources x_tiny = x[0:100000] #threshold 1000, 0 calling first index greater 1000 thresh = indices(x_tiny, lambda y: y > 1000)[1] # backs signal 20 bins, not ignore initial pluck sound... thresh_start = thresh-20 #starts @ threshstart ends @ end of signal (-1 referencing     thing) analysis_signal = x[thresh_start-1:]   #split signal 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 bulk process on multiple .wav files run code separately on whole bunch of different .wav files , put them excel compare. sake of not looking @ ugly graphs, graphed in python. here's #process1 , #process2 when graphed:

process 1

#process 1

process 2

#process 2

magnetude absolute value of frequency spectrum. have labelled in process 1 "energy" way think it.

both process 1 , process 2 in same units. difference values in process 2 has been divided total length of array (a scalar, hence no change of units). happens part of fft, not (e.g. numpy.fft doesn't include divide length).

the easiest way scale db is:

(spectrum, freqs, _) = magnitude_spectrum(onesec, fs=fs, scale='db')

if wanted need like: spectrum2 = 20*numpy.log10(spectrum)

**it worth noting i'm not sure if should applying /len(spectrum) or not. suggest using scale='db' !!


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -