Calculating fundamental frequency from FFT and storing it as a variable.

Hello all. I've been toying around with the idea for a project, and I am not sure how to do it. What I want to do is take an input signal from a bass or guitar, find the fundamental frequency of it, and then store that as a variable.

I've been reading up on a lot of posts here and other places about autocorellation and FFTs, and I don't know if my programming skills are strong enough yet to tackle it, so I've been looking at the code people have posted. I've learned a good amount but I'm not there yet.

So far, this (http://www.instructables.com/id/Reliable-Frequency-Detection-Using-DSP-Techniques/) seems to be the best one I've found. But I don't know how to modify it to take the results in from one of the pins, and then store the dominant frequency as a variable. Can anyone give me some assistance?

I think that you're asking how to fill an array with analog samples, suitable for some sort of frequency estimation, taken from an audio signal. Is that right?

What have you done so far?

The frequency content of a real sound changes thorough the duration of the note. The fundamental frequency is not always the biggest or the lowest frequency that you measure.

Use the YIN algorithm, not FFT.

http://www.pjrc.com/teensy/gui/?info=AudioAnalyzeNoteFrequency

Sorry for the late reply, with the holidays and such, I haven't had the time to check the replies.

tmd3:
I think that you're asking how to fill an array with analog samples, suitable for some sort of frequency estimation, taken from an audio signal. Is that right?

What have you done so far?

Nothing besides speculating how it would be done. I haven't done much in the way of Arduino programming, but I am pretty competent in programming otherwise. If I could figure out how to identify those frequency values, I'd be able to sustain myself from there.

Grumpy_Mike:
The frequency content of a real sound changes thorough the duration of the note. The fundamental frequency is not always the biggest or the lowest frequency that you measure.

If you play a note on a guitar, what is the main note that you hear? Is it mostly the loudest one, or the lowest one, or some 50/50 combination?

Thank you. I looked up the paper that the YIN algorithm came from, but didn't fully understand it. I'll check these out.

you play a note on a guitar, what is the main note that you hear? Is it mostly the loudest one, or the lowest one, or some 50/50 combination?

The combination of harmonics changes through the duration of the note. The change is different for each different note. You can not just pick one. This is why it is so hard to do. Try and understand the YIN algorithm, note it is not perfect and it will give you false values some of the time.

secretempire1:
If you play a note on a guitar, what is the main note that you hear?

It's certainly not necessarily the loudest one. You might want to read the Wikipedia articles on "pitch" and "missing fundamental" for an understanding of how we interpret musical sounds. The relationship between frequency - a physical property - and pitch - a perceived property - can be complex.

secretempire1:
What I want to do is

  • take an input signal from a bass or guitar,
  • find the fundamental frequency of it, and then
  • store that as a variable.

Because you tell us this:

... I am pretty competent in programming ...

I'll presume that you don't need any help storing a result. I think that you're looking for help with the other two tasks on your list: collecting analog samples from an audio input, and processing those samples to estimate the frequency of the audio signal.

Collecting samples has elements of hardware design and programming, while processing those samples is strictly programming. If you start with the task of processing samples, you can go a long way toward your goal without having to design hardware, by processing calculated analog values as opposed to analog values acquired from an audio input. Designing the hardware interface between the Arduino and the audio signal will require a fairly thorough understanding of the characteristics of the input hardware. Whichever task you tackle first, you'll want to use calculated values for testing the algorithm that estimates frequency, so that you can easily predict the correct results. Ultimately, though, you'll have to get both tasks working to make this project work.

I think that your project is achievable with an Arduino Uno, or maybe some derivative. But, it's certainly not trivial.

Which task do you want to tackle first?

Grumpy_Mike:
Try and understand the YIN algorithm, note it is not perfect and it will give you false values some of the time.

No algorithm is perfect. Neither are human ears & brains.

But the YIN algorithm gives very good results.

The main problem is it needs a lot of CPU power. It uses nearly all the CPU power of a Teensy 3.2 at 96 MHz to run it. 8 bit AVR (Arduino Uno, Nano, etc) and even 32 bit Cortex-M0+ (Arduino Zero, MKR1000) are nowhere near fast enough to run the YIN algorithm in real time for live signals.