Teensy or Arduino; FFT or YIN? frequency detection project

Hello forum,
I need your help choosing the appropriate hardware and software for my project.
I want to make an electronic tuner for low-pitched range music instruments (ca.70-280Hz).
(It doesn´t need to work superfast or instantly. A output value every 0,5sec or 1sec should be enough.)
Accuracy: 1Hz

Until now I found a lot of material regarding the microcontroller TEENESY:
https://www.adafruit.com/product/2756
Fun with FFT:

There are a lot of libraries for sound
http://www.pjrc.com/teensy/td_libs_Audio.html
especially that one, that seems predestinated for my project:
http://www.pjrc.com/teensy/gui/?info=AudioAnalyzeNoteFrequency
(YIN algorithm)

What I´m not sure… there is written:
“…will allow you to detect with fairly good accuracy the fundamental frequencies from electric guitars and basses.

Does this mean that it will not work properly with other instruments such a tuba for example?

On the other hand I found also material regarding ARDUINO:
Arduino FHT Library.
http://wiki.openmusiclabs.com/wiki/ArduinoFHT

To get a clean signal I could insert a RC filter or a software filter from Arduinos libraries (lowpass filter: 0-300HZ pass).
Than I would use a sample rate of 600Hz…
FFT size: 256 (It`s possible to choose also a bigger one with Arduino?)
(600/2 )/ (256/2) =2,34Hz accuracy only. :confused:

What do you recommend?:
The for me a little bit familiar Arduino or the powerful new Teensy?
What is better for my application FFT or YIN?

Best regards ::slight_smile:

Hello me again… I have found an instructable where autocorrelation for Arduino was used.

Seems very simple and also precise. What do you think?

Pick one up and try it.
http://www.guitarcenter.com/search?typeAheadSuggestion=true&typeAheadRedirect=true&Ns=r&Ntt=chromatic+tuner
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.

https://forum.pjrc.com/threads/36756-Teensyduino-1-30-Beta-4-Available

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: