/scilab-master-1333395999/modules/signal_processing/macros/system.sci

# · Unknown · 43 lines · 41 code · 2 blank · 0 comment · 0 complexity · e704ba74bc95d96d405217dca3dc2dd5 MD5 · raw file

  1. // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  2. // Copyright (C) 1988 - INRIA - C. Bunks
  3. // Copyright (C) DIGITEO - 2011 - Allan CORNET
  4. //
  5. // This file must be used under the terms of the CeCILL.
  6. // This source file is licensed as described in the file COPYING, which
  7. // you should have received as part of this distribution. The terms
  8. // are also available at
  9. // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
  10. //
  11. function [x1, y] = system(x0, f, g, h, q, r)
  12. //<x1,y>=system(x0,f,g,h,q,r)
  13. //define system macro which generates the next
  14. //observation given the old state
  15. // x0 :Input state vector
  16. // f :System matrix
  17. // g :Input matrix
  18. // h :Output matrix
  19. // q :Input noise covariance matrix
  20. // r :Output noise covariance matrix
  21. // x1 :Output state vector
  22. // y :Output observation
  23. //System recursively calculates
  24. //
  25. // x1=f*x0+g*u
  26. // y=h*x0+v
  27. //
  28. //where u is distributed N(0,q)
  29. //and v is distribute N(0,r).
  30. [lhs, rhs] = argn(0);
  31. if rhs == 0 then
  32. error(999, msprintf(_("%s: Wrong number of input argument(s).\n"), "system"));
  33. end
  34. rand('normal');
  35. q2 = chol(q);
  36. r2 = chol(r);
  37. u = q2' * rand(ones(x0));
  38. v = r2' * rand(ones(x0));
  39. x1 = f * x0 + g * u;
  40. y = h * x0 + v;
  41. endfunction