Kalman Filter applied to linear discrete time process and interpretation of the estimated covariance matrix












1












$begingroup$


I want to have a deeper understanding of the discrete time Kalman Filter.



As a part of this I have modeled a forced, damped, mass spring system numerically in the Jupyter Notebook available here:
https://colab.research.google.com/drive/14c3-moLnPlbWArnT5I0_MEW6zytYW6Mv



The model of the system is:



$ddot{x} = -k (x - x_0) - mu v + f sin(5t)$



Where:



$x$ is the spring position, unit $[mathrm{m}]$.



$k$ is the spring constant, unit $[mathrm{N/m}]$.



$mu$ is the viscous friction, unit $[mathrm{Ns/m}]$.



$x_0$ is the spring equilibrium position, unit $[mathrm{m}]$.



$f$ is the external force amplitude, unit $[mathrm{N}]$.



$ddot{x}$ is the double derivative of $x$ with respect to time, or $frac{mathrm{d}^2 x}{mathrm{d} t^2}$.



The question is: To my understanding this process should be optimally estimated by the Kalman filter. My understanding is that this implies that the filter estimate $hat{x}$ should be between $x pm sigma_x$ with a probability of 0.682.



In my numerical experiments the position estimate follows this relation perfectly, but the velocity estimate does not at all. I am struggling to understand the exact cause of this. The notebook explains each step of the numerics, and shows how the distribution of the position estimate and velocity estimate differ. You can edit and comment in the notebook to test changes and explain where things go wrong.



Any help to shed light on this would be greatly appreciated.










share|cite|improve this question









$endgroup$












  • $begingroup$
    I found the problem. The issue was coming from having an incorrect state model matrix $A$. The problem was thus purely from a bug in the numerical implementation. The numerical example has been updated to be correct. So others seeing this question in the future can have it as reference.
    $endgroup$
    – lysgaard
    Jan 21 at 12:37
















1












$begingroup$


I want to have a deeper understanding of the discrete time Kalman Filter.



As a part of this I have modeled a forced, damped, mass spring system numerically in the Jupyter Notebook available here:
https://colab.research.google.com/drive/14c3-moLnPlbWArnT5I0_MEW6zytYW6Mv



The model of the system is:



$ddot{x} = -k (x - x_0) - mu v + f sin(5t)$



Where:



$x$ is the spring position, unit $[mathrm{m}]$.



$k$ is the spring constant, unit $[mathrm{N/m}]$.



$mu$ is the viscous friction, unit $[mathrm{Ns/m}]$.



$x_0$ is the spring equilibrium position, unit $[mathrm{m}]$.



$f$ is the external force amplitude, unit $[mathrm{N}]$.



$ddot{x}$ is the double derivative of $x$ with respect to time, or $frac{mathrm{d}^2 x}{mathrm{d} t^2}$.



The question is: To my understanding this process should be optimally estimated by the Kalman filter. My understanding is that this implies that the filter estimate $hat{x}$ should be between $x pm sigma_x$ with a probability of 0.682.



In my numerical experiments the position estimate follows this relation perfectly, but the velocity estimate does not at all. I am struggling to understand the exact cause of this. The notebook explains each step of the numerics, and shows how the distribution of the position estimate and velocity estimate differ. You can edit and comment in the notebook to test changes and explain where things go wrong.



Any help to shed light on this would be greatly appreciated.










share|cite|improve this question









$endgroup$












  • $begingroup$
    I found the problem. The issue was coming from having an incorrect state model matrix $A$. The problem was thus purely from a bug in the numerical implementation. The numerical example has been updated to be correct. So others seeing this question in the future can have it as reference.
    $endgroup$
    – lysgaard
    Jan 21 at 12:37














1












1








1





$begingroup$


I want to have a deeper understanding of the discrete time Kalman Filter.



As a part of this I have modeled a forced, damped, mass spring system numerically in the Jupyter Notebook available here:
https://colab.research.google.com/drive/14c3-moLnPlbWArnT5I0_MEW6zytYW6Mv



The model of the system is:



$ddot{x} = -k (x - x_0) - mu v + f sin(5t)$



Where:



$x$ is the spring position, unit $[mathrm{m}]$.



$k$ is the spring constant, unit $[mathrm{N/m}]$.



$mu$ is the viscous friction, unit $[mathrm{Ns/m}]$.



$x_0$ is the spring equilibrium position, unit $[mathrm{m}]$.



$f$ is the external force amplitude, unit $[mathrm{N}]$.



$ddot{x}$ is the double derivative of $x$ with respect to time, or $frac{mathrm{d}^2 x}{mathrm{d} t^2}$.



The question is: To my understanding this process should be optimally estimated by the Kalman filter. My understanding is that this implies that the filter estimate $hat{x}$ should be between $x pm sigma_x$ with a probability of 0.682.



In my numerical experiments the position estimate follows this relation perfectly, but the velocity estimate does not at all. I am struggling to understand the exact cause of this. The notebook explains each step of the numerics, and shows how the distribution of the position estimate and velocity estimate differ. You can edit and comment in the notebook to test changes and explain where things go wrong.



Any help to shed light on this would be greatly appreciated.










share|cite|improve this question









$endgroup$




I want to have a deeper understanding of the discrete time Kalman Filter.



As a part of this I have modeled a forced, damped, mass spring system numerically in the Jupyter Notebook available here:
https://colab.research.google.com/drive/14c3-moLnPlbWArnT5I0_MEW6zytYW6Mv



The model of the system is:



