## Solved: FFT for guitar tuner on EVK1104

8 posts / 0 new
Author
Message

Hello! I'm a new member!

So, I have an EVK1104 with AT32UC3A3256S microcontroller. I must build a guitar tuner with that, so I need to do a FFT into microcontroller to get fundamental frequency. The microphone that I use is MAX9814.

Guitar note has this frequency range: 0-1000Hz. I want to get foundamental frequency with 1 Hz resolution (maybe I should use 4096 samples).

There is any library that can help me? Or anyone can give me any advice?

Last Edited: Sat. Mar 25, 2017 - 01:10 AM

sabruri1 wrote:
Guitar note has this frequency range: 0-1000Hz

Of-course not. If you want to detect 0 Hz you will have to wait for an eternity. Literally. (And I'd be amazed if you could have the microphone pick up, and the firmware to detect, low single digit frequencies (a few Hz).

The low B0 on a five-string bass guitar is something like 30 Hz. The lowest frequency on an ordinary six-string guitar (the E2, sixth string open) is about 82 Hz.

The high E string (first string open, a k a E4, is roughly 329 Hz. 12th fret of that (i.e. the E5) is (of-course) the double or about 659 Hz. Assuming your guitar goes to 22nd fret then that will be a D6 or 1175 Hz. It just might be interesting to check the tuning there, e.g. for purposes of adjusting the intonation of the guitar - but then you'd likely want sub 1 Hz resolution and accuracy.

All this assuming "standard tuning". I quoted all those notes and frequencies from here: https://www.seventhstring.com/re... , and hope I got everything right..

Speaking of accuracy, I see no mention of it at all in your post. Since you formulated yourself "must build a guitar tuner" I'm sort of assuming that you "must" do this as a school assignment. If so, then pick up some extra points by not only discussing resolution but also accuracy in your hand in report. :-) (I.e./e.g. you can display frequencies with "1 Hz significance" all you like, but it won't be much good if all measurements are actually off by 5 %... The "off by" is the (in-)accuracy.)

Apart from this, I'm sorry I'm not an AT32 user, so can't give much insight on the actual implementation. But I do play the guitar (sloppily ;-) ) and tune up two or three guitars most every evening. Any decent guitar player who knows the "quirks" of his instrument(s) (all instruments have them "quirks") can tune all strings to a fraction of a Hz given he's got one string (e.g. fifth, or A2) is tuned right (i.e. to 110 Hz). Interference is the key (pun intended!) to managing that. If you want more discussions of guitar tuning practices to go into a discussion in your report then just ask!

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Wed. Mar 22, 2017 - 08:42 PM

JohanEkdahl wrote:

Of-course not. If you want to detect 0 Hz you will have to wait for an eternity. Literally. (And I'd be amazed if you could have the microphone pick up, and the firmware to detect, low single digit frequencies (a few Hz).

Yes, you are right! I can restrict Hz range into: 30Hz - 1175Hz.

JohanEkdahl wrote:

Speaking of accuracy, I see no mention of it at all in your post. Since you formulated yourself "must build a guitar tuner" I'm sort of assuming that you "must" do this as a school assignment. If so, then pick up some extra points by not only discussing resolution but also accuracy in your hand in report. :-) (I.e./e.g. you can display frequencies with "1 Hz significance" all you like, but it won't be much good if all measurements are actually off by 5 %... The "off by" is the (in-)accuracy.)

It's a university project. I do not get high accuracy. Tuner accuracy is not the exam's target.

@JohanEkdahl thanks for all your details.

So, I still need to know how to get fundamental frequency into 30 - 1175 Hz range from microphone (MAX9814). Someone can help me ?

Suppose you know about FFT, windowing, etc before you attempt your implementation?

In terms of uC libraries, I know (I used) a fixed-point fft implementation for avr-gcc that may be portable on your controller (not an AT32 user either). I am in transit now and can't provide the link but google can help you.

The MAX9814 is NOT a microphone.....it is a microphone pre-amp.

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

sabruri1 wrote:
It's a university project.

So the University expects you to do it - yourself.

So, I still need to know how to get fundamental frequency into 30 - 1175 Hz range from microphone (MAX9814). Someone can help me ?

Surely, that is a fundamental part of the exercise that you need to do - yourself ?

You need to get down to your university library and start reading-up about the FFT and how to implement it. This is not new; it is well covered in The Literature.

Of course, there is also plenty of information available online these days ...

If you really can't do this, then you should be speaking to your tutors - urgently.

Bluffing the test is not going to help you - it will just leave you further behind as the course progresses.

I must build a guitar tuner with that, so I need to do a FFT

No, you don't need an FFT.

A typical guitar has only 6 strings; so there are only 6 frequencies you actually need to detect - aren't there ... ?

Try googling for old projects where this was done either without any microcontroller at all, or with something basic like an 8051 where an FFT might not have been practical ...

The microphone that I use is MAX9814

That's not a microphone - that's just an amplifier!

Top Tips:

1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...

If you only need freq of the tone with most energy then just count peaks.

(next step would be a auto correlation near that freq. )