Page 1 of 3

DC offset trickery

Posted: Thu Nov 01, 2012 12:18 am
by steve
There are sometimes claims that the type of DC offset correction used by the Normalize effect in Audacity can cause DC offset errors with asymmetric waveforms. I previously believed this was true, but have since been unable to find any real evidence to support this claim. This post looks at one possible explanation for how this misconception might come about.

Asymmetric waveforms are common when recording real instruments and are often said to be particularly common to brass, woodwind and string instrument recordings. For demonstration purposes, this audio sample is a crude synthesized "bassoon" type sound.
dc-offset-sample.flac
(229.84 KiB) Downloaded 177 times
A close-up of the waveform reveals that it is asymmetric (higher above the 0.0 horizontal line than below)
firsttrack000.png
firsttrack000.png (9.5 KiB) Viewed 4670 times
Zoomed out we can see that the waveform is asymmetric, but there appears to be no "DC offset"
firsttrack001.png
firsttrack001.png (10.27 KiB) Viewed 4670 times
Now let's see what happens when we apply the Audacity Normalize effect and correct for DC offset:
firsttrack002.png
firsttrack002.png (10.41 KiB) Viewed 4670 times
Oops, that shouldn't happen should it?
Or should it?
What has gone wrong here?

Re: DC offset trickery

Posted: Thu Nov 01, 2012 12:36 am
by kozikowski
I'm not sure how you got the original waves. To get DC offset in the original show, the coil, diaphragm or ribbon would have to leave the microphone and slowly walk toward or away from the performer. There was and may still be a school exercise where you created a theoretically perfect music system that responded down to DC. You could put a gust of wind in and the gust of wind would come out on playback. The system would also suck on command.

That's the only way you can get "DC" in a music system barring something actually being broken.

So even though the digital system can do that, the analog system ahead of it can't. You also have to be careful not to pick a non-representative subset of sound. You have to select enough music so that a complete 1Hz of music would be supported.

I wish I had kept it, but I listened to a radio show where the presenter and the guest both had aggressively non-symmetrical voices -- in opposite directions. The timeline looked like a badly damaged square wave, but I'm sure if I analyzed it, it would all come out zero.

Koz

Re: DC offset trickery

Posted: Thu Nov 01, 2012 1:15 am
by steve
Here's a nice "real world" asymmetric waveform, it's a trumpet note by Miles Davis, aptly from “So What” (Kind of Blue, CD 460603 2)

Image
(image from: http://www.audiomisc.co.uk/asymmetry/asym.html)

I'd bet that this would come out "all zeros" too.

Re: DC offset trickery

Posted: Thu Nov 01, 2012 2:20 pm
by steve
steve wrote:Oops, that shouldn't happen should it?
Or should it?
What has gone wrong here?
This little Nyquist script allows us to see the offset (bias) for each 1/4 of a second of the audio track (mono only).

Code: Select all

(setq step (round (/ *sound-srate* 4))) ; 1/4 second in samples

(force-srate *sound-srate*
  (snd-avg s step  step op-average))
If you apply this script (in the Nyquist Prompt effect) to the audio sample posted previously it will shed some light on why the DC offset correction in the Normalize effect appears to fail.

Re: DC offset trickery

Posted: Thu Nov 01, 2012 2:40 pm
by steve
Q. That audio sample is not a real recording - you synthesized it to have this problem. Does this ever happen with real audio recordings?

A. Yes I cheated ;) but yes this can occur (though not usually as badly) if a strongly asymmetric waveform is recorded through a sound card that has very poor linearity. It can also occur is a strongly asymmetric waveform is clipped or peak limited.
It may also occur if audio that has DC offset is gated or subject to some "noise suppression" or "recording enhancement" effects.
(All of which amounts to the same thing: non-linear gain).

Q. Is there a solution?

A. The best solution is to use better recording equipment.
If that is not an option, (for example with audio that has already been recorded), use this Nyquist DC offset tool with the options:
  • Remove DC offset
  • Abs + Filter
The track may need to be normalized after processing as the peak level may exceed 0 dB.
[UPDATE: See here for the updated version of the DC offset tool: http://forum.audacityteam.org/viewtopic ... 96#p193996 ]

The results can be checked using the code snippet in my previous post.

Note: The Nyquist Nyquist DC offset tool should perform better in cases like this than the LASPA dcremove effect.

Re: DC offset trickery

Posted: Thu Nov 01, 2012 2:50 pm
by kozikowski
I have three now, StarTech ICUSBAudio devices.

http://www.startech.com/Cards-Adapters/ ... ICUSBAUDIO

Apparently, I got one that is just broken. It produces significant DC Offset in the recorded signal. It's going out in the rubbish.

Koz

Re: DC offset trickery

Posted: Thu Nov 01, 2012 2:53 pm
by steve
kozikowski wrote:It's going out in the rubbish.
Before you trash it, could you post some (uncorrected) audio sample please :)

Re: DC offset trickery

Posted: Thu Nov 01, 2012 7:06 pm
by steve
steve wrote:A. The best solution is to use better recording equipment.
If that is not an option, (for example with audio that has already been recorded), use this Nyquist DC offset tool with the options:

Remove DC offset
Abs + Filter
There is now an updated version of the DC Offset tool: http://forum.audacityteam.org/viewtopic ... 13#p195713

The new "Dynamic bias adjustment" is likely to produce the best results whenever there is a non-constant DC bias.

Re: DC offset trickery

Posted: Thu Nov 01, 2012 8:03 pm
by steve
There's a lot of interesting detail about "DC bias" in this topic: http://forum.audacityteam.org/viewtopic ... 39&t=65190

Re: DC offset trickery

Posted: Tue Nov 06, 2012 3:02 pm
by RS_RS
Doesn't the contribution by edgar-rft to the thread referenced above expain what is going on? Surely the asymmetry of peaks above and below the axis is irrelevant to whether there is DC offset? What matters is whether the integral of the waveform over a reasonable length of time is nonzero - think of it in terms of finding the cos nt component in the spectrum when n is zero.

Steve's artifical example in his first graph clearly has more area between the axis and the part of the waveform below the axis than between the axis and the part of the waveform above the axis, despite the above-axis peaks being larger than the below-axis peaks. So the DC offset is negative.

The second graph, over a longer time period, shows patches of a waveform with DC offset mixed with some zero-offset silence, a combination I would be surprised to see in reality in the absence of clipping of a waveform like the Miles Davis example. No surprise at all that applying DC offset correction moves the waveform up not down.