[sdiy] Removing the effect of a DC blocking filter through DSP
Richie Burnett
rburnett at richieburnett.co.uk
Sun Dec 11 20:13:58 CET 2022
I've done this using digital IIR filtering before in order to recover the
shape of various low-frequency waveforms that have been changed by passing
through one or more "DC-blocking" capacitors in mixers, soundcards, etc...
but the first thing I'd say is if you can re-record the samples with
acquisition that goes down to DC, you'll save yourself some hassle! If not,
then read on...
Each DC-blocking capacitor acts as a 1st-order high-pass filter. That is to
say that mathematically each DC-blocking cap puts a single zero at DC (0Hz)
and a single pole at the cutoff frequency of the resulting high-pass filter.
Compensating for (or "inverting") the effect of the pole at the cutoff
frequency is easily done by placing a transfer function zero at the cutoff
frequency in your digital IIR correction filter. Compensating the zero at
DC is a little more troublesome. Mathematically you can do this with an
integrator, but it results in infinite gain at 0Hz (DC!) The combination of
pole at DC (integrator) and zero at fc for each original DC-blocking stage
mathematically compensates perfectly for the high-pass characteristic of
each DC blocking stage, but causes some problems in practice! Particularly
if you are compensating for a number of DC-blocking stages and end up
needing several poles at DC and therefore several cascaded integrators!
Whilst one integrator might just result in an undesirable DC offset or
slowly wandering DC level in the resulting output, more than one integrator
in your IIR compensation filter is sure to end up with a waveform that heads
off to infinity pretty quickly!
There are a couple of ways to deal with this... Firstly, trim down any
waveform that you're working with to just include a small section that you
are interested in. (If it's a long recording, and you're interested in all
of it, it can be best to chop it up into sections for reasons that will
become obvious in the following points...) Secondly, remove any DC from
each snippet of the original signal before you process it further. (I know
that there shouldn't be any DC present by definition if the signal was
acquired through DC-blocking capacitors, but no ADC is perfect. So, check
for any DC, and remove it by applying an equal and opposite DC level to the
signal before processing it with the "un-mangling filter". If you know that
there is no net DC component in a 1 second snippet of audio, then you can at
least safely integrate it once without it heading off to infinity :-)
If you apply your filter and the DC quiescent level of the output is
different at the start to that at the end, you can often draw a line through
the waveform and subtract this to kill the DC drift across the recording if
it is linear. If not...
The next thing that you can do is modify (move) the pole at DC (integrator)
in your compensation filter to make it a low-frequency pole instead (leaky
integrator.) The more leaky you make each integrator the less you have
problems with DC accumulation, but the less perfect the un-mangling action
of the filter processing is because it no longer perfectly matches what
happened in the real-life HPF. In practice you can often find a good
compromise and get an output that looks acceptable (with minimal DC
accumulation and also minimal waveshape distortion) buy careful choice of
the leaky integrator cutoff frequency (or frequencies.)
What this is actually doing is undoing the action of the original
DC-blocking HPF's pole at fc but then re-introducing a new digital HPF
action at a much lower frequency. It is like as if you could go back and
increase the size of those DC-blocking capacitors to move the HPF filter
action down to a low enough frequency where it isn't so much of a problem
anymore. Sometimes, you don't need to move it down very far... For
instance if you are looking at a waveform that has a fundamental at 10Hz,
but it was recorded through a DC-blocking stage with HPF at 20Hz, you can
probably get good enough results by effectively moving the HPF filter down
to something like 1 or 2Hz. You're likely to get much less trouble with
wandering DC offsets by doing this and keeping the integrator slightly
leaky, than you would if you tried to compensate perfectly by putting the
integrator pole right at DC (0Hz.)
For example, I once got sent a recording of a rimshot sound from a TR-909
for analysis from a very kind person on this list who was helping me model
the TR-909's RS circuit. It turned out that it had accidentally been
recorded through an analogue console with the "rumble filter" on the channel
left enabled. This caused a bit of head-scratching because the 2-pole
high-pass action of the rumble filter contributed significant phase-shift at
the prominent frequencies in the RS sound and significantly modified the
wave-shape, if not even audibly changing the sound noticeably! It turned
out that the waveshape could be recovered back to what was expected by
post-processing the waveform with a digital IIR filter that had two poles
just up from DC, and a pair of complex zeroes that compensated for the
original rumble HPF.
One final point regards how to tweak the placement of the zero or zeroes in
the IIR correction filter... If you are expecting to see square waves, then
you will know when you have coefficients that result in the correct zero
positions because the portions between the edges of the square wave will be
constant and flat, with no overshoot, undershoot or curvature. Likewise, if
you are expecting a sawtooth with a linear slope but are seeing curvature
due to DC-blocking HPF action, you will know when it is perfectly
compensated, because the slope will be linear, (not convex, concave or
S-shaped!)
Sorry for long post, hopefully helpful to someone!
-Richie,
-----Original Message-----
From: Didrik Madheden via Synth-diy
Sent: Sunday, December 11, 2022 2:49 PM
To: SDIY List
Subject: [sdiy] Removing the effect of a DC blocking filter through DSP
Today the thing I'm tasked with is that I have some audio recorded
through a setup containing one or more DC blocking caps, and would
like to recover the unaffected audio. In principle, this could
potentially be fairly simple depending on the circuit: model a 1 pole
HP filter and run it backwards. Of course, the issue is that you would
be integrating over a fairly long period of time (in my case I'd need
to do it over multiple seconds) and the output is likely to diverge
easily. I'm able to produce a step function from this system as a
reference.
Before I roll up my sleeves and try to code something myself, is there
any project or code examples that does exactly this, in particular
automating or visualizing the trimming of the parameters needed to
avoid divergence? In the ideal case, such a software might have a
waveform view where I can select part of the reference waveform that's
silent, for extracting a corrective DC offset, and the pulse of my
reference step function, for extracting the filter parameters, and out
comes the parameters I need.
--
/Didrik
_______________________________________________
Synth-diy mailing list
Synth-diy at synth-diy.org
http://synth-diy.org/mailman/listinfo/synth-diy
Selling or trading? Use marketplace at synth-diy.org
More information about the Synth-diy
mailing list