DC Offset

For a little project (making an RGB Led strip react to Audio) I already setup a circuit with mosfets that can individually control the colors of the LED strip. Now I want to use a Y splitter to split my audio signal so I can feed it to my arduino and my audio system. Now I read that negative Voltages may damage the arduino so I need to offset the DC bias.

I tried to google a little bit and came to the result that I may need a circuit like that:

Now my questions are, is this correct / is my understanding of this correct?

We have a voltage divider due to the 2 same resistors (I just chose 10k because that seemed like a common value and I just need 2 equal values afaik). So when my signal comes in the voltage divider circuit will scale my signal by factor of 2.5 (should I use a higher R2 value to be sure to not get negative voltages?).

And I found circuits with a cap, sometimes in parallel, sometimes in series. The value I used I chose arbitrarily but have I a variety of electrolyte capacitors lying around.

My question here would be, as shown in my schematic the capacitor blocks DC voltage, does the value really matter? Should I add another capacitor in parallel to smooth out any distortions on my line?

I appreciate your input!

Your circuit is fine! (Except it's traditional to draw your schematic with signal flow from left-to-right, with input on the left and output on the right. :wink: )

I suggest you run the Analog Read Serial Example to see what kind of readings you get. It should read about 512 (half of the 1023 range) with silence and the "louder" the signal the more it should deviate up and down from there.

Note that it's an AC signal that crosses-through zero twice per cycle so the readings will appear "random" but louder sounds should give you some numbers that deviate farther from bias reading. (You can subtract-out the bias in software if you wish.)

Now I want to use a Y splitter to split my audio signal so I can feed it to my arduino and my audio system.

That should be a line-level or headphone-level signal. A speaker signal could be too high, especially from a high-power amplifier.

If you are reading zero you're probably going negative (it's unlikely that you're hitting exactly zero) and similarly if you read 1023 you are probably going above 5V. If that happens you'll need to reduce the signal (maybe with a pot or voltage divider).

We have a voltage divider due to the 2 same resistors (I just chose 10k because that seemed like a common value and I just need 2 equal values afaik).

That's good. Current from the audio signal flows through both resistors so you have a 5K load on the connected audio circuit. That should be fine but if you hear the sound level drop when you connect it, use higher value resistors. (5K is slightly low for a line-level signal, but it's "nothing" for a headphone output.)

So when my signal comes in the voltage divider circuit will scale my signal by factor of 2.5 (should I use a higher R2 value to be sure to not get negative voltages?).

No, it's not a factor of 2.5. It's half the voltage or 2.5V from the 5V supply. You also don't want to go over 5V and 2.5V allows the widest AC voltage-swing.

You can also "damage" (distort) the signal if you go negative or more than +5V. You probably won't damage the Arduino with a line-level or headphone-level signal because it as internal protection diodes that can handle a small amount of current, but a speaker-output could put-out enough current to fry the Arduino.

And I found circuits with a cap, sometimes in parallel, sometimes in series.

The series capacitor is required to block the DC from getting back into the audio circuits and it also prevents the audio circuit from messing-up the bias.

My question here would be, as shown in my schematic the capacitor blocks DC voltage, does the value really matter?

It makes a high-pass [u]high-pass filter[/u]. DC is zero Hz, so it gets blocked. You've got 10uF and 5K, so it's 3dB down at 3Hz and the full audio range will pass-through.

Should I add another capacitor in parallel to smooth out any distortions on my line?

Sometimes there is a (lower value) capacitor across the bottom resistor. That makes a low-pass filter to prevent aliasing (false frequencies). But I wouldn't worry about it... If you are not doing frequency analysis (FFT, etc.) aliasing isn't important, your not doing "high quality" FFT anyway, the high frequencies (that create aliasing) are not dominant in normal audio, and a single-stage RC filter isn't that effective anyway.

1 Like

For a low level input signal you may want to use the internal reference of 1.1V, and adjust the voltage divider accordingly (10:1). I'm not sure but eventually a 1:1 voltage divider from AREF to Gnd should work with any reference voltage.

I'm not sure but eventually a 1:1 voltage divider from AREF to Gnd should work with any reference voltage.

You mean a 2:1 voltage divider (two equal resistors). :wink:

That seems like a great idea but the ATmega datasheet says:

VREF can also be measured at the AREF pin with a high impedance voltmeter. Note that VREF is a high impedance source, and only a capacitive load should be connected in a system.

