summaryrefslogtreecommitdiff
path: root/macros/yulewalker.sci
diff options
context:
space:
mode:
authorSunil Shetye2018-07-25 17:32:17 +0530
committerSunil Shetye2018-07-26 23:50:17 +0530
commitcdd55940b7a287810e423017c42e7c965815c468 (patch)
treed802563d2d507039354a3cf48e75465b7e7a8d76 /macros/yulewalker.sci
parent1251f70aa3442736ce6fd9c4fb7fbce412af5a52 (diff)
downloadFOSSEE-Signal-Processing-Toolbox-cdd55940b7a287810e423017c42e7c965815c468.tar.gz
FOSSEE-Signal-Processing-Toolbox-cdd55940b7a287810e423017c42e7c965815c468.tar.bz2
FOSSEE-Signal-Processing-Toolbox-cdd55940b7a287810e423017c42e7c965815c468.zip
code changes by Shashikiran Yadalam during FOSSEE Fellowship 2018
Diffstat (limited to 'macros/yulewalker.sci')
-rw-r--r--macros/yulewalker.sci54
1 files changed, 39 insertions, 15 deletions
diff --git a/macros/yulewalker.sci b/macros/yulewalker.sci
index 40fcadb..22fbd77 100644
--- a/macros/yulewalker.sci
+++ b/macros/yulewalker.sci
@@ -1,32 +1,56 @@
-function [A,V]= yulewalker(C)
+// Copyright (C) 2018 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function [A,V]= yulewalker(c)
// Fit an AR (p)-model with Yule-Walker estimates given a vector C of autocovariances '[gamma_0, ..., gamma_p]'.
//Calling Sequence
//A = yulewalker(C)
//[A,V]= yulewalker(C)
-//Parameters
+//Parameters
//C: Autocovariances
//Description
//Fit an AR (p)-model with Yule-Walker estimates given a vector C of autocovariances '[gamma_0, ..., gamma_p]'.
//Returns the AR coefficients, A, and the variance of white noise, V.
+
+//Test cases
+//[A,V]=yulewalker([1 2 3])
+// V = - 2.6666667
+// A =1.3333333
+// 0.3333333
+
+
funcprot(0);
lhs=argn(1);
rhs= argn(2);
-if(rhs<1 | rhs>1)
- error("Wrong number of input arguments");
-end
+ if (rhs ~= 1)
+ error ("wrong number of input arguments");
+ end
+
+ p = length (c) - 1;
-if(lhs<1 | lhs>2)
- error("Wrong number of output arguments");
-end
+ if (size (c,"c") > 1)
+ c = c';
+ end
-select(lhs)
+ cp = c(2 : p+1);
+ CP = zeros (p, p);
- case 1 then
- A= callOctave("yulewalker", C);
- case 2 then
- [A,V]= callOctave("yulewalker", C);
-end
-endfunction
+ for i = 1:p
+ for j = 1:p
+ CP (i, j) = c (abs (i-j) + 1);
+ end
+ end
+ A = inv (CP) * cp;
+ V = c(1) -A' * cp;
+endfunction