0

I have a task to recognize a note that has been played by an instrument. From what i've read on the internet a good aproach to this problem is the FFT algorithm. It takes a wave input and splits it in multiple simple waves that when you sum them up they give you the original wave(decomposition). This part is clear.
I downloaded a .wav file that contains the piano note G that I want to recognize. I apply the FFT algorithm and obviously I get an output, from this step I am lost.
What do I need to do next to recognize the sound played ? I know i must transform this output in a frequency in Hz(as all notes have a frequency, unique if I am not mistaken). Which I can do like this:

[y,fs] = wavread('foo.wav');
ydft = fft(y);
% I'll assume y has even length
ydft = ydft(1:length(y)/2+1);
% create a frequency vector
freq = 0:fs/length(y):fs/2;

Now I have a vector named freq with the frequencies identified with the help of fft. How can I get the frequency of a note out of this vector?

Lucian Tarna
  • 1,806
  • 4
  • 25
  • 48
  • For a start you need to know how the instrument is tuned. The exact mapping from frequency to note varies quite a bit - see [Concert pitch](https://en.wikipedia.org/wiki/Concert_pitch) – greg-449 Nov 13 '16 at 11:03
  • I get them from [here](https://www.freesound.org/people/pinkyfinger/packs/4409/) so i guess it's the standard of 440 for A – Lucian Tarna Nov 13 '16 at 11:07
  • 2
    Note that musical pitch is typically a lot more complex than just finding the frequency of a single component. – Paul R Nov 13 '16 at 15:20
  • 1
    @LucianTarna I agree with Paul R, that there is more to it than simply finding the dominant frequency. However, if you just want to try that for starters, try `[ymax, idx] = max(ydft)` to find the maximal value in the FFT (`ymax`), and use `freq(idx)` to find the corresponding frequency. – hbaderts Nov 13 '16 at 17:17
  • but i never said i wanted the maximal value. My imput is a piano note(always), i must decide which note it is. Does the maximal value returned by the FFT represent the right answer always ? – Lucian Tarna Nov 13 '16 at 17:32
  • No - you really need to understand what [pitch](https://en.wikipedia.org/wiki/Pitch_%28music%29) is, and then read up on [pitch detection algorithms](https://en.wikipedia.org/wiki/Pitch_detection_algorithm). You might also find it instructive to look at the power spectrum of a piano note (plot the log magnitude of your FFT output) to see what you're up against. – Paul R Nov 13 '16 at 17:48
  • oh, i see, so reading for me, thank you very much Paul :) – Lucian Tarna Nov 13 '16 at 18:38
  • Yep - a little reading investment now will most likely save you a lot of wasted programming effort later... ;-) – Paul R Nov 14 '16 at 08:55

0 Answers0