Maybe you could "get away with" 100K or 1M resistors. It doesn't have to be "perfect" for a lighting effect so that might work!

...I automatically switch between the 5V and 1.1V reference depending on signal level, but I use a peak detector (additional circuitry) so my signal never goes negative. I also use a variable reference/threshold set in software.

DVDdoug:
(Except it's traditional to draw your schematic with signal flow from left-to-right, with input on the left and output on the right. :wink: )

I will consider this in future drawings!

DVDdoug:
(You can subtract-out the bias in software if you wish.)
That should be a line-level or headphone-level signal. A speaker signal could be too high, especially from a high-power amplifier.

Substracting the bias is not necessary as I just take other low frequency bins and omit the 0 Hz one for my calculations :wink: I just connect the project to my laptop or phone, so no high power.

DVDdoug:
If you are reading zero you're probably going negative (it's unlikely that you're hitting exactly zero) and similarly if you read 1023 you are probably going above 5V. If that happens you'll need to reduce the signal (maybe with a pot or voltage divider).

My cheapo oscilloscope read some negative voltage (around -0.13 V) when I got to higher frequencies with a tone generator on my web browser. I didn't worry too much about that and my arduino survived for hours now :wink:

DVDdoug:
You can also "damage" (distort) the signal if you go negative or more than +5V. You probably won't damage the Arduino with a line-level or headphone-level signal because it as internal protection diodes that can handle a small amount of current, but a speaker-output could put-out enough current to fry the Arduino.

The signal ends with the arduino since I have a Y splitter, what ever I to the signal shouldnt affect the actual audio.

DVDdoug:
It makes a high-pass [u]high-pass filter[/u]. DC is zero Hz, so it gets blocked. You've got 10uF and 5K, so it's 3dB down at 3Hz and the full audio range will pass-through.
Sometimes there is a (lower value) capacitor across the bottom resistor. That makes a low-pass filter to prevent aliasing (false frequencies). But I wouldn't worry about it... If you are not doing frequency analysis (FFT, etc.) aliasing isn't important, your not doing "high quality" FFT anyway, the high frequencies (that create aliasing) are not dominant in normal audio, and a single-stage RC filter isn't that effective anyway.

I actually just had a 0.1 uF lying around, I read somewhere I should use electrolyte ones... I do FFT my signal to get the frequency bins of low, mid and "high" frequencies for my LED but I don't really care about accuracy. If there is a higher than usual signal on a mid frequency bin -> green LEDs it is :wink:
I was thinking about adding a multistage low pass filter, to filter everything above 5 kHz as I can't sample faster than 10 kHz anyway and higher frequencies give false readings.

DrDiettrich:
For a low level input signal you may want to use the internal reference of 1.1V, and adjust the voltage divider accordingly (10:1). I'm not sure but eventually a 1:1 voltage divider from AREF to Gnd should work with any reference voltage.

What would be the advantage of that? Getting a higher resolution signal as my circuit doesn't have an amp?

DVDdoug:
That seems like a great idea but the ATmega datasheet says:Maybe you could "get away with" 100K or 1M resistors. It doesn't have to be "perfect" for a lighting effect so that might work!

So 10k may have been a little bit too small?

DVDdoug:
...I automatically switch between the 5V and 1.1V reference depending on signal level, but I use a peak detector (additional circuitry) so my signal never goes negative. I also use a variable reference/threshold set in software.

This seems to be worth keeping in mind when I advance my project and correlate the intesisty of the light to the intensity of the signal.

So far I tested it for one party evening and it went fine, but I really need to work on some input detection b/c as is you shouldn't change the volume on the laptop but on the speaker itself, otherwise the "tuning" of the thresholds doesn't hold.

Thank you all for your input so far!

chuckyx:
I will consider this in future drawings!
Substracting the bias is not necessary as I just take other low frequency bins and omit the 0 Hz one for my calculations :wink:

Right. if you are using FFT you can ignore the zero Hz bin.

I just connect the project to my laptop or phone, so no high power.
My cheapo oscilloscope read some negative voltage (around -0.13 V) when I got to higher frequencies with a tone generator on my web browser. I didn't worry too much about that and my arduino survived for hours now :wink:

With the bias it should (hopefully) never go negative. If it does, it will go over 5V by (approximately) the same amount, since the AC audio signal swings (approximately) equal in the positive and negative directions.

The signal ends with the arduino since I have a Y splitter, what ever I to the signal shouldnt affect the actual audio.

If the signal goes negative (into the Arduino, after the bias) or more than Vcc, the signal can be distorted. This is unlikely to happen, but you need to check the raw ADC readings, not the FFT.

I actually just had a 0.1 uF lying around, I read somewhere I should use electrolyte ones...

...So 10k may have been a little bit too small?

Yes. You are loosing bass. Try the link I gave you, and remember the resistors are effectively in parallel for the AC signal, so that's 01.uF and 5K.

❝For a low level input signal you may want to use the internal reference of 1.1V, and adjust the voltage divider accordingly (10:1). I'm not sure but eventually a 1:1 voltage divider from AREF to Gnd should work with any reference voltage.

What would be the advantage of that? Getting a higher resolution signal as my circuit doesn't have an amp?

Yes. Higher resolution and more "sensitivity" … Bigger ADC readings...

❝That seems like a great idea but the ATmega datasheet says:Maybe you could "get away with" 100K or 1M resistors. It doesn't have to be "perfect" for a lighting effect so that might work!

So 10k may have been a little bit too small?

This is only if you use Vref for your voltage divider, and switch between the 1.1V and 5V references in software. For example, you can't use the normal 2.5V bias with the 1.1V reference (you'd just max-out the ADC read 1023 all of the time).

