How to determine string tone from FFT

I have a spectrum from the Fourier transform. It looks like this: sound spektrogram created by passing police
The police just walked by

Color represents intensity.
X axis - time.
Y axis - frequency - where 0 is on top.

As long as the whistle or police siren leaves only one trace, many other tones seem to contain many harmonic frequencies.

sound spektrogram of EHGDAE tuned guitar An electric guitar connects directly to the microphone (standard setting)

The very bad thing is that, as you see, there is not much intensity - there are almost 2-3 frequencies that are almost equal. I wrote a peak detection algorithm to highlight the strongest peak:

    function findPeaks(data, look_range, minimal_val) {
      if(look_range==null)
        look_range = 10;
      if(minimal_val == null)
        minimal_val = 20;
      //Array of peaks            
      var peaks = [];
      //Currently the max value (that might or might not end up in peaks array)
      var max_value = 0;
      var max_value_pos = 0;
      //How many values did we check without changing the max value
      var smaller_values = 0;
      //Tmp variable for performance
      var val;
      var lastval=Math.round(data.averageValues(0,4));
      //console.log(lastval);
      for(var i=0, l=data.length; i<l; i++) {
        //Remember the value for performance and readibility
        val = data[i];

        //If last max value is larger then the current one, proceed and remember
        if(max_value>val) {
          //iterate the ammount of values that are smaller than our champion
          smaller_values++;
          //If there has been enough smaller values we take this one for confirmed peak
          if(smaller_values > look_range) {
            //Remember peak
            peaks.push(max_value_pos);
            //Reset other variables
            max_value = 0;
            max_value_pos = 0;
            smaller_values = 0;
          }
        }
        //Only take values when the difference is positive (next value is larger)
        //Also aonly take values that are larger than minimum thresold
        else if(val>lastval && val>minimal_val) {
          //Remeber this as our new champion
          max_value = val;
          max_value_pos = i;
          smaller_values = 0;
          //console.log("Max value: ", max_value);
        }           
        //Remember this value for next iteration
        lastval = val;
      }
      //Sort peaks so that the largest one is first
      peaks.sort(function(a, b) {return -data[a]+data[b];});
      //if(peaks.length>0)
      //  console.log(peaks);
      //Return array
      return peaks;
    }

, , , thresold minimal_val. look_range , . , .

, , :

Guitar strings now with highlighted strongest frequency

jsFiddle, , (, , ).

+4
1

, , -

f0, 2 * f0, 3 * f0,...

f0 - .

f0 ( FFT, abs, , ), , .

- () (, ) . t0 == 1/f0.

fft β†’ abs() β†’ fft-1 (ACF) -.

FFT ( ACF) . , "" sinc.

: . ( ) FFT, ACF "" ( , ).

+2

Source: https://habr.com/ru/post/1541608/


All Articles