Teensy or Arduino; FFT or YIN? frequency detection project

Pick one up and try it.

A $7 experiment would seem worthwhile. Or try it out in the store even. The one I have tells you the note being played, even when it is not one of the open strings.

The YIN algorithm is very powerful, able to find the fundamental even when the harmonics are much stronger.

Might be overkill for a wind instrument like a tuba?

Hello and thank you for your tips!

I have already an old chromatic tuner (maybe from 90´s) from Yamaha at home. Let’s says that in 90% of cases it works fine and it finds the first harmonic. In the remaining 10% the indicated tones jump around and it´s not possible to recognize the tone.

What do you think, what kind of algorithm did they used at that time? FFT or autocorrelation? :open_mouth:
Which algorithm is used in modern chromatic tuners?

I´m not happy with the display of commercial tuners. Therefore I want do make one with my own design and I opened this topic.

The YIN algorithm is very powerful, able to find the fundamental even when the harmonics are much stronger.

Ok, so it’s not optimized for electric guitars and basses (like described in the summary and notes here)?
http://www.pjrc.com/teensy/gui/?info=AudioAnalyzeNoteFrequency

… It could also work for other instruments?? Are there maybe some experiments?

Regarding Arduino I must repeat my question:
Is 256 the biggest FFT-size which an Arduino can do?

AdaZus:
… It could also work for other instruments?? Are there maybe some experiments?

It should work for other instruments.

If you'd like to do an experiment, I will help. Can you record a good quality sample of your tuba? If you'll post the sound clip and you're willing to allow it to be freely distributed, I'll put it into the list of sample for the NoteFrequency example. Only short sounds will fit, so please keep the sound to only 2 seconds if 44.1 kHz or only 4 seconds if 22.1 kHz sample rare.

Of course, I'll run the NoteFrequency code and post a copy of whatever it prints to the serial monitor while analyzing your sound.

Regarding Arduino I must repeat my question:
Is 256 the biggest FFT-size which an Arduino can do?

For most Arduino boards, the small memory size limits how large your FFT can be.

Teensy Audio has 1024 point FFT. But even 1024 is not usually enough resolution. YIN algorithm is much better than FFT for this purpose.

Hello Paul,
Many thanks for your offer!
What an honor to collaborate with the developer of teensy. :slight_smile:
Yes let’s make that experiment together.
Below now five different notes of the same tuba:





Question:
If Yin algorithm works fine with these examples, will it work also for other tubas?
I`m not sure because each tuba sounds a little bit different. Some sounds purer, and others have a lot of bad harmonics in their spectrum.

I think I understood now the different in FFT size...
Here the analysis of BBb_Tuba_01 with 256FFTsize, 1024FFTsize and 65536FFTsize:



With 256 it`s impossible to detect the tone with the biggest amplitude.

And the second problem with FFT:
Other tones in the signal can be louder than the firs harmonic and then you can`t anymore search for the bin with the biggest amplitude.

Hello me again,
Another difference between Arduino and Teensy is the number of IO pins.

Arduino has 14 pins.
Teensy has 34 pins.

It`s possible to connect this Microphone break out board to teensy or are there any restrictions?:

SparkFun Sound Detector