$ddot{x} = -k (x - x_0) - mu v + f sin(5t)$



Where:



$x$ is the spring position, unit $[mathrm{m}]$.



$k$ is the spring constant, unit $[mathrm{N/m}]$.



$mu$ is the viscous friction, unit $[mathrm{Ns/m}]$.



$x_0$ is the spring equilibrium position, unit $[mathrm{m}]$.



$f$ is the external force amplitude, unit $[mathrm{N}]$.



$ddot{x}$ is the double derivative of $x$ with respect to time, or $frac{mathrm{d}^2 x}{mathrm{d} t^2}$.



The question is: To my understanding this process should be optimally estimated by the Kalman filter. My understanding is that this implies that the filter estimate $hat{x}$ should be between $x pm sigma_x$ with a probability of 0.682.



In my numerical experiments the position estimate follows this relation perfectly, but the velocity estimate does not at all. I am struggling to understand the exact cause of this. The notebook explains each step of the numerics, and shows how the distribution of the position estimate and velocity estimate differ. You can edit and comment in the notebook to test changes and explain where things go wrong.



Any help to shed light on this would be greatly appreciated.







covariance kalman-filter






share|cite|improve this question













share|cite|improve this question











share|cite|improve this question




share|cite|improve this question










asked Jan 18 at 12:18









lysgaardlysgaard

62




62












  • $begingroup$
    I found the problem. The issue was coming from having an incorrect state model matrix $A$. The problem was thus purely from a bug in the numerical implementation. The numerical example has been updated to be correct. So others seeing this question in the future can have it as reference.
    $endgroup$
    – lysgaard
    Jan 21 at 12:37


















  • $begingroup$
    I found the problem. The issue was coming from having an incorrect state model matrix $A$. The problem was thus purely from a bug in the numerical implementation. The numerical example has been updated to be correct. So others seeing this question in the future can have it as reference.
    $endgroup$
    – lysgaard
    Jan 21 at 12:37
















$begingroup$
I found the problem. The issue was coming from having an incorrect state model matrix $A$. The problem was thus purely from a bug in the numerical implementation. The numerical example has been updated to be correct. So others seeing this question in the future can have it as reference.
$endgroup$
– lysgaard
Jan 21 at 12:37




$begingroup$
I found the problem. The issue was coming from having an incorrect state model matrix $A$. The problem was thus purely from a bug in the numerical implementation. The numerical example has been updated to be correct. So others seeing this question in the future can have it as reference.
$endgroup$
– lysgaard
Jan 21 at 12:37










1 Answer
1






active

oldest

votes


















0












$begingroup$

Your Kalman Filter seems to be tracking the position and velocity fairly well, so I don't think it is broken.



Have you looked at the offdiagonal elements of your covariance matrix? If these are nonzero, that would mean there is correlation between the position and velocity errors.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    The problem was found to be an incorrect model matrix, $A$. I have updated the numerical code to be correct. Thank you for the help.
    $endgroup$
    – lysgaard
    Jan 21 at 12:38











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3078170%2fkalman-filter-applied-to-linear-discrete-time-process-and-interpretation-of-the%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0












$begingroup$

Your Kalman Filter seems to be tracking the position and velocity fairly well, so I don't think it is broken.



Have you looked at the offdiagonal elements of your covariance matrix? If these are nonzero, that would mean there is correlation between the position and velocity errors.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    The problem was found to be an incorrect model matrix, $A$. I have updated the numerical code to be correct. Thank you for the help.
    $endgroup$
    – lysgaard
    Jan 21 at 12:38
















0












$begingroup$

Your Kalman Filter seems to be tracking the position and velocity fairly well, so I don't think it is broken.



Have you looked at the offdiagonal elements of your covariance matrix? If these are nonzero, that would mean there is correlation between the position and velocity errors.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    The problem was found to be an incorrect model matrix, $A$. I have updated the numerical code to be correct. Thank you for the help.
    $endgroup$
    – lysgaard
    Jan 21 at 12:38














0












0








0





$begingroup$

Your Kalman Filter seems to be tracking the position and velocity fairly well, so I don't think it is broken.



Have you looked at the offdiagonal elements of your covariance matrix? If these are nonzero, that would mean there is correlation between the position and velocity errors.






share|cite|improve this answer









$endgroup$



Your Kalman Filter seems to be tracking the position and velocity fairly well, so I don't think it is broken.



Have you looked at the offdiagonal elements of your covariance matrix? If these are nonzero, that would mean there is correlation between the position and velocity errors.







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered Jan 18 at 13:41









SRVfender01SRVfender01

112




112












  • $begingroup$
    The problem was found to be an incorrect model matrix, $A$. I have updated the numerical code to be correct. Thank you for the help.
    $endgroup$
    – lysgaard
    Jan 21 at 12:38


















  • $begingroup$
    The problem was found to be an incorrect model matrix, $A$. I have updated the numerical code to be correct. Thank you for the help.
    $endgroup$
    – lysgaard
    Jan 21 at 12:38
















$begingroup$
The problem was found to be an incorrect model matrix, $A$. I have updated the numerical code to be correct. Thank you for the help.
$endgroup$
– lysgaard
Jan 21 at 12:38




$begingroup$
The problem was found to be an incorrect model matrix, $A$. I have updated the numerical code to be correct. Thank you for the help.
$endgroup$
– lysgaard
Jan 21 at 12:38


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3078170%2fkalman-filter-applied-to-linear-discrete-time-process-and-interpretation-of-the%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter