6
$\begingroup$

I have audio recordings with a consistent DC offset, which I would like to correct. I know that in the time domain, I can subtract the mean of the entire signal from the original signal

(Data_without_dc_offset = Data_with_dc_offset - mean(Data_with_dc_offset))

to remove the DC offset, but I am uncertain how to do this in the spectral domain (e.g. removing the DC offset from FFT data). How do I do this?

$\endgroup$

6 Answers 6

10
$\begingroup$

You may not need to. The DC offset should show up only in a single bin of the FFT, namely the one corresponding to 0 Hz, which is (usually) the very first element of the vector output by an FFT function. As WMXZ suggests, you can zero it out.

In a horizontally-displayed spectrogram, this bin is the bottom edge - the bottom row - of the spectrogram. If you ignore that row, or adjust your display so that you don't even see that row, you shouldn't have to worry about it.

$\endgroup$
1
  • 1
    $\begingroup$ just to add if your desired signal contains near-dc frequencies & you may wish to preserve them. if so consider zero padding (and correct window) the end of your sample set if required to sufficiently shrink your bin resolution prior to nulling the zero bin. $\endgroup$
    – antimony
    Commented Jul 2, 2022 at 1:55
6
$\begingroup$

You can also reduce DC offset by applying a band filter to the signal, which will reduce the effects of DC offset in the spectrogram. Applications like Raven Lite and Audacity make this approach easy.

In Raven Lite you select "Edit > Band Filter > Filter All With" from the menu, then select Bandstop with Lower Limit 0 Hz and Upper Limit of 1 Hz. In Audacity select "Effect > High Pass" from the menu, then type in a Frequency of 1 Hz.

$\endgroup$
3
$\begingroup$

Removing the DC component in the frequency domain is not trivial, and generally not recommended. Although ideally all the DC content should be at the 0-th bin of your Discrete Fourier Transform, in practice the DC content tends to "leak" to nearby bins due to spectral leakage. The amount of leakage will depend on a bunch of factors such as the magnitude of your DC component, DFT size, amount of zero-padding, and chosen windowing function. This leakage may interfere with the estimation of your nearby lower frequencies, which may or may not be a significant problem for your signal analysis.

In general, it is more efficient, more controllable and more reproducible to perform a DC removal in the time domain, as you described in your question, or even a linear trend removal. Some packages/languages already contain pre-built functions to perform this task, such as SciPy/Python. Another option is to high-pass filter your signal at a very low frequency, e.g. 1 Hz or lower, as suggested in other answers.

See here (chapter 11) for more details on this issue.

$\endgroup$
2
$\begingroup$

If you work with R and you can remove it with the function rmoffset() from seewave package.

$\endgroup$
1
$\begingroup$

Simply put the zero'th frequency bin to zero.

$\endgroup$
1
$\begingroup$

Depending on how you're converting to the spectral domain, this may happen automatically. Many transformation algorithms either implicitly or explicitly drop the zero-frequency component of the signal during the conversion process.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.