Okay, this is about nothing of any practical importance I can think of, but I got interested in the subject, and arguably it’d be better posted at Mathematrec , but then I’d have to explain things like what a high pass filter is and so on, so it goes here.

This is about AC coupling. That’s when you use a capacitor in series after a signal source to remove its DC component, leaving only the oscillatory behavior around zero. Or rather, not just a capacitor. Think about it. If you connect a signal source on the left side of a cap, how does the right side know how to remove DC? Voltage, after all, is relative — it’s always measured relative to some other point, usually ground. The DC component is a constant voltage relative to ground. But how does that cap, which isn’t connected to ground, know what ground is? It doesn’t. So it can’t know how much DC to subtract.

No, you need something else, something that is connected to ground: A resistor. A series capacitor followed by a resistor to ground will remove DC. But that’s just a high pass filter. And that’s what AC coupling really is: High pass filtering with a sub-audio cutoff frequency.

Sometimes you do see a module output with a series capacitor on it, and no resistor to ground. So how does that work? It doesn’t! Or at least, it doesn’t if you don’t connect anything to the output. In which case you probably don’t care if it doesn’t work. But when you plug in a downstream module, the input resistance of that module, which typically is around 100 kΩ, completes the high pass filter and AC coupling happens. I’d rather see a design that doesn’t rely on a connected module to work, but it’s usually okay.

Now, the DC offset doesn’t disappear instantly. Switch on a DC voltage at the filter (green line below) and the output will initially be high, then will decay away exponentially (blue line). There’s a time constant equal to RC, and it takes a few times that long for the output to get close to zero.

Input voltage is a step from 0 to 5 V; output starts at 5 V but decays away, asymptotically approaching 0 V

High pass filter effect on a voltage step

This is why you want the filter cutoff to be below audio frequency, but not by too much. The lower the cutoff frequency, the longer it takes the DC offset to go away. Not much point in doing AC coupling if it’s going to take a week to work!

But what does this filter do to your oscillator signal? Well, let’s see some simulations. We’ll use a 100 nF cap and a 150 kΩ resistor. That gives an RC time constant of 15 ms and a cutoff of about 10 Hz (10.61 really). Put in a 100 Hz sine wave (green line below) and what you get out is… a 100 Hz sine wave, at pretty close to the same amplitude (blue line).

Input voltage is a sine wave; output is also a sine wave, but slightly shifted to the left

High pass filter effect on a sine wave

With a triangle wave you do see a slightly distorted shape.

Input voltage is a triangle wave; output is similar, but the 'triangle' edges curve a little

High pass filter effect on a triangle wave

And more shape distortion with a ramp.

Input voltage is a ramp wave; output is similar, but the rise is decidedly curved, and the minima and maxima are shifted downward a bit

High pass filter effect on a ramp wave

But arguably the most shape distortion occurs with a square wave.

Input voltage is a square wave; output jumps between positive and negative, but instead of flat tops/bottoms there are curved lines heading toward 0 V

High pass filter effect on a square wave

That output doesn’t look square at all! It’s positive when the input is positive and negative when the input is negative, but the shape is messed up.

But is this surprising? Here’s an input that’s +5 V for 5 ms, then -5 V for the next 5 ms, and so on. The filter doesn’t know it’s going to change from +5 V to -5 V and back. To the filter, that +5 V looks just like a DC offset (until it goes away). So it does the same thing it would do to an offset: Sends it decaying toward 0 V, exponentially, with an RC time constant. RC here is 15 ms, so in 5 ms you do lose a good deal of amplitude. So what?

So this is what: It’s a 100 Hz signal. The filter cutoff is 10 Hz. They’re a decade apart. Shouldn’t the signal be pretty close to unaffected by the filter?

More specifically, the 100 Hz square wave can be thought of as a bunch of harmonics at frequencies 100 Hz, 200 Hz, 300 Hz, and so on — well, actually 100 Hz, 300 Hz, 500 Hz, and so on. For a square wave there are no even harmonics. These harmonics have different amplitudes. The 300 Hz one is 1/3 the amplitude of the 100 Hz one, the 500 Hz one is down 1/5, and so on. Add the harmonics with those amplitudes all together and you get a square wave.

Plot shows the first several harmonics of a square wave and their sum, which resembles the square wave

Harmonics of a square wave and their sum

What does the filter do to these harmonic amplitudes? The output amplitude is $l \frac{2\pi fRC}{\sqrt{1+(2\pi fRC)^2}}$ times the input amplitude. For frequency $l f$ equal to 100 Hz, with RC = 15 ms, that works out to… 0.994418. The first harmonic is attenuated by a whopping half a percent! For 300 Hz it’s 0.999375 — down about 0.06%. For the higher harmonics the effect is even smaller. These are all barely noticeable. So how do they result in such a distorted wave shape?

They don’t. Scale the harmonic amplitudes by the above amounts and add them up and you get… pretty much a square wave.

But the thing is, the filter doesn’t just change the amplitudes of the harmonics. It also changes their phases. Look back at that sine wave plot. Notice how the output is shifted relative to the input. The phase shift (in radians) is $l \arctan(1/(2\pi fRC))$. For the 100 Hz harmonic that works out to 6.1°. That’s not so tiny. For the 300 Hz harmonic it’s 2.0°, for the 500 Hz it’s 1.2°, and so on. Add up the harmonics with attenuated amplitudes and phase shifts, and yes indeed, you get the kind of distorted shape we saw above.

Plot shows the first several harmonics of a filtered square wave and their sum, which resembles the distorted shape seen in the simulation

Harmonics of a filtered square wave and their sum

Even though we’re a decade above cutoff, the phase shifts are still just large enough to conspire to make the shape of RC decay. In fact, most of the change in shape is due to the phase shift of just the first harmonic:

Plot shows the first several harmonics of a filtered square wave, with the first harmonic phase shift set to zero and their sum, which looks nearly indistinguishable from the unfiltered square wave plot

Same, but with first harmonic phase shift set to zero

So yes, the filter does significantly change the wave shape. But does it change the sound? Not really. What the ear is good at hearing are harmonic amplitudes; harmonic phases, not so much. The harmonic amplitudes are barely affected here, with the result that you’d be hard pressed to hear any difference between the filtered and unfiltered signals. So you can go ahead and do AC coupling with a filter cutoff around 10 Hz — the result might look dreadful on your scope, but it’ll sound fine to your ears.

Added: Here’s what you get if you sum the harmonics of a square wave up to n=51 and then vary the phase shift of the first harmonic from 0 to 6°.

Something like a square wave, with small oscillations instead of flat top/bottom, and the tops/bottoms go from horizontal to tilted (and a little curved) and back

Sum of the harmonics of a square wave up to n=51 with phase shift of the first harmonic varying from 0 to 6°.