Frequency Measurement of a .wav file with an Arduino Uno and a SD-Card

Hello everybody!

I need your help with programming a digital tuning device for an acoustic guitar. What I have done so far: I recorded the sound of the low E of a guitar with my computer microphone. Using LTSpice, I included the .wav-file into the circuit and transformed the audio file into a square wave file. I converted the output of the circuit into a .wav-file again and stored it on a SD-Card. Now I want to do a frequency measurement of the .wav file with an Arduino Uno. I already wrote a small sketch that reads the SD-Card file and creates a .txt file out of it. Is there any way to use freqcount on a .txt file? Or are there different ways to read the .wav file and measure it's frequency with different libraries or codes?

I am really hoping for your help!

Greetings

What is "freqcount"?

How is this going to tune a guitar, exactly? You record the sound, open it in LTSpice, modify it, save it, run some file conversion on it, put it on an SD card, move the SD card to an Arduino... oh, I see, my string is flat.. okay turn it up a little bit. Record the sound, open up in LTSpice, modify it, save it.. etc etc.

Isn't this going to take all day to tune the guitar?

Yes, of course there are ways to measure frequency. All of them are fundamentally just math procedures. How much online research have you done about that? Have you googled, "frequency measurement algorithm" or "frequency measurement arduino" or anything like that?

Why did you make a square wave from it? Were you hoping to just measure the period, edge to edge and calculate frequency from 1/period? If so, what was the outcome? If not, why not?

Freqcount is a library that allows you to measure the frequency of a signal on a certain pin.

Yes, I know that this is very cumbersome. But it is a project for University. Of course it would be way easier to realize the project analog, but due to corona virus we can not enter the laboratories of our university. Thus, we need to realize our projects at home digitally.

Then why not use Freqcount? It is probably open source, go look at how it works. Also, how much research have you done so far?

Yes, I have spent a lot of time trying to google my problem. Unfortunately I cannot find any post that explains how to measure the frequency of a .wav or .txt file. The only things I found are projects that connect a microphone to a pin and use freqcount to measure the frequency of the voltage on that special pin.

Yes, I was hoping to measure the period from falling edge to falling edge. But as already mentioned, I don't have a voltage-signal that I can put on a certain pin. I only have .txt or .wav files, and I don't know how to connect this files with a pin.

So look at the source code for Freqcount, and just replace the analog input with data from the SD card. Don't do the square wave conversion.

lr2806:
Yes, I have spent a lot of time trying to google my problem. Unfortunately I cannot find any post

So, instead of consulting learned engineering and mathematical sources (which are abundant on the internet), you're content with surfing forums?

If you manage to adapt Freqcount to read from the SD, and at the end you have no idea how Freqcount works (let alone how other methods might work), how much have you learned? Apart from a little Arduino programming?

Thank you very much for your answer.
FreqCount for arduino uno counts the frequency of pin 5 of the arduino board. But I already connected the ethernet shield (in order to read the SD-Card) with Pin 5 of the arduino board. The pin of the ethernet shield that I connected with Pin 5 of the arduino is responsible for SD-Card registration. Is it still possible to do freqcount on pin 5 then?

Actually, consulting this forum was the last resort I knew to help myself. I wouldn't be asking if I hadn't done enough research to be sure that there is nothing that could help me solve my problem.

lr2806:
Actually, consulting this forum was the last resort I knew to help myself. I wouldn't be asking if I hadn't done enough research to be sure that there is nothing that could help me solve my problem.

Where did you look? I did a search for "guitar frequency measurement arduino" and got at least several pages of promising links. Even some threads on this forum.

lr2806:
Thank you very much for your answer.
FreqCount for arduino uno counts the frequency of pin 5 of the arduino board. But I already connected the ethernet shield (in order to read the SD-Card) with Pin 5 of the arduino board. The pin of the ethernet shield that I connected with Pin 5 of the arduino is responsible for SD-Card registration. Is it still possible to do freqcount on pin 5 then?

Is Freqcount really suitable for analog signals? Did you look at the source code like I suggested? Or no?

I tried searching for "frequency measurement arduino .wav file" "freqcount arduino .wav file" "freqcount arduino .txt file" and so on. I might have opened a hundred tabs today, but all of them were explaining how to do frequency measurement with analog signals. But none of them had a similar problem (using .wav files as an input). Freqcount counts the pulses of an analog voltage signal.

That is kind of like wanting to paint a car pink and purple, so you go and try to find instructions on "painting a car pink and purple". Of course, you find nothing so you give up and complain that you can't find help.

Alternatively, you can easily find all kinds of instructions on how to paint a car, where to buy pink and purple paint and so on. It's not challenging to imagine how to apply the paint selectively (perhaps you need some information on "masking" too, but that's out there also).

Your professors might want to see that you can put a few existing ideas together into something new.

See?

Freqcount counts the pulses of an analog voltage signal.

Wrong. From the first page of the Freqcount home page:

FreqCount requires the input frequency as a digital level signal on a specific pin.

The FreqCount library counts the number of rising edges over some time interval. This isn't a great way to measure the frequency of a guitar string because, while the string is resonant at the fundamental frequency, it typically will also contain overtones as well. One can demonstrate this by plucking the string at it's midpoint (12th fret) which emphasizes the fundamental and note the difference in tone compared to plucking the string near the bridge which generates more overtones. That is, plucking the low E string (E2 / 82.41 Hz) produces some linear sum of E2 and overtones E3, E4, . . . If one simply counts edges, there are likely to be more than one would expect from E2 by itself.

A more robust approach is to use autocorrelation on the analog signal as was explored on this thread and the links therein.