I want to create a project that will recognized the chords that i played in guitar. I recorded a raw sound to be compare to the one that the user will input.


I have a recorded sound chordA then I will ask the user to play a sound in the guitar and check if the signal is similar to my sound chordA..

Getting the audio signal is easy but comparing them is so hard. What is the method that will suit my application?

This is my code:

recObj = audiorecorder; 
disp('Start speaking.') 
recordblocking(recObj, 4); 
disp('End of Recording.'); 
myRecording = getaudiodata(recObj); 
[x, Fs] = wavread('chordread.wav'); 
[x1, Fs1] = wavread('chordA.wav'); 
Y = fft(x); 
Z = fft(x1); 

Now that I have Y and Z how can I compare those two?

  • $\begingroup$ Are you already using FFT? $\endgroup$ – user7358 Mar 5 '14 at 13:26
  • $\begingroup$ yes,,, this is my code recObj = audiorecorder; disp('Start speaking.') recordblocking(recObj, 4); disp('End of Recording.'); myRecording = getaudiodata(recObj); wavwrite(myRecording,'chordread.wav'); [x, Fs] = wavread('chordread.wav'); [x1, Fs1] = wavread('chordA.wav'); Y = fft(x); Z = fft(x1); now i get Y and Z how can i compare those two? $\endgroup$ – user8137 Mar 5 '14 at 13:38

You probably need more than one algorithm for an accurate detection. Work on frequency domain (mostly via DFT and spectrogram) is the most often used initial transform. After that sophisticated probabilistic models originally used in speech recognition are applied, such as hidden Markov models, dynamic Bayesian networks, and conditional random fields.

The review article Automatic Chord Transcription Using Computational Models of Musical Context gives you a thorough overview on the relevant technique, although it focuses on a more complicated chords recognition with more than one instrument (key, bass note, beat are all considered as well).

There are also some open source chord detection algorithms: Chordino, Chordata, and
LabROSA Chord Recognition. Note that in LabROSA, a supervised learning method is applied to "teach" the model recognize the chords with higher accuracy.

This is a very interesting topic, and I look forward to see your update in your guitar chord detection result.

  • $\begingroup$ Hi, thank you for the links it is really helpful:) $\endgroup$ – user8137 Mar 5 '14 at 14:32
  • $\begingroup$ you are welcome. Please keep me post in the progress of your project, thanks :) $\endgroup$ – lennon310 Mar 5 '14 at 14:42
  • $\begingroup$ Hi,, Its been several days but after I acquire the data I cant move on to comparing. can u pls check my other question plss dsp.stackexchange.com/questions/14906/… thank you so much! $\endgroup$ – user8137 Mar 9 '14 at 16:29

I'm afraid that there is no simple and straightforward way to solve your problem. The spectrum of the recording of chords contains too much redundant and unspecific information, so I do not think that you can base your comparison on the output of an FFT. You probably need to extract robust features which don't contain any irrelevant information. This will take quite some research effort. You should take a look at feature extraction used in speech recognition or music recognition.

  • $\begingroup$ hi thank you for your answer... It is really complicated to compare the signal with different frequency in it, im really having a hard time.. $\endgroup$ – user8137 Mar 5 '14 at 14:30

In terms of difficulty, your solution will be half-way between comparing raw FFTs and the kind of research cited by lennon310.

Chord transcription from polyphonic music recordings (fully produced songs) presents a bunch of challenges such as:

  • Notes of a chord can be spread across the time axis (for example, the lead sheet might mention a "C" chord, but the guitar player will slowly strum each note in sequence).

  • Notes of a chord can be spread across several instruments - the root note played by the bass, the fifth by a background synth and the third in the vocals.

  • The recognition system must be robust to chord inversions.

  • The system must make abstraction of the timbre of the instrument playing the chord.

  • The boundaries between chords are not known in advance.

None of these are going to be problems for you, since what you need to recognize are single chords whose start and end time correspond to the start and end of your signal, played with the same inversion structure as the template, and probably with the same octave, and with an instrument of vaguely similar timbre.

I would thus suggest the following steps:

  • One big FFT of the entirety of the recording.
  • Mapping of the FFT data to a constant-Q scale (such as quartertones).
  • If necessary, the same NNLS estimation as in Matthias Mauch's paper - to emphasize fundamentals and attenuate harmonics - with a parameter $s$ (decay of the template harmonic combs) fine-tuned for the guitar. This gives you a vector akin to a "piano roll" slice.
  • Comparison (by mean of scalar product) between the resulting vector and the template.

In particular, there is no need to use chroma features, since this would neutralize transposition/inversions errors that you might want to identify.

  • $\begingroup$ Hi, thank you for a very informative answer... Since I record all of the sound i need to compare to the signal that will be acquired I think the error that I will get will be lessen. In the strumming factor I note that the user will only strum once in the span of 4 sec.. so how about i get the most dominant frequencies then compare to my raw files? $\endgroup$ – user8137 Mar 9 '14 at 17:15

For each note, a guitar produces a mix of overtones that changes over time. The composite spectrum of multiple notes in a chord isn't likely to match that produced by another guitar strummed by a different person, so a simple FFT matching procedure will have some (perhaps large, depending on your matching method) probability of failure. Thus the need to look at research paper on the topic, and see if the test conditions and goals of the research suitably matches the requirements of your project.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.