How can I Remove a Wandering DC Offset from an Audio Clip?

5.4k views Asked by At

I've licensed some audio clips, but some of them come with what I have learned is a "DC Offset" that should normally have been removed during production.

Audacity's "Normalize" filter is able to fix a static DC Offset, but after applying it to my audio clips, I noticed that their DC offset varies (within 0.5 seconds it could go from 0.05 to 0.03 along a normalized amplitude range). For example:

Wandering DC Offset

To the left, silence is at 0.02, to the right, it's at 0.00 - this is after normalization by Audacity.

With me not being an audio engineer and not having any professional tools, is there a way to fix this?

4

There are 4 answers

1
learnvst On BEST ANSWER

A DC offset is a frequency component at 0 Hz. The "wandering DC offset" will be made of very low frequency components, so you should be able to remove this by using a high-pass filter with a cutoff of around 15 Hz. That way, you'll remove any sub-sonic DC related stuff without altering the audible frequency range.

Use a filter with a steep rolloff. Seeing as you're doing this offline, you can use a simple IIR type and filter the signal in both forward and reverse directions to remove any phase distortion that would otherwise be imposed by the filtering.

If you use matlab, the operation would look something like this . .

[x, fs] = wavread('myfile.wav');
[b,a] = butter(8, 15/(fs/2), 'highpass');
y = filtfilt(b,a,x);
0
dB' On

As @learnvst explains in his answer, what looks like "wandering DC offset" is actually just content at very low frequencies. You can remove this LF content with a high pass filter. Since frequencies below 20 Hz are generally inaudible, you should be able to take out the "wandering DC" without actually changing how the file sounds.

The latest version of Audacity (2.0.5) includes a high pass filter. Select Effect > High pass filter ... and adjust the cutoff frequency and rolloff parameters. A cutoff of around 15 Hz and a rolloff of 6 dB/oct should do the trick.

0
rolyan trauts On
for f in *.wav; do
  mv "$f" /tmp/dc1.wav
  dc=$(ffprobe -f lavfi "amovie=/tmp/dc1.wav,astats=metadata=1" 2>&1 | sed '/Overall/,$!d' | grep DC ) 
  #echo "$dc"
  dc=$(echo "$dc" | awk '{ print $6 }')
  #echo "$dc"
  dc=$(echo "$dc * -1" | bc)
  echo "bc" "$dc"
  ffmpeg -hide_banner -loglevel error -y -i "/tmp/dc1.wav" -af "dcshift=$dc:limitergain=0.02" "$f"
done
0
PatriceG On

From the command line, you can have a try with sox.

sox fileIn.wav fileOut.wav highpass 10

This will apply an high pass filter at a frequency of 10 Hz. This should remove the DC offset (but maybe not in the early beginning of the files).

See the sox manual for a little bit more information (but not so much).