summaryrefslogtreecommitdiff
path: root/src/signalProcessing/lev/dleva2.c
diff options
context:
space:
mode:
authortorset2009-02-10 13:52:09 +0000
committertorset2009-02-10 13:52:09 +0000
commit9cea656d20e16294356b99e360d93ab64e3e1e54 (patch)
treef0a587b6c4ffe20b491de41e46df4f77b07fe695 /src/signalProcessing/lev/dleva2.c
parentf9c7b6ca2059bc2f6737a406b4edfa34e32c57aa (diff)
downloadscilab2c-9cea656d20e16294356b99e360d93ab64e3e1e54.tar.gz
scilab2c-9cea656d20e16294356b99e360d93ab64e3e1e54.tar.bz2
scilab2c-9cea656d20e16294356b99e360d93ab64e3e1e54.zip
Add lev files end linked files
Diffstat (limited to 'src/signalProcessing/lev/dleva2.c')
-rw-r--r--src/signalProcessing/lev/dleva2.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/signalProcessing/lev/dleva2.c b/src/signalProcessing/lev/dleva2.c
new file mode 100644
index 00000000..34a304a6
--- /dev/null
+++ b/src/signalProcessing/lev/dleva2.c
@@ -0,0 +1,68 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - INRIA - Arnaud TORSET
+ *
+ * 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
+ *
+ */
+
+
+/*Resolve the Yule-Walker equations:
+
+ |r(0) r(1) ... r(N-1)|| a(1) | |sigma2|
+ |r(1) r(0) ... r(n-1)|| a(2) | | 0 |
+ | : : ... : || : |=| 0 |
+ | : : ... : || : | | 0 |
+ |r(N-1) r(N-2) ... r(0) ||a(N-1)| | 0 |
+
+ using Levinson's algorithm.
+ r :Correlation coefficients
+ ar :Auto-Regressive model parameters
+ sigma2 :Scale constant
+ rc :Reflection coefficients
+*/
+
+
+#include "lev.h"
+#include "malloc.h"
+#include "stdlib.h"
+
+
+double dleva2(double* in,int size, double* ar){
+ int i=0, j=0;
+ double accu=0;
+ double* ak1;
+ double sigma2;
+
+ /* FIXME : malloc here */
+ ak1=malloc((uint)size*sizeof(double));
+
+ /* initialize levinson's algorithm */
+ ar[0]=-in[1]/in[0];
+ sigma2=(1-ar[0]*ar[0])*in[0];
+ ak1[0]=0;
+
+ /* iterative solution to yule-walker equations */
+ for (i=1;i<size-1;i++){
+ accu=0;
+ for (j=0;j<i;j++){
+ accu+=ar[j]*in[i-j];
+ }
+ ak1[i]=-(in[i+1]+accu)/(sigma2);
+ for (j=0;j<i;j++){
+ ak1[j] = ar[j]+ak1[i]*ar[i-1-j];
+ }
+ sigma2=(1-ak1[i]*ak1[i])*(sigma2);
+ for (j=0;j<=i;j++){
+ ar[j]=ak1[j];
+ }
+ }
+ free(ak1);
+ return sigma2;
+}
+
+