# Pitch Detection on Arduino using Autocorrelation

This is the ninth part of the article about the Arduino Pitch Detector. On this page, I will see how well the algorithms did.

## Verification

The testing methodology reflects the three design criteria.

1. To test the frequency and pitch detection, I used clarinet and monophonic piano samples from the University of Iowa Electronic Music Studios. The measured frequencies were corrected for transposing instruments such as the clarinet and then written to the debug port, and then imported into a spreadsheet for further evaluation.
2. For note level segmentation, I used commercial solo clarinet recordings such as “Sean Osborn, A Set for Clarinet Allegro”. The algorithm was verified by reading the piano roll output on the device and by listening to the output of the MIDI synthesizer.
3. To measure the delay between the note being played and being recognized, I edited the code adding a timer. I measured the delay between audio input and MIDI output.

While testing different algorithms, I found it very helpful to always use the same test set. I added configuration options that allows the device to read input from the memory card, and write the frequency and pitch detected to the debug port.

### Input

Instead of taking input from the microphone, the audio samples will be read from μSD card. This replaces the first two components of the signal path with samples read from .wav files. The module sddir.cpp expects top level directories “NOTES” and “SOLOS”. The next level of directories should have the name of the sample rate (e.g. 9615). From there it will recurse the subdirectories and open each .wav file found. The module wave.cpp parses the TLV fields in the .wav file, and stores the samples in an array.

The frequency detection and segmentation algorithms can be tested independently.

### Frequency and pitch detection

I use instrument samples from the University of Iowa Electronic Music Studios supplemented with my own.

• For example, for a clarinet sampled at 9615 S/s, store 8-bit mono PCM wave files in the directory “NOTES/9615/CLARINET/“. The file name should be the official note name such as DB4.WAV for D♭4.
• Edit config.h, so that it takes input from FILE and writes to the SERIAL port. The output can then be imported into a spreadsheet for further evaluation. These results are presented in the conclusion of this article.

### Note level segmentation

• The algorithm is considered correct, when it tracks the pitch correctly and the melody of the original file has not been modified. The following test sets have been identified:
1. Monophonic music segmentation dataset (CMMSD) [Coler, 2014]
• A new data set with annotations for monophonic audio excerpts. Annotations for note (steady state, sustain), transition (transient, release), and rest (silence, noise, reverberation). The data set consists of 36 items, excerpts of commercial recordings of solo performances of classical music. It covers the instruments bass, bassoon, cello, flute, horn, oboe, trombone, trumpet, and violin, and spans several periods of time in history.
2. Various solo clarinet recordings
• Ernesto Molinari, Charme (pour clarinette) (amazon.com)
• Sean Osborn, A Set for Clarinet Allegro (amazon.com)
• Sean Osborn, A Set for Clarinet Adagio (amazon.com)
• Traditions of Excellence, book 1, page 38, exercise 4 on DVD (amazon.com)
• To transcribe the music using the Arduino, store the recordings as 8-bit mono PCM wave files to SD card in the directory “SOLOS“. Remember to obey the 8.3 file name convention.
• Edit config.h, so that it takes input from FILE and writes to PIANOROLL. This will also output MIDI events. Verify by either comparing the generated MIDI piano roll to the original score, or listening to the synthesizing MIDI events and comparing it to the original performance.

Student at MVHS
I see education as the foundation upon which entrepreneurs are able to build innovative organizations and execute their vision for the future.

## 4 Replies to “Pitch Detection on Arduino using Autocorrelation”

1. Brecht Humasol says:

Hello,

I want to know the frequency of the power grid, but harmonic frequencies in the power grid are a huge problem.
Can you send me a code for ‘filtering’ fundamental? (0-150Hz max)
Thanks!

2. achala says:

great works !!!

3. Romain says:

Hello,

First of all, this a great work ! Not only just a sample stuff but very documented, you shoudl be proud !

I’d like to use it for a guitare. Do you think it will work ? Did you test it ?

Finally, did you make a video of it to see how good it works ? :)

Thanks for the sharing and keep having fun making all these things :)

4. Denis Bélières says:

Hello. Bravo for this work …
I am a retired electronic engineer, and I designed a tuner working with FFT on a PC with a professional tool : Labview from National Instrument, which offers huge signal processing libraries. I wanted a very precise instrument to tune the reeds of a vintage italian accordion (Paolo Soprani, 1915). I am also playing bassoon, and then concerned with bass notes. I encountered many difficulties with low frequency cut off of the microphones, giving signals with harmonics far higher than fundamental (up to 20 dB). The lowest note of my accordion is a Bb at 58.27 Hz, on the left hand chords. This is also the lowest note of the basson. Precise measurement need very long sampling of several seconds !
Well, now, I want to buid a little funny gadget which will animate a “snake” poping out of a basket in relation with the recognised notes … I am very interested by your work, but I think i will use a more powerfull processor than the Arduino uno, and then higher sampling frequency and 500 or 1000 samples.

This site uses Akismet to reduce spam. Learn how your comment data is processed.