7
$\begingroup$

There is sinusoidally controlled signal, which other than being noisy, can change values for amplitude, frequency, phase and offset. At every new sample a new sine is fitted for the last N samples. These fitted signals might be different due to noise or due to the signal changing value. To filter it, I would like to use a Kalman filter to estimate the actual sine and to smoothen the transition of the above mentioned parameters.

I tried to get familiar with Kalman filters, but most of the examples deal with only estimating one parameter, and in my case the parameters are not independent.

Could somebody provide some hints on how to get started, or knows how to do it?

$\endgroup$
13
  • $\begingroup$ "a sine is fitted": How so? The usual method of doing this would be employing a PLL, not making estimates only based on the last few samples. $\endgroup$ Jul 24, 2021 at 13:09
  • $\begingroup$ Okay, this one is not done with a PLL. Can we focus on the Kalman filtering part? $\endgroup$ Jul 24, 2021 at 14:17
  • $\begingroup$ no, we can't: the Kalman needs a model of the way you estimate and how consecutive estimates depend on each other. So, the information you're omitting here is critical to any answer. $\endgroup$ Jul 24, 2021 at 14:18
  • 1
    $\begingroup$ That is correct -- and it's sounding like it's not suitable because, first, you need an accurate model, second, the Kalman filter isn't the best choice if you're always working with a fixed number of samples after the fact, and, third, this is a nonlinear optimization problem for which a Kalman might be suitable if you had a decent model and were doing this on-line instead of after the fact with a fixed-size vector, but certainly isn't going to be optimal for the situation you describe. $\endgroup$
    – TimWescott
    Jul 24, 2021 at 23:58
  • 1
    $\begingroup$ You should edit your question with that information about the signal being less than a cycle, and about you not being able to model it. If you can't model it though, then there's very little basis for designing any kind of estimator -- while you're writing the rest into your question, add in what you do know about your signal (and the noise) that might be pertinent. $\endgroup$
    – TimWescott
    Jul 25, 2021 at 0:00

1 Answer 1

7
$\begingroup$

We can build a non linear dynamic model in order to estimate the parameters of a sine signal.

Let's model the signal as $ a \sin \left( \phi \right) $ where $ \phi $ is the instantaneous phase. So the model could be also written as $ a \sin \left( \omega t + \psi \right) $.

Then the model can be:

$$ {a}_{k} \sin \left( {\omega}_{k} {t}_{k} + \psi \right) = {a}_{k} \sin \left( {\phi}_{k} \right) $$

With some math and pre processing of Kalman Filter you may derive the model with the matrices:

$$ \boldsymbol{x}_{k} = \begin{bmatrix} {a}_{k} \\ {\omega}_{k} \\ {\phi}_{k} \end{bmatrix}, F = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & \Delta t & 1 \end{bmatrix}, Q = \begin{bmatrix} \Delta t {\sigma}_{a}^{2} & 0 & 0 \\ 0 & \Delta t {\sigma}_{\omega}^{2} & \frac{ {\Delta t}^{2} {\sigma}_{\omega}^{2}}{2} \\ 0 & \frac{ {\Delta t}^{2} {\sigma}_{\omega}^{2}}{2} & \frac{ {\Delta t}^{3} {\sigma}_{\omega}^{2}}{3} \end{bmatrix} $$

Where $ {\sigma}_{a}^{2} $ is the process variance of the amplitude and $ {\sigma}_{\omega}^{2} $ is the variance of the process noise of instant angular frequency.

The measurement model is a bit more tricky. The measurement model is:

$$ {z}_{k} = h \left( \boldsymbol{x}_{k} \right) = {a}_{k} \sin \left( {\phi}_{k} \right) $$

Hence the Jacobian is given by $ \frac{\partial h \left( \boldsymbol{x}_{k} \right )}{\partial \boldsymbol{x}_{k}} = \left[ \sin \left( {\phi}_{k} \right), 0, {a}_{k} \cos \left( {\phi}_{k} \right) \right] $.

Wrapping all this into a Kalman Model will yield:

enter image description here

You may see that the model can effectively track changes in the parameters.
There are other alternatives to this dynamic model but I think this is a simple and effective one.

You may also use the Unscented Kalman Filter. I implemented it at Extended Kalman Filter (EKF) for Non Linear (Coordinate Conversion - Polar to Cartesian) Measurements and Linear Predictions.

The code is available at my StackExchange Signal Processing Q76443 GitHub Repository (Look at the SignalProcessing\Q76443 folder).

$\endgroup$
17
  • $\begingroup$ Thank you! Your interpretation is correct. $\endgroup$ Jul 25, 2021 at 6:46
  • $\begingroup$ Thank you very much Royi! $\endgroup$ Jul 25, 2021 at 19:05
  • $\begingroup$ @user3761419, You're welcome. You're invited to read and +1 the other question I linked to. It will assist you as well. $\endgroup$
    – Royi
    Jul 25, 2021 at 20:21
  • $\begingroup$ This is very interesting, normally I wouldn't see EKF as an appropriate use of this. I still wonder how you would select the right parameters though to balance measurement noise vs state change considering the model is dynamic $\endgroup$ Jul 26, 2021 at 7:28
  • 1
    $\begingroup$ For DC you may have a look at dsp.stackexchange.com/questions/36135. For higher bandwidth filter you may increase the process noise ($ \sigma_{a} $ and $ \sigma_{\omega} $). $\endgroup$
    – Royi
    Sep 2, 2021 at 3:44

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.