From db464f35f5a10b58d9ed1085e0b462689adee583 Mon Sep 17 00:00:00 2001 From: Siddhesh Wani Date: Mon, 25 May 2015 14:46:31 +0530 Subject: Original Version --- src/c/signalProcessing/lev/cleva.c | 85 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/c/signalProcessing/lev/cleva.c (limited to 'src/c/signalProcessing/lev/cleva.c') diff --git a/src/c/signalProcessing/lev/cleva.c b/src/c/signalProcessing/lev/cleva.c new file mode 100644 index 0000000..5d4b964 --- /dev/null +++ b/src/c/signalProcessing/lev/cleva.c @@ -0,0 +1,85 @@ +/* + * 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 +#include "lev.h" +#include "conj.h" +#include "multiplication.h" +#include "addition.h" +#include "division.h" +#include "subtraction.h" + + +floatComplex cleva(floatComplex* in,int size, floatComplex* ar, floatComplex* rc){ + int i=0, j=0; + floatComplex accu=FloatComplex(0,0); + floatComplex* ak1; + floatComplex temp; + floatComplex sigma2; + + /* FIXME : malloc here */ + ak1=(floatComplex*)malloc((unsigned int)size*sizeof(floatComplex)); + + /* initialize levinson's algorithm */ + temp=crdivs(in[1],in[0]); + ar[0]=FloatComplex(-creals(temp),-cimags(temp)); + + rc[0]=ar[0]; + + temp = cmuls(ar[0],cconjs(ar[0])); + sigma2=cmuls(cdiffs(FloatComplex(1,0), temp), in[0]); + + ak1[0]=FloatComplex(0,0); + + /* iterative solution to yule-walker equations */ + for (i=1;i