I like it because of the different output modalities. Also because it`s possible to change the gain easily with a potentiometer.

https://learn.sparkfun.com/tutorials/sound-detector-hookup-guide

I added your 5 clips to the NoteFrequency example.

Here are the results NoteFrequency prints to the Arduino Serial Monitor.

Bbb_tuba_1

Note: 59.69 | Probability: 0.99
Note: 59.42 | Probability: 0.98
Note: 59.82 | Probability: 0.96
Note: 59.58 | Probability: 0.96
Note: 58.97 | Probability: 0.93
Note: 59.09 | Probability: 0.95
Note: 58.94 | Probability: 0.99
Note: 59.15 | Probability: 1.00
Note: 59.22 | Probability: 1.00
Note: 59.29 | Probability: 1.00
Note: 59.07 | Probability: 1.00
Note: 59.16 | Probability: 0.99

Bbb_tuba_2

Note: 56.83 | Probability: 0.98
Note: 56.53 | Probability: 0.99
Note: 56.62 | Probability: 1.00
Note: 56.73 | Probability: 1.00
Note: 56.72 | Probability: 1.00
Note: 56.51 | Probability: 1.00
Note: 56.47 | Probability: 0.99
Note: 56.46 | Probability: 1.00
Note: 56.38 | Probability: 1.00

Bbb_tuba_3

Note: 53.73 | Probability: 0.96
Note: 53.36 | Probability: 0.99
Note: 53.25 | Probability: 0.99
Note: 53.19 | Probability: 0.99
Note: 53.22 | Probability: 1.00
Note: 53.01 | Probability: 0.98
Note: 52.81 | Probability: 1.00
Note: 53.02 | Probability: 0.99
Note: 53.16 | Probability: 0.96
Note: 52.81 | Probability: 0.98
Note: 53.01 | Probability: 0.98
Note: 53.16 | Probability: 0.99
Note: 52.11 | Probability: 0.95
Note: 54.71 | Probability: 0.88
Note: 53.80 | Probability: 0.93
Note: 53.48 | Probability: 0.97

Bbb_tuba_4

Note: 53.73 | Probability: 0.96
Note: 53.36 | Probability: 0.99
Note: 53.25 | Probability: 0.99
Note: 53.19 | Probability: 0.99
Note: 53.22 | Probability: 1.00
Note: 53.01 | Probability: 0.98
Note: 52.81 | Probability: 1.00
Note: 53.02 | Probability: 0.99
Note: 53.16 | Probability: 0.96
Note: 52.81 | Probability: 0.98
Note: 53.01 | Probability: 0.98
Note: 53.16 | Probability: 0.99
Note: 52.11 | Probability: 0.95
Note: 54.71 | Probability: 0.88
Note: 53.80 | Probability: 0.93

Bbb_tuba_5

Note: 48.84 | Probability: 0.91
Note: 48.68 | Probability: 0.95
Note: 48.72 | Probability: 0.93
Note: 48.82 | Probability: 0.93
Note: 48.78 | Probability: 0.92
Note: 48.56 | Probability: 0.97
Note: 48.56 | Probability: 0.96
Note: 48.52 | Probability: 0.96
Note: 48.61 | Probability: 0.98
Note: 48.64 | Probability: 0.99
Note: 48.73 | Probability: 1.00
Note: 48.89 | Probability: 0.99
Note: 49.16 | Probability: 0.99
Note: 49.29 | Probability: 0.98
Note: 48.58 | Probability: 0.87

Hello,
many thanks for the collaboration!

It looks very good!

Would it be possible to make further tests for verification?

I have 13 more recordings:

I named it with German note name, than American note name and at the end the Frequency measured manually with AudaCity Frequencyanalysis.

Example:
,C_C1_33Hz

AdaZus:
Would it be possible to make further tests for verification?

I have 13 more recordings:

Perhaps you could test these 13 files with a Teensy 3.2 board?

Hey I have purchased a Teensy 3.2 and other components for my projects. :slight_smile:

I’m glad and curious if all will work as I want.

Great. Did you try running File > Examples > Audio > Analysis > NoteFrequency yet?

Hi I tried to upload “NoteFrequency” to Teensy, but it returns the error that the sketch uses to much space: :confused:

Arduino: 1.6.5 (Windows 7), TD: 1.29, Board: "Teensy 3.2 / 3.1, Serial, 48 MHz optimized, German"
Sketch uses 262,228 bytes (100%) of program storage space. Maximum is 262,144 bytes.
Global variables use 21,416 bytes (32%) of dynamic memory, leaving 44,120 bytes for local variables. Maximum is 65,536 bytes. …..

Why that? Do I have maybe to change something in proprieties?

After that my next step will be to figure out, how to connect this microphone

and how to change the “NoteFrequency”-sketch in order to record from an analog input... :slight_smile:

Update to the lastest audio library. It fixes this problem. You update, you can grab the latest code from github, or install Teensyduino 1.30-beta4 which has the updated code.

Hi I update to 1.30 beta. It works well now. Thank you for support.
I recognize also that you put my tuba recordings to the examples.
Wow, that’s very cool!
:slight_smile:

Good.

I'm curious to hear how it works for your other sounds.

This note frequency detection question comes up occasionally on this forum, and rarely is the really good answer, so if you can let everyone know how this works, might help others in the future....

Hi,
no problem! As soon as I have some results I will post them.

I started with some research this evening but for me it`s not clear if I need 16bit audio bit depth for “NoteFrequency”-YIN algorithm or if 10bit of Teensy analog input are enough?

Have you read the workshop/tutorial manual, or watched the 48 minute video?

When you understand how to use the design tool, hopefully you'll see it has a ADC object you use to get the signal into the audio library.

Please, do yourself a favor and watch the video to learn how to use the design tool. I put a lot of work into that tool to make this so much simpler and easier for you and everyone who uses this audio library.

Hi I did a first test (without connecting the microphone, only with “wav2sketch”) with one of my other tuba recordings:
First test = positive. 110Hz as expected:

tired now..
:sleeping:

Hi,
finally I had time to test the 13 tuba files I mentioned some posts before :
Below you can download the wav-files I have tested, the wav2sketch files (renamed), a screenshot of serial monitor of any note and the Arduino sketch for Teensy.

Everyone can use these files ad lib.

In general the note detection works well. Sometimes there are some exceptions like on "Tuba_98_G2":
G2 has exactly 97,998 Hz
If I measure with smartphone app "gStrings" I get 97,5Hz.
With Teensy the frequency switches between 96,78Hz and 99,15Hz (With 3 exceptions: 32.71Hz, 110.56Hz and -10.94Hz).
Maybe later I will filter the values through probability and/or I will average them…

Yes Paul it`s clearly evident that you put a lot of work in it. Now I´m only at beginning and I will go on with studying your documentations and postings.

I'm not at all keen on FFT with arduino, as by its nature it is rather a fat algorithm which works best with lots of sample points and several times as much memory as holds them all at once. I rather think that a counter-timer would better suit the arduino, and that you might want to read a bit about interrupts. I rather think that the low pass filter which you might need to avoid triple-blipping waveforms and comparable nastiness, particularly violin, should be changed according to the initial estimate from the counter timer.

Audacity on a pc with many MB of RAM can do FFT quite well

I see that you might have 262kB, and have 44kB for local variables. Whilst that is rather a lot to a 1980's bloke, I think that it still looks small for a heavily parallel algorithm such as FFT.