RE: Audio Input

Hi Gang

I need some help connecting an audio source (0.5 - 2.0Vp-p) to my Arduino UNO. I want to use minimal components to identify a low frequency tone. I've found a few articles on the subject but I was hoping someone could elaborate on the electronics?

Arduino project: Stereo Peak Program Meter

Arduino Realtime Audio Processing

Audio Input to Arduino

Attached is a common configuration comprising of just four components.

Below is what I do and don't know about the circuit.

1 x 10kΩ Resistor
Supposedly protects audio input if input exceeds 5V.
Not sure how this works?
Necessary?
Why 10kΩ?

1 x 10uF Capacitor
Block DC.
Why electrolytic?
Why 10uF?

2 x 100kΩ Resistors
DC Offset.
Voltage Divider.
Why 100kΩ?
To ensure very little current (0.03mA)?

Any help would be greatly appreciated?

Cheers

Jase :slight_smile:

audio_input.pdf (216 KB)

1 x 10kΩ Resistor
Supposedly protects audio input if input exceeds 5V.
Not sure how this works?
Necessary?
Why 10kΩ?

I would say not necessary given that you say your signal is only 2V PTP.

1 x 10uF Capacitor
Block DC.
Why electrolytic?
Why 10uF?

Electrolytic because that is the cheapest / only way to get large values. That value is right on the edge of the maximum you can get with other technologies. Why that size, well the bigger it is the more low frequencies get through so it is a compromise between keeping it small and a good low frequency response.

2 x 100kΩ Resistors
DC Offset.
Voltage Divider.
Why 100kΩ?
To ensure very little current (0.03mA)?

Yes and it also makes for a lower frequency response because the 10uF is only driving 50K so the time constant ( R times C ) is bigger and so lower frequencies. However it is also subject to more interference pick up so like so many things it is a compromise. Myself I would normally use a 1K here and put up the capacitor value.

Hi Grumpy_Mike

Thanks for getting back to me. To clarify;

1 x 10kΩ Resistor

  • Not necessary because at the node where the audio signal meets the voltage divider the voltage theoretically should not exceed 3.5V (2.5V plus 1V which is half the peak) albeit half a cycle out because of the capacitor?
  • If it is used, its purpose is to decrease the speed at which the capacitor charges? Would this not decrease the overall circuits responsiveness to frequency?
  • If it is used, it's purpose is to also decrease the current 'entering' the circuit?

1 x 10uF Capacitor

  • Having a sufficient capacity means it has the facility to charge with low frequency.

2 x 100kΩ Resistors

  • 10uF is only driving 50K?
  • Time constant? Hmmm, something to investigate.

Cheers

Jase :slight_smile:

Use the 10k - otherwise you'll easily exceed the input current safe limits of the
Arduino - when the audio source is first connected, it ifs low impedance and happens
to be -1V say, then the capacitor will pull the Arduino input down to -1V as well (it
takes time for the capacitor to charge up).

The 10k is a value thats much lower than the 100k bias/load resistors, so it won't
affect frequency response much - you could lower to 1k if you want.

The 100k's are chosen because 47k is the "standard" audio line impedance ,and two 100k's
in parallel are equivalent to 50k which is close enough.

The electrolytic cap must be the right way round, -ve terminal to the audio source.

Time constant of an RC circuit is R x C, so with 10uF and 50k load, that's 0.5 seconds, or
equivalently a roll-off starting at 0.08Hz, which is absurdly low. 220nF is plenty for the
cap into a 50k load.

