get the fundamental frequency

hi to all in this forum,
I have an analog signal applied to the A0 pin of my arduino. I want to get the frequency of the fundamental and possibly its amplitude.
The signal in quite similar to a sinewave but it has some distortion,
How could I do that please ?
Any help is appreciated.

Most Arduinos are not good with analog signals. Approximately what frequency and amplitude are you talking about?

If it's really close to a sine wave the fundamental is not too bad. An amplifier will convert it to roughly a square wave and you can just measure the time between edges. Amplitude is rather trickier.


even if under-sampling, you may be able to determine the frequency by monitoring zero crossings, ignoring short term crossings and determining an average time over a larger period of time.

at the same time you may be able to capture the peak amplitude, but it it probably not the amplitude of the fundamental frequency.

What is the maximum frequency of the applied signal?


the signal is the 800 to 2000 Hz range.


Run an FFT and analyze the result.

Though 2kHz is pretty near the usable limit for the A/D in 10-bit mode...

Ray L.

There's an extended thread at the link below that shows some code for pitch detection using autocorrelation techniques. This is probably a better approach for signals with harmonic content than doing a Fourier Transform and interpreting the result if there is significant harmonic content/distortion.