# Maximum sample rate of Arduino Duemilanove?

G'day all!

I have an Arduino Duemilanove hanging around spare at the moment and thought I might try a few audio interfacing projects. I'm just wondering what sort of sampling frequency I can achieve using a single analog input and applying some simple algorithms on chip, then reporting using a few digital outputs tied to LEDs.

I'd like to sample in at ~44.1 kHz if possible.

For reference the first thing I want to try is a simple guitar tuner.

• Oops - it's the ATMega168 version. Nov 30, 2009 at 3:05
• @Sketchy you can edit you question if you need to, rather than adding detail in a comment. Nov 30, 2009 at 3:38
• For guitar tuners, there are a number of questions on stackoverflow about frequency estimation. stackoverflow.com/questions/65268/… I've answered a bunch of them and posted sample code for some methods here: gist.github.com/255291 Apr 27, 2010 at 21:15

I don't think you can sample that fast at full resolution. The ATMega168 can only sample at 15 ksps at its full resolution.

Having said that, you should be able to get a suitable sample rate to get a functioning guitar tuner. 44.1 kHz is most likely a fair bit faster than you will need given that the fundamental of the high E string an a guitar is around 330 Hz.

• Brilliant - that answers my question handily. I didn't think the 168 would be capable of full human audio spectrum sampling, but if I can get a sample rate of at least 660 Hz I should be able to identify the high e string with no aliasing. I'll bump that up a bit for safety and sensibility though. Thanks! Nov 30, 2009 at 4:26
• The phone system samples at 8000 Hz. Jul 14, 2010 at 21:34

Rob.

Google for 'AVR guitar tuner', there are a couple projects out there that do this already, and they seem to be able to do it without too much trouble with the speed of the AVR.

If you use an analog comparator (either the internal one in the AVR or an external opamp one) that turns the analog input into a square wave, you can sample oscillations at much higher speeds. While this isn't true audio sampling, for building a guitar tuner it's often all you need since all your code would be doing anyway would be counting zero crossings per unit time.

• My concern, I think, is that you really need to run an FFT to pick out the fundamental. Guitars produce all kinds of frequencies when a string is plucked, and counting the zero crossings only gives you enough information to construct a square wave, making an FFT pretty thoroughly useless. Nov 30, 2009 at 15:35
• Single-note guitar output (especially electric) is a close approximation of a sine wave, once you get past the initial transient. No weird harmonics anywhere near the amplitude of the fundamental. All cheapie digital guitar tuners just do zero-crossing timing and don't do anything in the frequency domain. Here's one example of the technique on an AVR 2323 (close relative to Arduino) myplace.nu/avr/gtuner/index.htm and here's another using the Arduino with MIDI out youtube.com/watch?v=oGKE1vmAWCA Nov 30, 2009 at 21:57
• I don't think guitar tuners count zero crossings, and this certainly isn't a good method. It ain't even close to a sine wave, and there can be many zero crossings per cycle: flic.kr/p/7ns9nu Apr 27, 2010 at 21:12
• The tuners I've seen had a low-pass filter to turn the input signal as much into a sine wave as possible. Apr 28, 2010 at 4:21

There are a number of ADCs available that are serial, I2S is NXP's standard based on I2C. They allow you to pretty easily pull in analog even at much higher speeds. This link should get you to an NXP part that is designed for audio: UDA1361TS

Free samples are your friend :)

• Thanks very much! That's gonna be a bit more than I need to get a simple tuner going, but that chip looks perfect for some of my future projects. I'd eventually like to get a simple inline DSP deck going to experiment with effects processing. Thanks! Dec 1, 2009 at 2:43

First, for your particular application, you really only need 1 kHz or so sampling rate, assuming you're tuning the fundamental frequency and not one of the inharmonic partials...

Anyway, as for the maximum possible sampling rate, the Arduino manual says:

This would imply 10 kHz sampling frequency is the max. However. You can get higher sampling rates by accessing the ADC registers directly. The Arduino Realtime Audio Processing page uses two channels at 15 kHz, for instance. So the 10 kHz max is only while using the built-in AnalogRead() function, because it has a lot of overhead.

The ADC is optimized for best operation with a clock speed of between 50 kHz and 200 kHz:

By default, the successive approximation circuitry requires an input clock frequency [ADC clock] between 50 kHz and 200 kHz to get maximum resolution.

Since an ADC conversion takes 13 clock cycles, this would be a sampling rate of 4 kHz to 15 kHz. According to AVR120: Characterization and Calibration of the ADC on an AVR:

For optimum performance, the ADC clock should not exceed 200 kHz. However, frequencies up to 1 MHz do not reduce the ADC resolution significantly.

Operating the ADC with frequencies greater than 1 MHz is not characterized.

1 MHz clock frequency = 77 kHz sampling frequency, so that's the realistic max.