I wrote a program that computes incrementally the mean and variance of values generated with the function $a\cos(\omega t)+\mu$.
The program will have to compute these for sums of cosine and sine of same frequency ($\omega$ values) but with various phases. The result of the sum is still a cosine or a sine, only the amplitude and phase will vary.
I tried changing $\omega$ and the number of iterations but it didn't increase the precision much which is around $10^{-3}$ and down to $10^{-5}$.
Is there a way I could increase the precision of the mean value which is used to compute the variance ? The real variance and mean are unknown when processing.
I have noticed that the computed mean oscillates around the real mean. Could I use this property to help increasing the precision ?
In the final application, the variance and mean will change over time and the program will have to update the computed values. The faster it is able to adjust to the new mean and variance values, the better.
I was thinking to simply sum the values over $2\pi$ periods and average these.
Edit:
To rephrase the problem in a more general and accurate form, I have a sequence of values $x_t$ that follows the function below for a discrete incremental sequence of t representing time.
$$x_t = A\cos(\omega t + \phi) + \mu = a\cos(\omega t) + b\sin(\omega t) =p+ \mu$$
The parameters A, $\omega$, $\phi$ and $mu$ are unknown.
I have to normalize the mean and standard deviation of $x_t$ and for that I need to determine it's mean ans standard deviation.
A naive mean and variance computation shows that they oscillate, which is normal due to the cosine. I'm looking for a way to increase the precision of the mean and variance, and thus ki d of counter balance the oscillations.
An incremental algorithm able do adapt to changes of parameter A and $mu$ would be optimal. The parameter $\omega$ is expected to change only very slowly or be constant.
I asked the same question on stackoverflow and got an interesting solution. I also found myself a way to determine the parameter $\omega$ (the pulsation) with simple arithmetic.
$\cos$typesets the cosine function better than$cos$. – David K Jul 09 '23 at 21:52