1

I'm using an ADC to sample a periodic signal and I want to calculate the DC bias of the signal from the samples. The obvious solution is to take the average of the samples. This works fine if there are an integer number of periods of the signal in the sample set. But if the sample set contains an additional fraction of a period then those extra samples can throw the average off a bit.

The signal frequency can vary (from one sample set to another) and is independent of the sampling rate. The sampling is asynchronous to the signal so sampling could begin anywhere in the period of the signal. Assume there is at least a couple periods of the signal in the sample set although it could be many more.

Do you know of a better way to calculate the DC bias of the signal from a sample set that contains a non-integer number of periods of the signal?

Update: For my application this is not a real-time calculation. My device collects a sample set occasionally and I'm trying to do post-processing of the samples for various measurements.

I don't know the period of the signal by any other information. All I have is the sample set.

This is admittedly an XY problem. I want to know the DC bias so I can remove it from the samples (and then I plan to integrate the signal). I'm hoping for a way to improve my original implementation (which is easy for me to understand) before trying something more complicated (for me).

kkrambo
  • 137
  • 4

2 Answers2

1

Low-pass filter with DC gain = 1 (or 0 dB).

i s'pose, if you want to be sophisticated and want a rock-solid DC that might vary very little, then the output of your LPF can go into a median filter.

robert bristow-johnson
  • 20,661
  • 4
  • 38
  • 76
1

Let's say you have $N$ samples of the periodic signal $\tilde{x}(t)$ whose period is $\tau$ seconds and is sampled at sampling frequency $f_s$ where $\tau \cdot f_s$ is an integer (otherwise the discrete signal wouldn't become periodic).

Obviously, the sampled signal $\tilde{x}[n]$ repeats every $\tau \cdot f_s$ samples. That is $\tilde{x}[m]=\tilde{x}[m+\tau \cdot f_s]$. So the number of complete cycles is

$$K= \left\lfloor\frac{N}{\tau \cdot f_s} \right\rfloor$$

where $ \lfloor \cdot \rfloor $ is the floor function that returns the largest integer no greater than the argument.

The DC Bias can be given by

$$\frac{1}{K\cdot\tau\cdot f_s}\sum_{n=0}^{K\cdot\tau\cdot f_s-1}x[n]$$

In case if $\tau \cdot f_s$ is not an integer also a similar approach can be used, except you may need to upsample to a new sampling frequency to make it integer.

If you don't know the period, there are classic approaches (based on autocorrelation, DFT, etc.) to estimate it from a set of samples.

robert bristow-johnson
  • 20,661
  • 4
  • 38
  • 76
msm
  • 4,285
  • 1
  • 13
  • 25