❝...I automatically switch between the 5V and 1.1V reference depending on signal level, but I use a peak detector (additional circuitry) so my signal never goes negative.

You cannot use a peak detector with FFT. There is no audio out of it, only varying DC.

I also use a variable reference/threshold set in software.

This seems to be worth keeping in mind when I advance my project and correlate the intesisty of the light to the intensity of the signal.

So far I tested it for one party evening and it went fine, but I really need to work on some input detection b/c as is you shouldn't change the volume on the laptop but on the speaker itself

I'm not using FFT so my situation is simpler but besides switching to the 1.1V reference with low-level signals, here's what I do -

I take a "sample" of the "loudness" once per second and save it in a 20-element (20-second) [u]circular buffer[/u]. Then, depending on the effect I use the average or the maximum from that array (buffer) as a threshold or reference. You could also map() that the actual range to LED brightness, etc.

I get good results when I change the volume or with quiet & loud songs. My "simplest effect" is a "flicker" effect that turns the LED/light on when the signal is above average and off when below average.

I've got a "VU meter" effect where the top of the meter is the maximum and the bottom is the average. That gives a lot more "meter action" than a real meter, but it's completely useless as a meter since it's constantly re-adjusting itself and the increments between the LEDs are meaningless.

If you wanted, you could make separate thresholds/references for each color/band, or you could use the overall volume.

Note that there is more energy in the bass & mid frequencies so you might want to adjust for that. Of course, you're not getting a "true-spectrum" when you start monkeying with the readings but it might make a better display!

DVDdoug:
If the signal goes negative (into the Arduino, after the bias) or more than Vcc, the signal can be distorted. This is unlikely to happen, but you need to check the raw ADC readings, not the FFT.

My cheap osci says I'm sometimes hitting negative voltages, but the raw ADC reading suggests I'm fine. The values are ranging about +- 200 around 530ish.

DVDdoug:
Yes. You are loosing bass. Try the link I gave you, and remember the resistors are effectively in parallel for the AC signal, so that's 01.uF and 5K.

::slight_smile: Of course...

DVDdoug:
This is only if you use Vref for your voltage divider, and switch between the 1.1V and 5V references in software. For example, you can't use the normal 2.5V bias with the 1.1V reference (you'd just max-out the ADC read 1023 all of the time).

Can you elaborate a little bit on that? I tested it and got 1023. But shouldn't I also sometimes get voltages of under 1.1 V if my signal is swinging between 0 and 5V? If I understood you correctly I could use internal 1.1V if I tied AREF to 2.5V? Why would it matter then what AREF is tied to? I never worked with that.

Don't touch AREF if you didn't understand the related data sheet paragraphs.

@diettrich I didn't intend to :wink: I read this link

and saw the possible dangers when connecting something to aref.

@doug I read your post over again and I think I got what I missed (or there's still the language barrier). You meant that I shouldn't use a 1:1 voltage divider but maybe 1:10 and then I could use 1.1V internal reference? I will still need to test that as I think it will only offset and not scale the voltage.

So I would expect for example if use a 1:10 divider my boss would be 0.45 V instead of 2.5 V. However wouldn't I range from -2.05V to 2.95V then?

Hopefully someone sees where I'm struggling and can give me a pointer in the right direction.