In practice almost every audio device in the world can drive much lower impedances than
47k (that's a hang-over from valve electronics I suspect).

I'd recommend 1uF into a bias network of two 22k resistors, then you are driving the
Arduino analog input at a low enough impedance (11k) to meet its specs. Add a 1k protection
resistor on the input too to prevent connection transients as mentioned above.

Hi MarkT

Thanks for your reply. It appears there is a marriage between two common circuits; a resistor capacitor circuit and a voltage divider circuit. I'm unclear how they play together?

The voltage divider circuit comprises of two 100kΩ resistors in series?

I = VR
I = 5V x 200kΩ
I = 0.03mA

This doesn't seem like a lot of current?

The audio signal current would add to the above 0.03mA?

The voltage divider provides 2.5V at its junction?

If the voltage is -1V at the capacitor that will drop the above voltage to 1.5V?

The 10kΩ resistor controls the rate of charge of the 10uF capacitor?

The following I don't understand at all?

The 100k's are chosen because 47k is the "standard" audio line impedance ,and two 100k's
in parallel are equivalent to 50k which is close enough.

The electrolytic cap must be the right way round, -ve terminal to the audio source.

Time constant of an RC circuit is R x C, so with 10uF and 50k load, that's 0.5 seconds, or
equivalently a roll-off starting at 0.08Hz, which is absurdly low. 220nF is plenty for the
cap into a 50k load.

In practice almost every audio device in the world can drive much lower impedances than
47k (that's a hang-over from valve electronics I suspect).

I'd recommend 1uF into a bias network of two 22k resistors, then you are driving the
Arduino analog input at a low enough impedance (11k) to meet its specs. Add a 1k protection
resistor on the input too to prevent connection transients as mentioned above.

I do know impedance is like resistance for alternating current.

Why would there be impedance in a line?

Very confused?

Cheers

Jase :slight_smile:

From an AC point of view each power rail is at the same potential and can be considered the same point. That means those two resistors are in effect in parallel as far as an AC signal is concerned. So the signal "sees" an impedance of 50K, think of it ass a load it is trying to drive.

As you can see the use of the 10K seriese resistor is controversial wig some engineeres thinking it is useful as a protection and others seeing it as being not necessary. Given n engineeres there will always be at least n+1 firmly held opinions.

Hi Grumpy_Mike

Where are these 'power rails'? In my diagram I have one 5V source.

What is the significance of 50kΩ?

Are we talking about the junction where the two 100kΩ resistors meet?

I thought impedance only related to the capacitor not the resistors?

I think my understanding of how this circuit is working is completely wrong. In my mind there are two parts.

Voltage Divider Circuit
Current is running from the 5V source through the two 100kΩ resistors to ground. The resistors are there otherwise we would have a short. The value of the resistors is a combined 200kΩ so that only 0.03mA of current passes through. A nominal amount.

Resistor Capacitor Circuit
The 10kΩ controls the rate of charge of the 10uF capacitor. The resistor-capacitor (RC) time constant is 0.1 of a second.

Combined Circuits
The signal voltage adds and subtracts (AC) from the voltage at the voltage divider junction and specifically what is being read at the Arduino's analogue input.

Can we start afresh and someone explain in detail what is really going on?

Cheers

Jase :confused:

Where are these 'power rails'? In my diagram I have one 5V source.

and the other one is labeled ground.

What is the significance of 50kΩ?

It is what you get with two 100K resistors in parallel. The 100K resistors are the ones going to 5V and to ground.

I thought impedance only related to the capacitor not the resistors?

No impedance is measured in ohms. It can be affected by the capacitave reactance of a capacitor or inductive reactance of an inductor and also pure resistance. The final impedance is a vector sum of all three values.

The value of the resistors is a combined 200kΩ so that only 0.03mA of current passes through.

Yes that is the DC conditions, but from the point of view of an AC signal it "sees" a load of 50K because those two resistors are in effect in parallel, because as I have said before the 5V and ground are, from an AC point of view at the same potential.

The 10kΩ controls the rate of charge of the 10uF capacitor.

It is this plus the 50K load. The controlling of the charge rate is an unwanted side effect of having this resistor. Its main job is to limit the current through the diodes inside the chip if you exceed the supply rail voltages.

specifically what is being read at the Arduino's analogue input.

The 2.5V DC level set by the potential divider plus or minus the voltage from the audio signal.

Can we start afresh and someone explain in detail what is really going on?

Any explanation would only contain exactly the same information as you have been told here.

Hi Grumpy_Mike

Thanks for your patience. I’ve spent the last 24hrs thinking about your last post. So what we have are two common circuits they being a resistor capacitor circuit and voltage divider circuit. To complicate matters; the resistor capacitor circuit is AC while the voltage divider circuit is DC.

Resistor Capacitor Circuit
The 10kΩ resistor primary purpose is to limit current to the Arduino analogue pin. If we imagine the 10uF capacitor is not in this circuit then it would limit the current to just 0.1mA?

I = V/R
I = 1/10,000
I = 0.0001A or 0.1mA

Given the Arduino analogue pin has an input resistance of 100MΩ it begs the question; is it really necessary?

The 100kΩ resistors in parallel provide 50kΩ resitance combined along with the 10uF electrolytic capacitor control the rate of charge.

T = RC
T = 50,000 x 0.00001
T = 0.5s

Provided half the wavelength of the frequency I’m interested in is less than this we’re golden?

This acts as a low pass filter?

Voltage Divider Circuit
The Arduino analogue pin has an input resistance of 100MΩ. Little current can pass but it can determine voltage (similar to a multi-meter). The audio signal therefore takes the paths of lesser resistance they being the 50kΩ resistors. Adding or subtracting 1V from the 2.5V at the voltage divider junction.

Other
I was checking the specifications of the device’s audio output and noticed the audio input impedance is 10kΩ. Should I adjust my component values?

2 x 20kΩ resistors.
1 x ?uF capacitor

If I wanted to detect frequencies up to 100Hz;

100 cycles per second
0.01s per cycle
0.005s per half cycle

T = RC
0.005 = 10,000 x C
0.005 / 10,000 = C
0.0000005F or 0.5uF = C

Let me know if I'm on the right path and as always appreciate your help.

Cheers

Jase :slight_smile:

If we imagine the 10uF capacitor is not in this circuit then it would limit the current to just 0.1mA

No. It only limits current when the signal is greater that 5V or less than 0V. As you say the input current on the analogue input is very high and needs nothing to limit the current.

This acts as a low pass filter?

No, it acts as a high pass filter. Any series capacitor blocks DC and you can think of DC as an AC signal with an infinitely long period. High and low pass are just relative terms. In this case high means all frequencies above a certain value. It is those that are passed and the ones below are attenuated. Note they are not blocked altogether they are just attenuated. The further the frequency from the certain frequency the more they are attenuated.

The audio signal therefore takes the paths of lesser resistance

OK lets bang this one on the head. Taking the path of least resistance is something that electricity NEVER does, despite it being often quoted it is wrong. An electrical signal takes ALL paths available to it. More current flows through the lower resistance paths, that's ohms law, but all paths have current in them.

I was checking the specifications of the device's audio output and noticed the audio input impedance is 10kΩ.

No not quite. With a 10K impedance driving the input then the input capacitor on the sample and hold circuit before the A/D circuit in the Arduino chip has time to charge up when switching from one channel to the other. This is why I would use a 10K resistor divider instead of a 100K, but this is not as critical as you might think because the current is DC and doesn't change. Only if you want to switch the input channels would you possibly see a difference.

If I wanted to detect frequencies up to 100Hz;

What you mean here is If I wanted to detect frequencies up down to 100Hz;
Otherwise it is roughly correct and you are on the right path. It is not exactly correct because the time constant is the time it takes a capacitor to charge up to 0.6321 of the voltage it is aiming at. As a rule of thumb you can say that by 3 time constants the capacitor can be considered fully charged. Although the truth is that a capacitor is only fully charged after an infinite time. In electronics it is very often necessary to not get too picky about what the truth is. Remember there is not a cut off point, only varying degrees of attenuation.

Hi Grumpy_Mike

Thanks for your patience. I’m keen to have a good understanding of how this circuit works so that I’m able to run some numbers on it.

No. It only limits current when the signal is greater that 5V or less than 0V. As you say the input current on the analogue input is very high and needs nothing to limit the current.

The Arduino analogue pin has an input resistance of 100MΩ therefore little current can pass. I’m unsure how adding a 10kΩ resistor prevents further current (<0V or >5V) given it only provides a 1/10,000th increase in the resistance (10,000Ω vs 100,000,000Ω)? Is there something under the proverbial bonnet that I’m not aware of?

I can now see that with the capacitor is series we have in fact have a high pass filter (my bad). I found the following formula.

Cut Off Frequency (Attenuation)
f = 1/2πRC
f = 1/2π x 10,000 x 0.00001
f = 1.59Hz

It’s interesting that frequencies above 1.59Hz pass while those below are attenuated. I played with the increasing the cut off frequency to 100Hz.

C = 1/2πRf
C = 1/2π x 10,000 x 100
C = 1.59F

YIKES! That’s one big capacitor. Is that correct???

No not quite. With a 10K impedance driving the input then the input capacitor on the sample and hold circuit before the A/D circuit in the Arduino chip has time to charge up when switching from one channel to the other. This is why I would use a 10K resistor divider instead of a 100K, but this is not as critical as you might think because the current is DC and doesn't change. Only if you want to switch the input channels would you possibly see a difference

I’m not quite sure what you’re saying here? Are you suggesting that using lower value resistors (<100kΩ) in the voltage divider results in less current passing through to the analogue pin on the Arduino meaning more time to charge the ‘sample and hold’ circuit? This is a good thing? If this is the case and I use two 20kΩ resistors in parallel I achieve this along with the recommended 10kΩ impedance?

Are you also suggesting I need not get too hung up on the size of the capacitor? Provided it’s large enough to store the charge of the lowest frequency I’m interested in then I should be OK (possibly the original 10uF capacitor)?

The more I look at this the more I’m beginning to appreciate that it’s a balancing act.

As always appreciate your help.

Cheers

Jase :slight_smile:

Is there something under the proverbial bonnet that I'm not aware of?

I keep trying to tell you. I said in that last post:-

It only limits current when the signal is greater that 5V or less than 0V.

Once the input to the A/D input exceeds the supply voltage or is less than the ground voltage then the input impedance of the converter goes out of the window and what happens is the diodes between the input and the supply rail starts to conduct, this is a very low impedance so a relative large amount of current can flow. There are two things limiting the current here. The first is that 10K resistor and the second is the capacitor.

Are you suggesting that using lower value resistors (<100kΩ) in the voltage divider results in less current passing through to the analogue pin on the Arduino meaning more time to charge the 'sample and hold' circuit?

No
Lower value resistors result in more current down the resistors, meaning that the input capacitor on the sample and hold will charge faster. There is never "more time", it is faster.

This is a good thing?

Yes because this means you get the proper value with only one analogue read.

C = 1/2πRf
C = 1/2π x 10,000 x 100
C = 1.59F

YIKES! That's one big capacitor. Is that correct???

No that is not correct.
C = 1/2π x 10,000 x 100
should be
C = 1/(2π x 10,000 x 100)
C = 15.9uF

The more I look at this the more I'm beginning to appreciate that it's a balancing act.

Yes that is it.

Hi Grumpy_Mike

Thanks again. This simple circuit belies something far more complicated that has a number of factors to consider. I therefore put together a spreadsheet (see attached) to test various combinations of capacitors and resistors.

If I use a 10uF capacitor along with a pair of 20kΩ resistors (parallel 10kΩ) I can achieve close to 10kΩ impedance. As you suggested in an earlier post, this would allow the input capacitor to charge quickly on the sample and hold circuit before the A/D circuit in the Arduino chip.

In addition, it would mean the circuits impedance would match that of the device's audio I'm trying to interrogate. How important is impedance matching?

Audio Device Specifications
Audio input impedance: 10kΩ
Audio input level: 0.5 - 2.0Vp-p

You mentioned earlier that this is a high pass filter and is therefore subject to interference below the cut-off frequency. I noticed in my spreadsheet that this figure is rather low (1.59Hz). I was toying with the idea that I could raise this frequency by possibly reducing the capacitor value slightly?

I’m starting to appreciate that the original circuit provides a good starting point for audio input. I suppose at the very least I’ve got a better understanding of what’s going on.

Cheers

Jase :slight_smile:

audio_input.pdf (228 KB)

How important is impedance matching?

Well you generally want to drive into a higher impedance if you want to maximize the voltage transfer. On the other hand to maximize the current transfer you need to drive into a lower impedance.

It is only the special case when you want to maximize the power transfer that the drive impedance should match the load impedance. Typically that would be only in the case of driving a speaker with an amplifier.

Hi Grumpy_Mike

Wow that was quick. I get driving a lower impedance maximises current transfer but I don't get how driving a higher impedance maximises voltage transfer. Could you elaborate? More importantly what should I be aiming for in my situation? I obviously thought matching being the balanced approach given that we're dealing with audio.

In addition, do my numbers look OK? There seems to be a few formulas I can apply to the circuit to perform a health check. I realise I've made a couple of mistakes earlier (sorry).

I really appreciate your help.

Cheers

Jase :slight_smile:

Sorry, GrumpyMike ... but at the risk of confusing the OP even further (!?)....

It is only the special case when you want to maximize the power transfer that the drive impedance should match the load impedance. Typically that would be only in the case of driving a speaker with an amplifier.

...just isn't how it's done. . The output impedance of an audio power amp is very small....

regards

Allan

edit... after all this discussion , the OP wants get audio into an arduino.... what he does with it thereafter is unknown.

  • Typical Max sampling rate 10kHz, which means with 'brick-wall' filtering to prevent aliasing a maximum of 5kHz hf response

  • given the requirement for that filter the minor effect of value of coupling capacitors and resistive loads is academic. And the design ( a 7-pole Chebychev/elliptic? or a much higher order Bessel if you're fussy about group delay....) rather more complex than r-c nets.

  • and 10 bits resolution . ~60dB dynamic range.... presuming the a/d is perfect.....

not exactly hifi....

If you want good quality audio there are much better platforms.

A

Hi Allan

Thanks for your suggestions. To be candid they're way over my head. I can however answer one question you have. I want to determine the frequency of a simple tone ranging from 100Hz to 200Hz using a simple circuit (like those linked in the first post) that uses common parts. I'd like to understand how it works and if there is any way I can optimise it to work best with the frequencies I'm interested in. I hope this clarifies where I'm coming from.

Cheers

Jase :slight_smile:

If you're limited to 200Hz max, at the input , and the resolution is adequate, the arduino would be fine

I misunderstood - I thought you were after hifi quality.....
regards

Allan

Hi Allan

No worries. Given the basic nature of what I'm trying to do I'm thinking provided my voltage divider doesn't draw too much current and my capacitor is large enough to charge for the frequency range (see previously attached) I should be fine? I'd be interested in your thoughts.

Cheers

Jase :slight_smile:

...just isn't how it's done. . The output impedance of an audio power amp is very small....

Yes but so is the load. Yes it is how it is done. It's all in the maths, power transfer is maximised with matching impedances. It was one of the first things we learned at collage.

but I don't get how driving a higher impedance maximises voltage transfer.

Because all voltage generators have an output impedance which can be thought of as a series resistance. This forms a potential divider with the load. In order to get the most voltage at the load then the load impedance must be as high as possible so that the potential divider action does not reduce the voltage too much.

This link is not about the Arduino but the Raspberry Pi which has the ability to change the output impedance of the output pins, but it goes through the above in a bit more detail.
http://www.thebox.myzen.co.uk/Raspberry/Understanding_Outputs.html