That’s a interesting and versatile tool. I normally do not worry very much about DC offset (quite logical if you don’t see the waveform). However, the tool is a eye opener to some degree.
The equal amplitude option confused me at first. Am I right in saying that it will center the signal in regard to the 0 amp line? That is, if you have a positive peak of 0.7 and a negative of 0.6 that both will end up at (-) 0.65, right?
As far as I can see, the shifting of the sound will result in a new DC offset. Or will the signal be average zero? At least all (digital) silence will afterwards be off by the shift amount.
I could imagine an additional feature that is based on the equal peaks option. Instead of shifting the signal, the positive and negative parts could be multiplied independently to match the average peak and thus preserve all 0 value samples.
Another thing that comes to my mind is the case where you have a track that is composed from different sources. if there is a clip with a fair amount of DC offset, any attempted correction must fail, since the clean signal will be shifted to the opposite side of the offset.
I know, some say that a offset that doesn’t last the whole signal is no DC offset but I am not of this opinion and the speaker membran would surely agree with me.
I fancy that such issues via the ratio of the average peaks of the positive and negative bands of the signal could be identified and also corrected, maybe within a new plug-in.
Though it would still be important if you recorded with a sound card that had a significant amount of DC offset.
DC offset is a common reasons for clicks at edit points. Often one would try to edit at places where the audio signal is close to silence but if there is significant DC offset then “silence” will be offset from the -infinity dB line and will cause a click if it is edited next to audio that has a different amount of DC offset.
Yes that is correct.
Strictly speaking this is not DC offset removal and in some cases may create DC offset. Many waveforms are asymmetric (have peaks that are greater in one direction than the other). This may be useful if maximum amplitude is required in a situation where DC offset is unimportant.
Yes, both viewpoints are valid in my opinion. Over a short time period, very low frequency or an “offset drift” can be considered to be DC, and will burn out woofer coils in the same way that DC will. The low-frequency high-pass filter is often a good option for dealing with this type of problem.
I couldn’t find any reference to this in the documentation so I added a note div in several appropriate places in both the Manual and the Wiki (see Recent Changes logs).
New version. dc-offset.ny (1.97 KB)
This version has a new method for DC offset removal which I’ve called “Dynamic” offset removal. It is a hybrid method that is designed to overcome the limitations of the conventional methods. My initial tests look good so I have made it the default.
Dynamic bias correction:
Rather than calculating the absolute DC offset for the entire selection it calculates a rolling average, then compensates accordingly.
The advantages of this method are that it can cope much better with non-constant bias than either the “absolute” method (as used in the Audacity Normalize effect) or the high pass filter method (as used by the LADSPA dcremove effect).
I thought you wanted a separate (additional) tool for removing DC offset.
I think that (basic) DC offset correction should be a feature of the Normalize effect. The Normalize effect should not normally amplify any DC component to the signal, so usually the DC component should be removed by Normalize. However, this is established as an option and making it an “always on” feature would probably be seen as regression, even if there is a separate bias removal tool. Also, there may be (rare) cases where Normalizing without removing DC is required (though this is likely to be with test signals rather than audio).
I don’t think that the basic DC removal offered in the Normalize effect should be the only bias correction tool available.
New users are unlikely to look in “Normalize” if they want “DC offset correction”.
The current DC offset correction cannot handle non-constant DC bias.
High Pass filtering cannot correct the start of the selection or track.
There are probably not many common uses for adding an offset, but as it is intended to be a “full featured” DC offset tool I decided to include it. If the feature is not included in this tool, then where would a user find it if they do want to add an offset?
One example that comes to mind is for control signals.
Some time ago someone on the forum was using Audacity to send IR remote signals. They used a square wave to drive an IR diode.
It’s easy enough to generate a square wave with the Tone generator, but (without entering Nyquist code) how would you generate a square wave that goes from 0 to +1?
Answer: Generate a square wave with an amplitude of 0.5 and then add an offset of 0.5
Here’s the updated version with the typo correction: dc-offset.ny (2.1 KB)
And here is a simplified version that only has bias removal, no option to add DC and less removal method options: dc-remove.ny (2.21 KB)
Ah, but I’ve just found a a use - I needed to add some DC with the "DC offset…" so that I could test the "DC bias removal…"
Both appear to work ok on my tests.
I note from a comment by Gale (on the Wiki I think) that he doesn’t like the use of the nomenclature “DC bias” and I’m minded to agree - that’s one reason why I haven’t yet added the image to the DC offset removal proposal in the Wiki.
I’m guessing that you’ve done that to differentiate the two effects - but …
and I’ve probably used it more for that same reason than any other.
Re. the nomenclature:
If you say “DC offset” to any of the developers, they will immediately think “constant offset” and will be without any doubt that that is what is meant. Technically they are absolutely correct. As described in Wikipedia http://en.wikipedia.org/wiki/DC_bias:
When describing a periodic function in the frequency domain, the DC bias, DC component, DC offset, or DC coefficient is the mean value of the waveform. If the mean amplitude is zero, there is no DC offset. In contrast, various other frequencies are analogous to superimposed AC voltages or currents, hence called AC components or AC coefficients.
The practical situation is not so clear cut.
“Audio” is defined as “audible” frequencies, hence the “audio range” of 20 Hz - 20 kHz.
“Direct Current” (DC) is not necessarily a constant voltage - many (most?) DC circuits exhibit non-constant voltage. If I have a 1.5 (DC) battery and connect it to a circuit, the voltage will drop initially to a little below 1.5 volts (due to the “load” of the circuit) and then gradually diminish to 0 v as the battery goes flat. This is not AC (Alternating Current) because the current is all in one direction between the positive and negative terminals of the battery, but it is not “constant” either - it is gradually changing (in this example, diminishing).
How should we refer to a “non-constant DC offset” and distinguish it from a “constant DC component”?
For want of a better word I suggested “bias”.
Any better ideas?
Well that would depend on just what we are trying to remove/correct for the user.
Is that the constant or the non-constant variety? I’m no expert here
I do note that the the Realtek soundcard on my Tosh laptop offers (by default) to perform “DC Offset Cancellation” for the Stereo Mix on recording - and on the Mic - but I have no line-in device connected, indeed I have no line in on the laptop.
Koz has frequently stated that “DC is not audio” and that the sound card has no right to pass anything below 20 Hz.
The first statement is inarguably correct.
The second statement may be open to a little difference of opinion, but basically for “audio” recording you do not want any signal below about 20 Hz, so that includes constant DC and non-constant offset. For “audio”, unless it has an alternating frequency above 20 Hz, you don’t want it and it should be removed.
Unfortunately, although a 20 Hz high-pass filter might appear to be a simple solution, it is not a complete solution.
Some limitations of high pass filtering:
There is no such thing as a “perfect” filter. All filters have a “roll-off” response. You cannot suddenly cut off frequencies at a certain point, the best that you can do is to progressively reduce frequencies below a certain point. Frequencies just above the “filter frequency” are also reduced and frequencies just below the “filter frequency” are not completely removed, just reduced a bit.
When you press the record button, there may be DC offset present immediately, but filters operate in the time domain and cannot respond immediately. In non-technical description, they take a little time to settle.
To illustrate, here is a picture of what happens in the first 1 second with a steep (48 dB per octave) 10 Hz high pass filter applied to a DC offset of 0.5
Filters introduce “phase shift”. They introduce a frequency dependent delay to the signal.
Here is a 100 Hz square wave before and after filtering with a 10 Hz filter:
Notice how the peak amplitude is much higher after filtering, so even though the phase shift may be inaudible, it could create significant clipping.
It also looks nothing like the waveform that we were expecting.
I think that the idea that Audacity should be doing this by default is highly questionable.
I noticed the following behaviour which I don’t understand.
1 Generate White Noise at amplitude 0.0005.
2 Effect > DC offset.
3 Add offset or Remove then Add, Dynamic, +0.84.
4 Effect > DC offset.
5 Remove offset, Dynamic.
6 Effect > Amplify offers + 30.6 dB to maximise amplitude which looks “wrong”, but click OK.
7 The actual amplitude is now about -34 dB but Effect > Amplify does not let you amplify further without enabling clipping. Normalizing to 0 dB similarly does nothing.
If instead at step 4 I remove the offset using Effect > Normalize then I can maximise the noise to 0 dB as expected using Amplify or Normalize.
Similarly, if you use: Effect > DC offset: Remove offset / Absolute
In step 3 you added an “absolute offset” of +0.84, so the best way to remove that is with the “Absolute” method (which is also the method used in Normalize).
Explanation:
In step 1, if you generate 10 seconds of the noise, then after step 5 (Remove offset, Dynamic) look at 9.90 seconds and you will notice a slight “ripple”.
We had a huge DC offset (step 3) which “Dynamic” offset correction was not able to fully correct and a small (about -30 dB) ripple remains at the end. When amplified in step 6 this ripple is amplified to 0 dB.