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).