11
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ Oops - it's the ATMega168 version. \$\endgroup\$ Commented Nov 30, 2009 at 3:05
  • 4
    \$\begingroup\$ @Sketchy you can edit you question if you need to, rather than adding detail in a comment. \$\endgroup\$ Commented Nov 30, 2009 at 3:38
  • 1
    \$\begingroup\$ 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 \$\endgroup\$
    – endolith
    Commented Apr 27, 2010 at 21:15

8 Answers 8

15
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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! \$\endgroup\$ Commented Nov 30, 2009 at 4:26
  • \$\begingroup\$ The phone system samples at 8000 Hz. \$\endgroup\$
    – joeforker
    Commented Jul 14, 2010 at 21:34
8
\$\begingroup\$

It takes about 100 us (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.

http://arduino.cc/en/Reference/AnalogRead

Rob.

\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented Nov 30, 2009 at 15:35
  • \$\begingroup\$ 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 \$\endgroup\$
    – todbot
    Commented Nov 30, 2009 at 21:57
  • \$\begingroup\$ 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 \$\endgroup\$
    – endolith
    Commented Apr 27, 2010 at 21:12
  • \$\begingroup\$ The tuners I've seen had a low-pass filter to turn the input signal as much into a sine wave as possible. \$\endgroup\$
    – todbot
    Commented Apr 28, 2010 at 4:21
3
\$\begingroup\$

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 :)

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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! \$\endgroup\$ Commented Dec 1, 2009 at 2:43
2
\$\begingroup\$

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:

It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.

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.

The forum thread Faster Analog Read? has more about this.

\$\endgroup\$
0
\$\begingroup\$

The on-chip converter will work for this application as others have pointed out, but you should really look into using an external ADC. This will save you a lot of trouble, and free your micro to sample over SPI or I2C at much, mich higher data rates, with less noise from the micro's clock, and with greater precision than using the internal ADC. If you want more resolution and/or a higher data rate, then use something like the LTC1867 , which will let you sample at up to 175kHz (Although you can clock it however quickly you want to) and then read out the 24-bit data at up to 20MHz over SPI. See what a real ADC can do? :) With that kind of power (And a 24- or 32-bit DSP), you can compress and store your audio, filter it, modulate it, play it back... the possibilities are endless.

\$\endgroup\$
0
\$\begingroup\$

Are you interested in a 64K sampling rate? Have a look here

Now raised to 150 kHz, 10 bits, no additional components!

Have a look there

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.