diff options
author | torset | 2009-02-11 11:10:51 +0000 |
---|---|---|
committer | torset | 2009-02-11 11:10:51 +0000 |
commit | bb1a8ae28e166d28b3bcfde59bd11a0bf71df26c (patch) | |
tree | e4ff3d0d8c20b901b051e11595926cc93a06b216 | |
parent | 8c23bcfa3632f1140d32fa86d9a950ffe8f9faeb (diff) | |
download | scilab2c-bb1a8ae28e166d28b3bcfde59bd11a0bf71df26c.tar.gz scilab2c-bb1a8ae28e166d28b3bcfde59bd11a0bf71df26c.tar.bz2 scilab2c-bb1a8ae28e166d28b3bcfde59bd11a0bf71df26c.zip |
separate levinUtils from levin.h and modify functions(which wheren't good)
-rw-r--r-- | src/signalProcessing/includes/levin.h | 61 | ||||
-rw-r--r-- | src/signalProcessing/interfaces/int_levin.h | 37 | ||||
-rw-r--r-- | src/signalProcessing/levin/Makefile.am | 15 | ||||
-rw-r--r-- | src/signalProcessing/levin/Makefile.in | 16 | ||||
-rw-r--r-- | src/signalProcessing/levin/dlevina.c | 89 | ||||
-rw-r--r-- | src/signalProcessing/levin/levinUtils.c | 195 | ||||
-rw-r--r-- | src/signalProcessing/levin/levinUtils.h | 71 | ||||
-rw-r--r-- | src/signalProcessing/levin/slevina.c | 87 | ||||
-rw-r--r-- | src/signalProcessing/levin/testDoubleLevin.c | 146 | ||||
-rw-r--r-- | src/signalProcessing/levin/testFloatLevin.c | 152 |
10 files changed, 446 insertions, 423 deletions
diff --git a/src/signalProcessing/includes/levin.h b/src/signalProcessing/includes/levin.h index f2c7fd91..c39206f9 100644 --- a/src/signalProcessing/includes/levin.h +++ b/src/signalProcessing/includes/levin.h @@ -21,66 +21,5 @@ void slevina (int n, float* cov, int lCov, int cCov, float* la, float* sig, floa - - -/* levinUtils.c */ -void dr1(double *in,int lines,int columns, int n, double * out); -void dr2(double *in,int lines,int columns, int n, double * out); -void dr3(double *in,int lines,int columns, int n, double * out); -void dr4(double *in,int lines,int columns, int n, double * out); -void sr1(float *in,int lines,int columns, int n, float * out); -void sr2(float *in,int lines,int columns, int n, float * out); -void sr3(float *in,int lines,int columns, int n, float * out); -void sr4(float *in,int lines,int columns, int n, float * out); - - - -/*multiplications used in levin program, are differents from the classic multiplication*/ -/* - in1,in2 : matrices to multiply - n : - columns : number of columns of in2 - ind_boucle : indice of the loop - out : result matrix - lines : number of lines of the result - deb_out : 0 if the result start to the indice 0, 1 otherwise - choix : 'u' or 'd', depends of in2. We take either the k first elements of in2 ('u') or the k last ('d'), - k is a nomber which depends of the indice of loop, the columns ... - */ -void dlevinmul(double* in1, double* in2, int n, int columns, int ind_boucle, double* out, int lines, int deb_out,char choix); -void dlevinmul2(double* in1, double *in2,int ind_boucle,int n,int columns,double* out); -void slevinmul(float* in1, float* in2, int n, int columns, int ind_boucle, float* out, int lines, int deb_out,char choix); -void slevinmul2(float* in1, float *in2,int ind_boucle,int n,int columns,float* out); - - -/*take the values of sig wanted*/ -void dlevinsig(double *sig,int n, int columns, int lines, double *sig1); -void slevinsig(float *sig,int n, int columns, int lines, float *sig1); - -/*a subtraction used in levin program, is different from the classic subtraction cause of the indices*/ -/* - in1,in2 : matrices to subtract - n : - columns : number of columns of in2 - deb_in : place of the first element of in1 - ind_boucle : indice of the loop - out : result matrix - */ -void dlevinsub(double* in1, double* in2, int n, int columns, int deb_in, int ind_boucle, double* out); -void slevinsub(float* in1, float* in2, int n, int columns, int deb_in, int ind_boucle, float* out); - -/*initialize a table*/ -void dinitTab(double* in, int size); -void sinitTab(float* in, int size); - -/*used for the multiplication by z which is equal to step forward*/ -void ddecalage(double* in, int deb_in,int n,int columns,double * out); -void sdecalage(float* in, int deb_in,int n,int columns,float * out); - -/*end*/ - - - - #endif /*__LEVIN_H__*/ diff --git a/src/signalProcessing/interfaces/int_levin.h b/src/signalProcessing/interfaces/int_levin.h new file mode 100644 index 00000000..82831428 --- /dev/null +++ b/src/signalProcessing/interfaces/int_levin.h @@ -0,0 +1,37 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008-2008 - INRIA - Bruno JOFRET + * + * 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 + * + */ + +/* THIS IS AN AUTOMATICALLY GENERATED FILE : DO NOT EDIT BY HAND. */ + +#ifndef __INT_LEVIN_H__ +#define __INT_LEVIN_H__ +/* FIXME : malloc here */ +#define s0s2levins2s2(in1,in2,size,out1,out2) {float* out3;\ + out3 = malloc((uint)*(size[1]*size[1]*in1*(in1+1))*sizeof(float));\ + slevina (in1, in2, size[0], size[1], out1, out2, out3);\ + free(out3);\ + } + +#define d0d2levind2d2(in1,in2,size,out1,out2) {double* out3;\ + out3 = malloc((uint)*(size[1]*size[1]*in1*(in1+1))*sizeof(double));\ + dlevina (in1, in2, size[0], size[1], out1, out2, out3);\ + free(out3);\ + } + + + +#define s0s2levins2s2s2(in1,in2,size,out1,out2,out3) slevina (in1, in2, size[0], size[1], out1, out2, out3); + +#define d0d2levind2d2d2(in1,in2,size,out1,out2,out3) dlevina (in1, in2, size[0], size[1], out1, out2, out3); + + +#endif /* !__INT_LEVIN_H__ */ diff --git a/src/signalProcessing/levin/Makefile.am b/src/signalProcessing/levin/Makefile.am index 748b03d0..bd8336d0 100644 --- a/src/signalProcessing/levin/Makefile.am +++ b/src/signalProcessing/levin/Makefile.am @@ -14,11 +14,12 @@ libLevin_la_CFLAGS = -I $(top_builddir)/type \ - -I $(top_builddir)/matrixOperations/includes \ - -I $(top_builddir)/operations/includes \ - -I $(top_builddir)/auxiliaryFunctions/includes \ - -I $(top_builddir)/elementaryFunctions/includes \ - -I $(top_builddir)/signalProcessing/includes + -I $(top_builddir)/matrixOperations/includes \ + -I $(top_builddir)/operations/includes \ + -I $(top_builddir)/auxiliaryFunctions/includes \ + -I $(top_builddir)/elementaryFunctions/includes \ + -I $(top_builddir)/signalProcessing/includes \ + -I $(top_builddir)/signalProcessing/levin instdir = $(top_builddir)/lib @@ -47,6 +48,7 @@ check_LDADD = $(top_builddir)/type/libDoubleComplex.la \ $(top_builddir)/lib/lapack/libscilapack.la \ $(top_builddir)/matrixOperations/inversion/libMatrixInversion.la \ $(top_builddir)/matrixOperations/multiplication/libMatrixMultiplication.la \ + $(top_builddir)/matrixOperations/zeros/libMatrixZeros.la \ $(top_builddir)/signalProcessing/levin/libLevin.la \ $(top_builddir)/operations/addition/libAddition.la \ $(top_builddir)/operations/multiplication/libMultiplication.la \ @@ -58,7 +60,8 @@ check_INCLUDES = -I $(top_builddir)/type \ -I $(top_builddir)/matrixOperations/includes \ -I $(top_builddir)/operations/includes \ -I $(top_builddir)/auxiliaryFunctions/includes \ - -I $(top_builddir)/signalProcessing/includes + -I $(top_builddir)/signalProcessing/includes \ + -I $(top_builddir)/signalProcessing/levin testDoubleLevin_SOURCES = testDoubleLevin.c diff --git a/src/signalProcessing/levin/Makefile.in b/src/signalProcessing/levin/Makefile.in index d082b981..51af48a8 100644 --- a/src/signalProcessing/levin/Makefile.in +++ b/src/signalProcessing/levin/Makefile.in @@ -69,6 +69,7 @@ am__DEPENDENCIES_1 = $(top_builddir)/type/libDoubleComplex.la \ $(top_builddir)/lib/lapack/libscilapack.la \ $(top_builddir)/matrixOperations/inversion/libMatrixInversion.la \ $(top_builddir)/matrixOperations/multiplication/libMatrixMultiplication.la \ + $(top_builddir)/matrixOperations/zeros/libMatrixZeros.la \ $(top_builddir)/signalProcessing/levin/libLevin.la \ $(top_builddir)/operations/addition/libAddition.la \ $(top_builddir)/operations/multiplication/libMultiplication.la \ @@ -213,11 +214,12 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ libLevin_la_CFLAGS = -I $(top_builddir)/type \ - -I $(top_builddir)/matrixOperations/includes \ - -I $(top_builddir)/operations/includes \ - -I $(top_builddir)/auxiliaryFunctions/includes \ - -I $(top_builddir)/elementaryFunctions/includes \ - -I $(top_builddir)/signalProcessing/includes + -I $(top_builddir)/matrixOperations/includes \ + -I $(top_builddir)/operations/includes \ + -I $(top_builddir)/auxiliaryFunctions/includes \ + -I $(top_builddir)/elementaryFunctions/includes \ + -I $(top_builddir)/signalProcessing/includes \ + -I $(top_builddir)/signalProcessing/levin instdir = $(top_builddir)/lib pkglib_LTLIBRARIES = libLevin.la @@ -233,6 +235,7 @@ check_LDADD = $(top_builddir)/type/libDoubleComplex.la \ $(top_builddir)/lib/lapack/libscilapack.la \ $(top_builddir)/matrixOperations/inversion/libMatrixInversion.la \ $(top_builddir)/matrixOperations/multiplication/libMatrixMultiplication.la \ + $(top_builddir)/matrixOperations/zeros/libMatrixZeros.la \ $(top_builddir)/signalProcessing/levin/libLevin.la \ $(top_builddir)/operations/addition/libAddition.la \ $(top_builddir)/operations/multiplication/libMultiplication.la \ @@ -243,7 +246,8 @@ check_INCLUDES = -I $(top_builddir)/type \ -I $(top_builddir)/matrixOperations/includes \ -I $(top_builddir)/operations/includes \ -I $(top_builddir)/auxiliaryFunctions/includes \ - -I $(top_builddir)/signalProcessing/includes + -I $(top_builddir)/signalProcessing/includes \ + -I $(top_builddir)/signalProcessing/levin testDoubleLevin_SOURCES = testDoubleLevin.c testDoubleLevin_LDADD = $(check_LDADD) diff --git a/src/signalProcessing/levin/dlevina.c b/src/signalProcessing/levin/dlevina.c index f3daed9f..d19efbc6 100644 --- a/src/signalProcessing/levin/dlevina.c +++ b/src/signalProcessing/levin/dlevina.c @@ -11,8 +11,10 @@ */ #include "levin.h" +#include "levinUtils.h" #include "matrixInversion.h" #include "matrixMultiplication.h" +#include "zeros.h" #include <malloc.h> #include <stdio.h> @@ -32,13 +34,16 @@ void dlevina (int n, double* cov, int lCov, int cCov, double* la, double* sig, d Enter now in a element of the list. Take the first for example. This is, like said before, a cCov*cCov matrix. In la, it contains (n+1)*cCov*cCov. Each element of the matrix contains (n+1) elements. As it's stocked by columns, if we represent a matrix like [a c], for example, the elements 0 to n of la represent - [b d] + [b d] a, the elements (n+1) to 2(n+1)-1 represent b,... To finish, look at the elements of the matrix, the polynomes. The coefficients of the polynomes are stocked in increasing order. - For example, if la in Scilab is : list( [3+2x 5-2x ],[3+x-x^2 -1+2x ]) - ( [-5+x -2+4x],[1+6x+3x^2 -2x-x^2 ]), the result in dlevin will be : + For example, if la in Scilab is : list( [3+2x 5-2x ]) + ( [-5+x -2+4x]) + ([3+x-x^2 -1+2x ]) + ([1+6x+3x^2 -2x-x^2 ]) + the result in dlevin will be : -la is a table of 2*3*2*2 elements(n=2,cCov=2); -la[]={3,2,0, -5,1,0, 5,-2,0, -2,4,0, 3,1,-1, 1,6,3 -1,2,0, 0,-2,-1}. @@ -50,16 +55,24 @@ void dlevina (int n, double* cov, int lCov, int cCov, double* la, double* sig, d The greatest size of a element of the list is : cCov*cCov. Let see an example so know how it's stocked. - In Scilab, if sig is : list( [1 3],[5 7]) - ( [2 4],[6 8]),the result in dlevin will be : + In Scilab, if sig is : list( [1 3]) + ( [2 4]) + ( [5 7]) + ( [6 8]) + the result in dlevin will be : -sig={1,2, 5,6, 3,4, 7,8}. It's as if we put the matrix the ones under the others and we take the first column, the second,... - + >>>CAREFUL<<< + la/lb and sig are stored differently */ + + int i=0; + + /*version ISO C99 double tmp1[n*cCov*cCov], tmp2[n*cCov*cCov]; double sig1[cCov], gam[cCov]; @@ -70,7 +83,7 @@ void dlevina (int n, double* cov, int lCov, int cCov, double* la, double* sig, d double *sig1, *gam; double *R1,*R2,*R3,*R4; - + /* FIXME : malloc here */ tmp1=malloc((unsigned int)((n+1)*cCov*cCov)*sizeof(double)); tmp2=malloc((unsigned int)((n+1)*cCov*cCov)*sizeof(double)); @@ -86,9 +99,9 @@ void dlevina (int n, double* cov, int lCov, int cCov, double* la, double* sig, d /* * Initializations * */ - dinitTab(sig,n*cCov*cCov); - dinitTab(la,n*(n+1)*cCov*cCov); - dinitTab(lb,n*(n+1)*cCov*cCov); + dzerosa(sig,n*cCov*cCov,1); + dzerosa(la,n*(n+1)*cCov*cCov,1); + dzerosa(lb,n*(n+1)*cCov*cCov,1); /*equal to eye(la) and eye(lb) but we can't use eye cause to the indexation*/ @@ -105,49 +118,38 @@ void dlevina (int n, double* cov, int lCov, int cCov, double* la, double* sig, d /* case i=0 */ - /*calculation of sig */ + /*computation of sig */ dlevinmul(la,R4,n,cCov,0,sig,n*cCov,0,'d'); - /*calculation of gam1 */ + /*computation of gam1 */ dlevinmul(lb,R2,n,cCov,0,gam,cCov,0,'u'); - /*calculation of c1*r1 */ + /*computation of c1*r1 */ dlevinmul(la,R1,n,cCov,0,tmp1,cCov,0,'u'); - /*calculation of inv(gam1) */ + /*computation of inv(gam1) */ dinverma(gam,sig1,cCov); - dinitTab(gam,cCov*cCov); - /*calculation of k1 = c1*r1*inv(gam1) */ + /*computation of k1 = c1*r1*inv(gam1) */ dmulma(tmp1,cCov,cCov,sig1,cCov,cCov,tmp2); - dinitTab(tmp1,n*cCov*cCov); - dinitTab(sig1,cCov*cCov); - /*calculation of k1*lb */ + /*computation of k1*lb */ dlevinmul2(tmp2,lb,0,n,cCov,tmp1); - dinitTab(tmp2,n*cCov*cCov); - /*calculation of k1*lb*z */ + /*computation of k1*lb*z */ ddecalage(tmp1,0,n,cCov,tmp1); - /*calculation of la */ + /*computation of la */ dlevinsub(la,tmp1,n,cCov,0,0,la); - dinitTab(tmp1,n*cCov*cCov); - /*calculation of sig1 (we extract the value if sig at time 0)*/ + /*computation of sig1 (we extract the value if sig at time 0)*/ dlevinsig(sig,0,cCov,n*cCov,sig1); - /*calculation of c2*r3 */ + /*computation of c2*r3 */ dlevinmul(lb,R3,n,cCov,0,tmp1,cCov,0,'d'); - /*calculation of inv(sig1)*/ + /*computation of inv(sig1)*/ dinverma(sig1,gam,cCov); - dinitTab(sig1,cCov*cCov); - /*calculation of k2 = c2*r3*inv(sig1) */ + /*computation of k2 = c2*r3*inv(sig1) */ dmulma(tmp1,cCov,cCov,gam,cCov,cCov,tmp2); - dinitTab(tmp1,n*cCov*cCov); - dinitTab(gam,cCov*cCov); - /*calculation of k2*la (here it's lb cause la have been modified + /*computation of k2*la (here it's lb cause la have been modified and the precedent values hadn't been saved)*/ dlevinmul2(tmp2,lb,0,n,cCov,tmp1); - dinitTab(tmp2,n*cCov*cCov); - /*calculation of lb*z */ + /*computation of lb*z */ ddecalage(lb,0,n,cCov,lb); - /*calculation of lb */ + /*computation of lb */ dlevinsub(lb,tmp1,n,cCov,0,0,lb); - dinitTab(tmp1,n*cCov*cCov); - dinitTab(tmp2,n*cCov*cCov); for (i=1;i<n;i++){ @@ -155,30 +157,21 @@ void dlevina (int n, double* cov, int lCov, int cCov, double* la, double* sig, d dlevinmul(lb,R2,n,cCov,i,gam,cCov,0,'u'); dlevinmul(la,R1,n,cCov,i,tmp1,cCov,0,'u'); dinverma(gam,sig1,cCov); - dinitTab(gam,cCov*cCov); dmulma(tmp1,cCov,cCov,sig1,cCov,cCov,tmp2); - - dinitTab(tmp1,n*cCov*cCov); + dlevinmul2(tmp2,lb,i-1,n,cCov,tmp1); - dinitTab(tmp2,n*cCov*cCov); ddecalage(tmp1,0,n,cCov,tmp1); dlevinsub(la,tmp1,n,cCov,i,i,la);/*a*/ - dinitTab(tmp1,n*cCov*cCov); - /*calculation of sig1 (we extract the value if sig at time i)*/ + /*computation of sig1 (we extract the value if sig at time i)*/ dlevinsig(sig,i,cCov,n*cCov,sig1); dlevinmul(lb,R3,n,cCov,i,tmp1,cCov,0,'d'); dinverma(sig1,gam,cCov); - dinitTab(sig1,cCov*cCov); dmulma(tmp1,cCov,cCov,gam,cCov,cCov,tmp2); - dinitTab(tmp1,n*cCov*cCov); - /*calculation of k2*la (now it's la at time (i-1))*/ + /*computation of k2*la (now it's la at time (i-1))*/ dlevinmul2(tmp2,la,i-1,n,cCov,tmp1); - dinitTab(tmp2,n*cCov*cCov); ddecalage(lb,(i-1)*(n+1)*cCov*cCov,n,cCov,tmp2); dlevinsub(tmp2,tmp1,n,cCov,0,i,lb); - dinitTab(tmp1,n*cCov*cCov); - dinitTab(tmp2,n*cCov*cCov); } diff --git a/src/signalProcessing/levin/levinUtils.c b/src/signalProcessing/levin/levinUtils.c index b7eb2b4a..0048c860 100644 --- a/src/signalProcessing/levin/levinUtils.c +++ b/src/signalProcessing/levin/levinUtils.c @@ -1,72 +1,90 @@ -#include "levin.h" +/* + * 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 + * + */ + + + + +#include "levinUtils.h" +#include "stdio.h" /* Double Functions */ -void dr1(double *in,int lines, int rows, int n, double * out){ +void dr1(double *in,int lines, int columns, int n, double * out){ int i,j; - for (i=0;i<n*rows;i++) { - for (j=0;j<rows;j++){ - out[i+j*n*rows]=in[(n-i/rows)*rows + i%rows + j*lines]; + for (i=0;i<n*columns;i++) { + for (j=0;j<columns;j++){ + out[i+j*n*columns]=in[(n-i/columns)*columns + i%columns + j*lines]; } } } -void dr2(double *in,int lines, int rows, int n, double * out){ +void dr2(double *in,int lines, int columns, int n, double * out){ int i,j; - for (i=0;i<n*rows;i++) { - for (j=0;j<rows;j++){ - out[i+j*n*rows]=in[(n-1-i/rows)*rows + i%rows + j*lines]; + for (i=0;i<n*columns;i++) { + for (j=0;j<columns;j++){ + out[i+j*n*columns]=in[(n-1-i/columns)*columns + i%columns + j*lines]; } } } -void dr3(double *in,int lines, int rows, int n, double * out){ +void dr3(double *in,int lines, int columns, int n, double * out){ int i,j; - for (i=0;i<n*rows;i++) { - for (j=0;j<rows;j++){ - out[i+j*n*rows]=in[(i/rows+1)*rows + j%rows + (i%rows)*lines]; + for (i=0;i<n*columns;i++) { + for (j=0;j<columns;j++){ + out[i+j*n*columns]=in[(i/columns+1)*columns + j%columns + (i%columns)*lines]; } } } -void dr4(double *in,int lines, int rows, int n, double * out){ +void dr4(double *in,int lines, int columns, int n, double * out){ int i,j; - for (i=0;i<n*rows;i++) { - for (j=0;j<rows;j++){ - out[i+j*n*rows]=in[i + j%rows + (i%rows)*(lines-1)]; + for (i=0;i<n*columns;i++) { + for (j=0;j<columns;j++){ + if ( (j*n*columns-1<i+j*n*columns) && (i+j*n*columns<j*n*columns+columns) ) + out[i+j*n*columns]=in[i+j*lines]; + else out[i+j*n*columns]=in[i + j%columns + (i%columns)*(lines-1)]; } } } -void dlevinmul(double* in1, double* in2, int n, int rows, int ind_boucle, double* out, int lines, int deb_out,char choix){ +void dlevinmul(double* in1, double* in2, int n, int columns, int ind_boucle, double* out, int lines, int deb_out,char choix){ int i=0, j=0, debut=0,start_out=0; double accu; if (ind_boucle==0) debut=0; - else debut = (ind_boucle-1)*(n+1)*rows*rows; + else debut = (ind_boucle-1)*(n+1)*columns*columns; - start_out = deb_out*ind_boucle*rows; + start_out = deb_out*ind_boucle*columns; switch(choix){ case 'u' : - for (i=0;i<rows*rows;i++){ + for (i=0;i<columns*columns;i++){ accu=0; - for(j=0;j<ind_boucle*rows+rows;j++){ - accu += in1[debut+i%rows*(n+1) + (rows*(n+1))*(j%rows)+j/rows] * in2[n*rows-((ind_boucle+1)*rows)+j+(i/rows)*n*rows]; + for(j=0;j<ind_boucle*columns+columns;j++){ + accu += in1[debut+i%columns*(n+1) + (columns*(n+1))*(j%columns)+j/columns] * in2[n*columns-((ind_boucle+1)*columns)+j+(i/columns)*n*columns]; } - out[start_out+i%rows+(i/rows)*lines] = accu; + out[start_out+i%columns+(i/columns)*lines] = accu; } break; case 'd' : - for (i=0;i<rows*rows;i++){ + for (i=0;i<columns*columns;i++){ accu=0; - for(j=0;j<ind_boucle*rows+rows;j++){ - accu+=in1[debut+i%rows*(n+1) + (rows*(n+1))*(j%rows)+j/rows]*in2[j+(i/rows)*n*rows]; + for(j=0;j<ind_boucle*columns+columns;j++){ + accu+=in1[debut+i%columns*(n+1) + (columns*(n+1))*(j%columns)+j/columns]*in2[j+(i/columns)*n*columns]; } - out[start_out+i%rows+(i/rows)*lines] = accu; + out[start_out+i%columns+(i/columns)*lines] = accu; } break; default : break; @@ -75,51 +93,47 @@ void dlevinmul(double* in1, double* in2, int n, int rows, int ind_boucle, double -void dlevinsig(double *sig,int n, int rows, int lines, double *sig1){ +void dlevinsig(double *sig,int n, int columns, int lines, double *sig1){ int i=0; - for (i=0;i<rows*rows;i++){ - sig1[i]=sig[n*rows + i%rows +(i/rows)*lines]; + for (i=0;i<columns*columns;i++){ + sig1[i]=sig[n*columns + i%columns +(i/columns)*lines]; } } -void dlevinmul2(double* in1, double *in2,int ind_boucle,int n,int rows,double* out){ +void dlevinmul2(double* in1, double *in2,int ind_boucle,int n,int columns,double* out){ int i=0,j=0, debut; double accu; - debut = ind_boucle*(n+1)*rows*rows; - for(i=0;i<(n+1)*rows*rows;i++){ + debut = ind_boucle*(n+1)*columns*columns; + for(i=0;i<(n+1)*columns*columns;i++){ accu=0; - for (j=0;j<rows;j++){ - accu += in1[(i/(n+1))%rows+j*rows]*in2[debut+i%(n+1)+(i/((n+1)*rows))*(n+1)*rows+j*(n+1)]; + for (j=0;j<columns;j++){ + accu += in1[(i/(n+1))%columns+j*columns]*in2[debut+i%(n+1)+(i/((n+1)*columns))*(n+1)*columns+j*(n+1)]; } out[i]=accu; } } -void dlevinsub(double* in1, double* in2, int n, int rows, int deb_in, int ind_boucle, double* out){ +void dlevinsub(double* in1, double* in2, int n, int columns, int deb_in, int ind_boucle, double* out){ int i=0; - int deb_out= ind_boucle*(n+1)*rows*rows; + int deb_out= ind_boucle*(n+1)*columns*columns; int deb_in1; if (deb_in==0) deb_in1=0; - else deb_in1=(deb_in-1)*(n+1)*rows*rows; + else deb_in1=(deb_in-1)*(n+1)*columns*columns; - for (i=0;i<(n+1)*rows*rows;i++){ + for (i=0;i<(n+1)*columns*columns;i++){ out[deb_out + i] = in1[deb_in1+i]-in2[i]; } } -void dinitTab(double* in, int size){ - int i; - for (i=0;i<size;i++) in[i]=0; -} -void ddecalage(double* in, int deb_in,int n,int rows,double *out){ +void ddecalage(double* in, int deb_in,int n,int columns,double *out){ int i=0,j=0; - for (i=0;i<rows*rows;i++){ + for (i=0;i<columns*columns;i++){ for(j=n;j>0;j--) {out[i*(n+1)+j]=in[i*(n+1)+deb_in+j-1];} out[i*(n+1)]=0; } @@ -132,72 +146,74 @@ void ddecalage(double* in, int deb_in,int n,int rows,double *out){ /* Float Functions */ -void sr1(float *in,int lines, int rows, int n, float * out){ +void sr1(float *in,int lines, int columns, int n, float * out){ int i,j; - for (i=0;i<n*rows;i++) { - for (j=0;j<rows;j++){ - out[i+j*n*rows]=in[(n-i/rows)*rows + i%rows + j*lines]; + for (i=0;i<n*columns;i++) { + for (j=0;j<columns;j++){ + out[i+j*n*columns]=in[(n-i/columns)*columns + i%columns + j*lines]; } } } -void sr2(float *in,int lines, int rows, int n, float * out){ +void sr2(float *in,int lines, int columns, int n, float * out){ int i,j; - for (i=0;i<n*rows;i++) { - for (j=0;j<rows;j++){ - out[i+j*n*rows]=in[(n-1-i/rows)*rows + i%rows + j*lines]; + for (i=0;i<n*columns;i++) { + for (j=0;j<columns;j++){ + out[i+j*n*columns]=in[(n-1-i/columns)*columns + i%columns + j*lines]; } } } -void sr3(float *in,int lines, int rows, int n, float * out){ +void sr3(float *in,int lines, int columns, int n, float * out){ int i,j; - for (i=0;i<n*rows;i++) { - for (j=0;j<rows;j++){ - out[i+j*n*rows]=in[(i/rows+1)*rows + j%rows + (i%rows)*lines]; + for (i=0;i<n*columns;i++) { + for (j=0;j<columns;j++){ + out[i+j*n*columns]=in[(i/columns+1)*columns + j%columns + (i%columns)*lines]; } } } -void sr4(float *in,int lines, int rows, int n, float * out){ +void sr4(float *in,int lines, int columns, int n, float * out){ int i,j; - for (i=0;i<n*rows;i++) { - for (j=0;j<rows;j++){ - out[i+j*n*rows]=in[i + j%rows + (i%rows)*(lines-1)]; + for (i=0;i<n*columns;i++) { + for (j=0;j<columns;j++){ + if ( (j*n*columns-1<i+j*n*columns) && (i+j*n*columns<j*n*columns+columns) ) + out[i+j*n*columns]=in[i+j*lines]; + else out[i+j*n*columns]=in[i + j%columns + (i%columns)*(lines-1)]; } } } -void slevinmul(float* in1, float* in2, int n, int rows, int ind_boucle, float* out, int lines, int deb_out,char choix){ +void slevinmul(float* in1, float* in2, int n, int columns, int ind_boucle, float* out, int lines, int deb_out,char choix){ int i=0, j=0, debut=0,start_out=0; float accu; if (ind_boucle==0) debut=0; - else debut = (ind_boucle-1)*(n+1)*rows*rows; + else debut = (ind_boucle-1)*(n+1)*columns*columns; - start_out = deb_out*ind_boucle*rows; + start_out = deb_out*ind_boucle*columns; switch(choix){ case 'u' : - for (i=0;i<rows*rows;i++){ + for (i=0;i<columns*columns;i++){ accu=0; - for(j=0;j<ind_boucle*rows+rows;j++){ - accu += in1[debut+i%rows*(n+1) + (rows*(n+1))*(j%rows)+j/rows] * in2[n*rows-((ind_boucle+1)*rows)+j+(i/rows)*n*rows]; + for(j=0;j<ind_boucle*columns+columns;j++){ + accu += in1[debut+i%columns*(n+1) + (columns*(n+1))*(j%columns)+j/columns] * in2[n*columns-((ind_boucle+1)*columns)+j+(i/columns)*n*columns]; } - out[start_out+i%rows+(i/rows)*lines] = accu; + out[start_out+i%columns+(i/columns)*lines] = accu; } break; case 'd' : - for (i=0;i<rows*rows;i++){ + for (i=0;i<columns*columns;i++){ accu=0; - for(j=0;j<ind_boucle*rows+rows;j++){ - accu+=in1[debut+i%rows*(n+1) + (rows*(n+1))*(j%rows)+j/rows]*in2[j+(i/rows)*n*rows]; + for(j=0;j<ind_boucle*columns+columns;j++){ + accu+=in1[debut+i%columns*(n+1) + (columns*(n+1))*(j%columns)+j/columns]*in2[j+(i/columns)*n*columns]; } - out[start_out+i%rows+(i/rows)*lines] = accu; + out[start_out+i%columns+(i/columns)*lines] = accu; } break; default : break; @@ -206,51 +222,46 @@ void slevinmul(float* in1, float* in2, int n, int rows, int ind_boucle, float* o -void slevinsig(float *sig,int n, int rows, int lines, float *sig1){ +void slevinsig(float *sig,int n, int columns, int lines, float *sig1){ int i=0; - for (i=0;i<rows*rows;i++){ - sig1[i]=sig[n*rows + i%rows +(i/rows)*lines]; + for (i=0;i<columns*columns;i++){ + sig1[i]=sig[n*columns + i%columns +(i/columns)*lines]; } } -void slevinmul2(float* in1, float *in2,int ind_boucle,int n,int rows,float* out){ +void slevinmul2(float* in1, float *in2,int ind_boucle,int n,int columns,float* out){ int i=0,j=0, debut; float accu; - debut = ind_boucle*(n+1)*rows*rows; - for(i=0;i<(n+1)*rows*rows;i++){ + debut = ind_boucle*(n+1)*columns*columns; + for(i=0;i<(n+1)*columns*columns;i++){ accu=0; - for (j=0;j<rows;j++){ - accu += in1[(i/(n+1))%rows+j*rows]*in2[debut+i%(n+1)+(i/((n+1)*rows))*(n+1)*rows+j*(n+1)]; + for (j=0;j<columns;j++){ + accu += in1[(i/(n+1))%columns+j*columns]*in2[debut+i%(n+1)+(i/((n+1)*columns))*(n+1)*columns+j*(n+1)]; } out[i]=accu; } } -void slevinsub(float* in1, float* in2, int n, int rows, int deb_in, int ind_boucle, float* out){ +void slevinsub(float* in1, float* in2, int n, int columns, int deb_in, int ind_boucle, float* out){ int i=0; - int deb_out= ind_boucle*(n+1)*rows*rows; + int deb_out= ind_boucle*(n+1)*columns*columns; int deb_in1; if (deb_in==0) deb_in1=0; - else deb_in1=(deb_in-1)*(n+1)*rows*rows; + else deb_in1=(deb_in-1)*(n+1)*columns*columns; - for (i=0;i<(n+1)*rows*rows;i++){ + for (i=0;i<(n+1)*columns*columns;i++){ out[deb_out + i] = in1[deb_in1+i]-in2[i]; } } -void sinitTab(float* in, int size){ - int i; - for (i=0;i<size;i++) in[i]=0; -} - -void sdecalage(float* in, int deb_in,int n,int rows,float *out){ +void sdecalage(float* in, int deb_in,int n,int columns,float *out){ int i=0,j=0; - for (i=0;i<rows*rows;i++){ + for (i=0;i<columns*columns;i++){ for(j=n;j>0;j--) {out[i*(n+1)+j]=in[i*(n+1)+deb_in+j-1];} out[i*(n+1)]=0; } diff --git a/src/signalProcessing/levin/levinUtils.h b/src/signalProcessing/levin/levinUtils.h new file mode 100644 index 00000000..62df88f2 --- /dev/null +++ b/src/signalProcessing/levin/levinUtils.h @@ -0,0 +1,71 @@ +/* + * 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 + * + */ + + + + + +/* creation of arrays used in levin */ + +void dr1(double *in,int lines,int columns, int n, double * out); +void dr2(double *in,int lines,int columns, int n, double * out); +void dr3(double *in,int lines,int columns, int n, double * out); +void dr4(double *in,int lines,int columns, int n, double * out); +void sr1(float *in,int lines,int columns, int n, float * out); +void sr2(float *in,int lines,int columns, int n, float * out); +void sr3(float *in,int lines,int columns, int n, float * out); +void sr4(float *in,int lines,int columns, int n, float * out); + + + +/*multiplications used in levin program, differents from the classic multiplication*/ +/* + in1,in2 : matrices to multiply + n : + columns : number of columns of in2 + ind_boucle : indice of the loop + out : result matrix + lines : number of lines of the result + deb_out : 0 if the result start to the indice 0, 1 otherwise + choix : 'u' or 'd', depends of in2. We take either the k first elements of in2 ('u') or the k last ('d'), + k is a nomber which depends of the indice of loop, the columns ... + */ +void dlevinmul(double* in1, double* in2, int n, int columns, int ind_boucle, double* out, int lines, int deb_out,char choix); +void dlevinmul2(double* in1, double *in2,int ind_boucle,int n,int columns,double* out); +void slevinmul(float* in1, float* in2, int n, int columns, int ind_boucle, float* out, int lines, int deb_out,char choix); +void slevinmul2(float* in1, float *in2,int ind_boucle,int n,int columns,float* out); + + +/*take the values of sig wanted*/ +void dlevinsig(double *sig,int n, int columns, int lines, double *sig1); +void slevinsig(float *sig,int n, int columns, int lines, float *sig1); + +/*a subtraction used in levin program, is different from the classic subtraction cause of the indices*/ +/* + in1,in2 : matrices to subtract + n : + columns : number of columns of in2 + deb_in : place of the first element of in1 + ind_boucle : indice of the loop + out : result matrix + */ +void dlevinsub(double* in1, double* in2, int n, int columns, int deb_in, int ind_boucle, double* out); +void slevinsub(float* in1, float* in2, int n, int columns, int deb_in, int ind_boucle, float* out); + + +/*used for the multiplication by z which is equal to step forward*/ +void ddecalage(double* in, int deb_in,int n,int columns,double * out); +void sdecalage(float* in, int deb_in,int n,int columns,float * out); + + + + diff --git a/src/signalProcessing/levin/slevina.c b/src/signalProcessing/levin/slevina.c index 636aa285..8d3ef1d2 100644 --- a/src/signalProcessing/levin/slevina.c +++ b/src/signalProcessing/levin/slevina.c @@ -11,8 +11,10 @@ */ #include "levin.h" +#include "levinUtils.h" #include "matrixInversion.h" #include "matrixMultiplication.h" +#include "zeros.h" #include <malloc.h> #include <stdio.h> @@ -32,13 +34,16 @@ void slevina (int n, float* cov, int lCov, int cCov, float* la, float* sig, floa Enter now in a element of the list. Take the first for example. This is, like said before, a cCov*cCov matrix. In la, it contains (n+1)*cCov*cCov. Each element of the matrix contains (n+1) elements. As it's stocked by columns, if we represent a matrix like [a c], for example, the elements 0 to n of la represent - [b d] + [b d] a, the elements (n+1) to 2(n+1)-1 represent b,... To finish, look at the elements of the matrix, the polynomes. The coefficients of the polynomes are stocked in increasing order. - For example, if la in Scilab is : list( [3+2x 5-2x ],[3+x-x^2 -1+2x ]) - ( [-5+x -2+4x],[1+6x+3x^2 -2x-x^2 ]), the result in dlevin will be : + For example, if la in Scilab is : list( [3+2x 5-2x ]) + ( [-5+x -2+4x]) + ([3+x-x^2 -1+2x ]) + ([1+6x+3x^2 -2x-x^2 ]) + the result in dlevin will be : -la is a table of 2*3*2*2 elements(n=2,cCov=2); -la[]={3,2,0, -5,1,0, 5,-2,0, -2,4,0, 3,1,-1, 1,6,3 -1,2,0, 0,-2,-1}. @@ -50,16 +55,24 @@ void slevina (int n, float* cov, int lCov, int cCov, float* la, float* sig, floa The greatest size of a element of the list is : cCov*cCov. Let see an example so know how it's stocked. - In Scilab, if sig is : list( [1 3],[5 7]) - ( [2 4],[6 8]),the result in dlevin will be : + In Scilab, if sig is : list( [1 3]) + ( [2 4]) + ( [5 7]) + ( [6 8]) + the result in dlevin will be : -sig={1,2, 5,6, 3,4, 7,8}. It's as if we put the matrix the ones under the others and we take the first column, the second,... - + >>>CAREFUL<<< + la/lb and sig are stored differently */ + + int i=0; + + /*version ISO C99 double tmp1[n*cCov*cCov], tmp2[n*cCov*cCov]; double sig1[cCov], gam[cCov]; @@ -70,7 +83,7 @@ void slevina (int n, float* cov, int lCov, int cCov, float* la, float* sig, floa float *sig1, *gam; float *R1,*R2,*R3,*R4; - + /* FIXME : malloc here */ tmp1=malloc((unsigned int)((n+1)*cCov*cCov)*sizeof(float)); tmp2=malloc((unsigned int)((n+1)*cCov*cCov)*sizeof(float)); @@ -86,9 +99,9 @@ void slevina (int n, float* cov, int lCov, int cCov, float* la, float* sig, floa /* * Initializations * */ - sinitTab(sig,n*cCov*cCov); - sinitTab(la,n*(n+1)*cCov*cCov); - sinitTab(lb,n*(n+1)*cCov*cCov); + szerosa(sig,n*cCov*cCov,1); + szerosa(la,n*(n+1)*cCov*cCov,1); + szerosa(lb,n*(n+1)*cCov*cCov,1); /*equal to eye(la) and eye(lb) but we can't use eye cause to the indexation*/ @@ -105,49 +118,38 @@ void slevina (int n, float* cov, int lCov, int cCov, float* la, float* sig, floa /* case i=0 */ - /*calculation of sig */ + /*computation of sig */ slevinmul(la,R4,n,cCov,0,sig,n*cCov,0,'d'); - /*calculation of gam1 */ + /*computation of gam1 */ slevinmul(lb,R2,n,cCov,0,gam,cCov,0,'u'); - /*calculation of c1*r1 */ + /*computation of c1*r1 */ slevinmul(la,R1,n,cCov,0,tmp1,cCov,0,'u'); - /*calculation of inv(gam1) */ + /*computation of inv(gam1) */ sinverma(gam,sig1,cCov); - sinitTab(gam,cCov*cCov); - /*calculation of k1 = c1*r1*inv(gam1) */ + /*computation of k1 = c1*r1*inv(gam1) */ smulma(tmp1,cCov,cCov,sig1,cCov,cCov,tmp2); - sinitTab(tmp1,n*cCov*cCov); - sinitTab(sig1,cCov*cCov); - /*calculation of k1*lb */ + /*computation of k1*lb */ slevinmul2(tmp2,lb,0,n,cCov,tmp1); - sinitTab(tmp2,n*cCov*cCov); - /*calculation of k1*lb*z */ + /*computation of k1*lb*z */ sdecalage(tmp1,0,n,cCov,tmp1); - /*calculation of la */ + /*computation of la */ slevinsub(la,tmp1,n,cCov,0,0,la); - sinitTab(tmp1,n*cCov*cCov); - /*calculation of sig1 (we extract the value if sig at time 0)*/ + /*computation of sig1 (we extract the value if sig at time 0)*/ slevinsig(sig,0,cCov,n*cCov,sig1); - /*calculation of c2*r3 */ + /*computation of c2*r3 */ slevinmul(lb,R3,n,cCov,0,tmp1,cCov,0,'d'); - /*calculation of inv(sig1)*/ + /*computation of inv(sig1)*/ sinverma(sig1,gam,cCov); - sinitTab(sig1,cCov*cCov); - /*calculation of k2 = c2*r3*inv(sig1) */ + /*computation of k2 = c2*r3*inv(sig1) */ smulma(tmp1,cCov,cCov,gam,cCov,cCov,tmp2); - sinitTab(tmp1,n*cCov*cCov); - sinitTab(gam,cCov*cCov); - /*calculation of k2*la (here it's lb cause la have been modified + /*computation of k2*la (here it's lb cause la have been modified and the precedent values hadn't been saved)*/ slevinmul2(tmp2,lb,0,n,cCov,tmp1); - sinitTab(tmp2,n*cCov*cCov); - /*calculation of lb*z */ + /*computation of lb*z */ sdecalage(lb,0,n,cCov,lb); - /*calculation of lb */ + /*computation of lb */ slevinsub(lb,tmp1,n,cCov,0,0,lb); - sinitTab(tmp1,n*cCov*cCov); - sinitTab(tmp2,n*cCov*cCov); for (i=1;i<n;i++){ @@ -155,30 +157,21 @@ void slevina (int n, float* cov, int lCov, int cCov, float* la, float* sig, floa slevinmul(lb,R2,n,cCov,i,gam,cCov,0,'u'); slevinmul(la,R1,n,cCov,i,tmp1,cCov,0,'u'); sinverma(gam,sig1,cCov); - sinitTab(gam,cCov*cCov); smulma(tmp1,cCov,cCov,sig1,cCov,cCov,tmp2); - sinitTab(tmp1,n*cCov*cCov); slevinmul2(tmp2,lb,i-1,n,cCov,tmp1); - sinitTab(tmp2,n*cCov*cCov); sdecalage(tmp1,0,n,cCov,tmp1); slevinsub(la,tmp1,n,cCov,i,i,la);/*a*/ - sinitTab(tmp1,n*cCov*cCov); - /*calculation of sig1 (we extract the value if sig at time i)*/ + /*computation of sig1 (we extract the value if sig at time i)*/ slevinsig(sig,i,cCov,n*cCov,sig1); slevinmul(lb,R3,n,cCov,i,tmp1,cCov,0,'d'); sinverma(sig1,gam,cCov); - sinitTab(sig1,cCov*cCov); smulma(tmp1,cCov,cCov,gam,cCov,cCov,tmp2); - sinitTab(tmp1,n*cCov*cCov); - /*calculation of k2*la (now it's la at time (i-1))*/ + /*computation of k2*la (now it's la at time (i-1))*/ slevinmul2(tmp2,la,i-1,n,cCov,tmp1); - sinitTab(tmp2,n*cCov*cCov); sdecalage(lb,(i-1)*(n+1)*cCov*cCov,n,cCov,tmp2); slevinsub(tmp2,tmp1,n,cCov,0,i,lb); - sinitTab(tmp1,n*cCov*cCov); - sinitTab(tmp2,n*cCov*cCov); } diff --git a/src/signalProcessing/levin/testDoubleLevin.c b/src/signalProcessing/levin/testDoubleLevin.c index 20560da4..d2e0b227 100644 --- a/src/signalProcessing/levin/testDoubleLevin.c +++ b/src/signalProcessing/levin/testDoubleLevin.c @@ -10,7 +10,7 @@ * */ - +#include <math.h> #include <stdio.h> #include <assert.h> #include "levin.h" @@ -18,89 +18,75 @@ static void dlevinaTest(void) { - int n=15; - -/* int i=0; - - double cov[128]={2.1632471,0.6253206,-0.2212568,-0.6154865,-0.2646837,0.0144518,-0.2511410,-0.5401314, \ --0.3017069,0.6439519,1.0938702,0.5916342,-0.2832519,-0.5799388,-0.2711958,0.0740953,\ --0.2646536,-0.6427527,-0.2888743,0.5798061,1.0301717,0.5939465,-0.1991420,-0.6068337,\ --0.2532973,-0.0156329,-0.2872505,-0.5836588,-0.2913317,0.5783603,1.0635956,0.5822280,\ --0.2711408,-0.6209564,-0.2485693,-0.0334097,-0.2733096,-0.5363602,-0.2689253,0.5987651,\ -1.0441869,0.5835384,-0.2934934,-0.5838854,-0.2848314,-0.0111112,-0.2838466,-0.5757844, \ --0.2925714,0.5468999,1.0859833,0.6045700,-0.2491218,-0.6152090,-0.2322848,-0.0206893, \ --0.3015463,-0.5653637,-0.2812883,0.5947973,1.0040374,0.5830293,-0.2684794,-0.5986135, \ --0.2673449,-0.0504689,-0.2989750,-0.5510215,-0.2771791,0.5943756,0.9436008,0.5795994, \ --0.2586094,-0.5544826,-0.2474743,0.0262180,-0.2474046,-0.5373957,-0.2932611,0.5803651,\ -0.9859401,0.5729370,-0.2169815,-0.5399512,-0.2332551,-0.0151484,-0.274592,-0.5905861, \ --0.2844705,0.5987613,0.9710525,0.5330744,-0.2443102,-0.5858032,-0.2166843,-0.0028519, \ --0.2613759,-0.5451755,-0.2489879,0.4847080,0.9502086,0.5870537,-0.2648506,-0.5585377, \ --0.2867994,0.0067153,-0.2101314,-0.5189354,-0.2473348,0.5727840,0.9393745,0.5947526, \ --0.2382349,-0.5675628,-0.2202667,-0.0863862,-0.2534431,-0.5561705,-0.2503315,0.5649435, \ -0.9288405,0.5373113,-0.2468931,-0.5345938,-0.2767231,-0.0397433,-0.2345866,-0.4977333};*/ - - double cov2[256]={1.8542341,0.2302480,0.5424259,0.2396233,-0.2802882,-0.1343754,-0.4585444,-0.0852306,\ - -0.3683334,0.0258069,-0.0655487,0.1546545,-0.3655665,-0.0310238,-0.4565569,0.0441730,\ - -0.1386023,-0.0434076,0.5189599,0.0357233,1.0210283,0.1781705,0.5183526,0.0801215,\ - -0.1862581,-0.1739927,-0.4755297,-0.1160617,-0.2512805,0.1471775,-0.0995046,0.1707012,\ - -0.3269761,-0.0112160,-0.4411032,-0.0872514,-0.1757269,-0.1472844,0.5471859,-0.0644483,\ - 0.8977092,0.2136813,0.3942809,-0.0382849,-0.1260751,-0.0965459,-0.5126250,-0.1452914,\ - -0.3046589,-0.0022501,0.0350519,0.2645226,-0.2509645,-0.0365893,-0.5183898,-0.0318046,\ - -0.1743803,-0.0873962,0.5372009,-0.1704277,0.7164172,0.1710189,0.4685590,-0.0759859,\ - -0.1911539,-0.0679539,-0.4706253,-0.0519689,-0.2791620,-0.0583353,-0.0267250,0.1014851,\ - -0.1576785,-0.1655821,-0.3847449,-0.0386553,-0.1297910,0.0083667,0.4836641,-0.0939749,\ - 0.7437560,0.2901242,0.3853338,0.0798201,-0.1689064,-0.1747635,-0.5110532,-0.1476417,\ - -0.1808702,0.0963522,0.0174652,0.2306552,-0.2592396,-0.1491170,-0.3227275,0.0629281,\ - -0.1185767,-0.0827683,0.4598633,0.0349602,0.6505747,0.3114497,0.2631378,-0.0103355,\ - -0.3194549,-0.2351815,-0.4274886,-0.1750659,-0.0813017,0.1245920,-0.0664094,0.1473835,\ - -0.2078978,-0.1688748,-0.3425365,0.1354790,-0.1685176,-0.1444135,0.3966746,-0.177444,\ - 0.5809542,0.2654948,0.3486682,0.0369250,-0.1920808,-0.1351589,-0.4381282,-0.1431602,\ -0.2302480,2.020749,-0.1453147,-0.4816412,-0.1059289,-0.3953205,0.0167060,0.5071499,\ - -0.0438978,-0.2461159,0.1641866,-0.0420505,-0.0166320,-0.1641097,-0.2515164,0.5068871,\ - -0.2113012,-0.3582454,0.1358039,-0.5180938,0.3298329,1.0316539,-0.1190920,-0.4336184,\ - -0.0743425,-0.1711531,0.0595813,0.5856594,0.0258974,-0.2492872,0.1667785,-0.1520977,\ - -0.0087917,-0.1656533,0.0463118,0.4459719,-0.1475134,-0.2804235,-0.2214265,-0.3674264,\ - 0.2137918,0.7380489,0.0643087,-0.4993311,0.0903295,-0.2392031,-0.0495192,0.4715900,\ - 0.0560724,-0.0850974,0.1811686,0.0572052,-0.0733149,-0.3059423,-0.1168040,0.4098819,\ - -0.1070201,-0.4125769,-0.0502986,-0.4541070,0.1923829,0.9167427,-0.0450642,-0.3861262,\ - -0.0551742,-0.2979827,-0.0868854,0.4011319,0.1660530,-0.1986059,0.2734969,-0.0263159,\ - 0.0112668,-0.0763537,-0.1452256,0.5250867,-0.1852298,-0.3335027,-0.1114010,-0.4129438,\ - 0.1639697,0.7177437,-0.1688863,-0.4391817,-0.0468476,-0.2069082,-0.0635808,0.4981539,\ - -0.0965365,-0.2057104,0.2059908,-0.2499686,-0.0270036,-0.0794378,-0.0264147,0.3461999,\ - -0.0746288,-0.3044705,-0.1251745,-0.2032644,0.0744516,0.7004425,-0.1367678,-0.5699592,\ - -0.0909027,-0.3123118,0.0731459,0.3900814,-0.0056685,-0.0145168,0.1415849,-0.0899785,\ - -0.0770252,-0.1568634,0.0146449,0.2642178,-0.0843896,-0.2369412,0.0091955,-0.2899846,\ - 0.0811130,0.6213581,-0.2800630,-0.3767941,-0.0630885,-0.155981,0.0395355,0.3978243}; - - double la[15*16*2*2],lb[15*16*2*2],sig[15*2*2]; - dlevina(n,cov2,128,2,la,sig,lb); - -/* - for (i=0;i<15*16*2*2;i++){ - printf("indice : %d valeur : %f - ",i,la[i]); - printf("\n"); - if((i+1)%64==0)printf("------------------------------------\n"); - if((i+1)%16==0)printf("###############\n"); + int i=0; + + double in[20]={0.9932627780362963676453,0.8074779896996915340424,0.8554796632379293441773, + 0.5031460602767765522003,0.0963323051109910011292,0.7058098311536014080048,0.8630577065050601959229, + 0.0076185003854334354401,0.8048951094970107078552,0.5963762304745614528656,0.1176836211234331130981, + 0.8010095250792801380158,0.5132340090349316596985,0.2010910022072494029999,0.7860820889472961425781, + 0.7865035482682287693024,0.6951530007645487785339,0.4248132123611867427826,0.3446625452488660812378, + 0.6497785751707851886749}; + + double result_la[48]={1,-0.3865652298877474413175,0,0, + 0,- 0.3434956227371184778185,0,0, + 0,- 0.5839401384584462784133,0,0, + 1, - 0.2005808775714553182645,0,0, + 1, - 0.9800896173744618744550, 1.690821697485581420750,0, + 0,- 0.0829753946826485844213, 0.1706850739778944525682,0, + 0,- 1.5024216979529190219012, - 0.2246231721723708774086,0, + 1, - 0.1137930279260921523354, - 0.9252347371003220022345,0, + 1, 0.9890664402902992202726, 0.5787159455904740124055,1.2930051366411721147642, + 0,- 0.8505434486601569643582,0.6053315910573954239382, - 0.5028225952598519565839, + 0,2.1236994816779066752588, - 2.0487578989503822946006, - 3.9701563399198689374714, + 1, - 1.4716550983021570164766, - 0.2144135496153387610008, 1.4891952441184541644503}; + + double result_sig[12]={0.9932627780362963676453, 0.8074779896996915340424,0.3628661470549920387008,0.4106795421050958294629, + - 0.6299693698364057237171,- 0.0327761932052800242232,0.1176836211234331130981,0.8010095250792801380158, + - 0.1942402590062223821654, 0.5878460460823274891240, 0.3391635613203383137204,0.1291488276492920306282}; + + double result_lb[48]={- 0.3981923483861428136876,1,0,0, + - 0.3550295998674473652024,0,0,0, + - 0.5696378489005990974903,0,0,0, + - 0.1988863157065166586968,1,0,0, + 1.62419596196504145702, - 0.9819754657045941526050,1,0, + 0.0329804805798983302623, - 0.0396945499933941681192,0,0, + - 0.1283118770193089619447, - 1.492334154918740996010,0,0, + - 0.9551334433810730883963, - 0.0265634378315470209841,1,0, + 1.1913835764722526810999,0.0301096362936850159286, 1.909619275538441574014,1, + 0.4767865147665533709365 ,- 0.2016469880890300325760,0.2878592385656049135179,0, + 5.1391578635011887499218, - 2.5030727471739586675881, - 6.5148738878935787965929,0, + - 2.8040366068494293472213 ,- 1.3523880325486907771904, 2.4607313355305917568217,1}; + + double la[48],lb[48],sig[12]; + + dlevina(3,in,10,2,la,sig,lb); + + /* FIXME : assert à 10^-13 */ + /* FIXME : sig est rangé différemment qu'à l'habitude */ + + for (i=0;i<48;i++){ + if (la[i]!=0) + assert( (fabs(la[i]-result_la[i]) / fabs(la[i]) ) <1e-14); + else + assert( fabs(la[i]-result_la[i]) == 0); } - printf("\n"); - printf("\n"); - printf("\n"); - for (i=0;i<15;i++){ - printf("i : %d - lb = ",i); - for (j=0;j<15;j++) printf(" %f - ",lb[15*i+j]); - printf("\n"); + + for (i=0;i<12;i++){ + if (sig[i]!=0) + assert( (fabs(sig[i]-result_sig[i]) / fabs(sig[i]) ) <1e-14); + else + assert( fabs(sig[i]-result_sig[i]) == 0); } - printf("\n"); - printf("\n"); - printf("\n"); - - - for (i=0;i<15*2;i++){ - printf("indice : %d %f | indice : %d %f\n",i,sig[i],i+30,sig[i+30]); + + + for (i=0;i<48;i++){ + if (lb[i]!=0) + assert( (fabs(lb[i]-result_lb[i]) / fabs(lb[i]) ) <1e-13); + else + assert( fabs(lb[i]-result_lb[i]) == 0); } -*/ - + } diff --git a/src/signalProcessing/levin/testFloatLevin.c b/src/signalProcessing/levin/testFloatLevin.c index 82c874fa..a7924cec 100644 --- a/src/signalProcessing/levin/testFloatLevin.c +++ b/src/signalProcessing/levin/testFloatLevin.c @@ -10,104 +10,90 @@ * */ - +#include <math.h> #include <stdio.h> #include <assert.h> #include "levin.h" -static void slevinaTest(void) { - int n=15; - -/* int i=0; -*/ - float cov[128]={2.1632471f,0.6253206f,-0.2212568f,-0.6154865f,-0.2646837f,0.0144518f,-0.2511410f,-0.5401314f, \ --0.3017069f,0.6439519f,1.0938702f,0.5916342f,-0.2832519f,-0.5799388f,-0.2711958f,0.0740953f,\ --0.2646536f,-0.6427527f,-0.2888743f,0.5798061f,1.0301717f,0.5939465f,-0.1991420f,-0.6068337f,\ --0.2532973f,-0.0156329f,-0.2872505f,-0.5836588f,-0.2913317f,0.5783603f,1.0635956f,0.5822280f,\ --0.2711408f,-0.6209564f,-0.2485693f,-0.0334097f,-0.2733096f,-0.5363602f,-0.2689253f,0.5987651f,\ -1.0441869f,0.5835384f,-0.2934934f,-0.5838854f,-0.2848314f,-0.0111112f,-0.2838466f,-0.5757844f, \ --0.2925714f,0.5468999f,1.0859833f,0.6045700f,-0.2491218f,-0.6152090f,-0.2322848f,-0.0206893f, \ --0.3015463f,-0.5653637f,-0.2812883f,0.5947973f,1.0040374f,0.5830293f,-0.2684794f,-0.5986135f, \ --0.2673449f,-0.0504689f,-0.2989750f,-0.5510215f,-0.2771791f,0.5943756f,0.9436008f,0.5795994f, \ --0.2586094f,-0.5544826f,-0.2474743f,0.0262180f,-0.2474046f,-0.5373957f,-0.2932611f,0.5803651f,\ -0.9859401f,0.5729370f,-0.2169815f,-0.5399512f,-0.2332551f,-0.0151484f,-0.274592f,-0.5905861f, \ --0.2844705f,0.5987613f,0.9710525f,0.5330744f,-0.2443102f,-0.5858032f,-0.2166843f,-0.0028519f, \ --0.2613759f,-0.5451755f,-0.2489879f,0.4847080f,0.9502086f,0.5870537f,-0.2648506f,-0.5585377f, \ --0.2867994f,0.0067153f,-0.2101314f,-0.5189354f,-0.2473348f,0.5727840f,0.9393745f,0.5947526f, \ --0.2382349f,-0.5675628f,-0.2202667f,-0.0863862f,-0.2534431f,-0.5561705f,-0.2503315f,0.5649435f, \ -0.9288405f,0.5373113f,-0.2468931f,-0.5345938f,-0.2767231f,-0.0397433f,-0.2345866f,-0.4977333f}; - -/* float cov2[256]={1.8542341f,0.2302480f,0.5424259f,0.2396233f,-0.2802882f,-0.1343754f,-0.4585444f,-0.0852306f,\ - -0.3683334f,0.0258069f,-0.0655487f,0.1546545f,-0.3655665f,-0.0310238f,-0.4565569f,0.0441730f,\ - -0.1386023f,-0.0434076f,0.5189599f,0.0357233f,1.0210283f,0.1781705f,0.5183526f,0.0801215f,\ - -0.1862581f,-0.1739927f,-0.4755297f,-0.1160617f,-0.2512805f,0.1471775f,-0.0995046f,0.1707012f,\ - -0.3269761f,-0.0112160f,-0.4411032f,-0.0872514f,-0.1757269f,-0.1472844f,0.5471859f,-0.0644483f,\ - 0.8977092f,0.2136813f,0.3942809f,-0.0382849f,-0.1260751f,-0.0965459f,-0.5126250f,-0.1452914f,\ - -0.3046589f,-0.0022501f,0.0350519f,0.2645226f,-0.2509645f,-0.0365893f,-0.5183898f,-0.0318046f,\ - -0.1743803f,-0.0873962f,0.5372009f,-0.1704277f,0.7164172f,0.1710189f,0.4685590f,-0.0759859f,\ - -0.1911539f,-0.0679539f,-0.4706253f,-0.0519689f,-0.2791620f,-0.0583353f,-0.0267250f,0.1014851f,\ - -0.1576785f,-0.1655821f,-0.3847449f,-0.0386553f,-0.1297910f,0.0083667f,0.4836641f,-0.0939749f,\ - 0.7437560f,0.2901242f,0.3853338f,0.0798201f,-0.1689064f,-0.1747635f,-0.5110532f,-0.1476417f,\ - -0.1808702f,0.0963522f,0.0174652f,0.2306552f,-0.2592396f,-0.1491170f,-0.3227275f,0.0629281f,\ - -0.1185767f,-0.0827683f,0.4598633f,0.0349602f,0.6505747f,0.3114497f,0.2631378f,-0.0103355f,\ - -0.3194549f,-0.2351815f,-0.4274886f,-0.1750659f,-0.0813017f,0.1245920f,-0.0664094f,0.1473835f,\ - -0.2078978f,-0.1688748f,-0.3425365f,0.1354790f,-0.1685176f,-0.1444135f,0.3966746f,-0.177444f,\ - 0.5809542f,0.2654948f,0.3486682f,0.0369250f,-0.1920808f,-0.1351589f,-0.4381282f,-0.1431602f,\ -0.2302480f,2.020749f,-0.1453147f,-0.4816412f,-0.1059289f,-0.3953205f,0.0167060f,0.5071499f,\ - -0.0438978f,-0.2461159f,0.1641866f,-0.0420505f,-0.0166320f,-0.1641097f,-0.2515164f,0.5068871f,\ - -0.2113012f,-0.3582454f,0.1358039f,-0.5180938f,0.3298329f,1.0316539f,-0.1190920f,-0.4336184f,\ - -0.0743425f,-0.1711531f,0.0595813f,0.5856594f,0.0258974f,-0.2492872f,0.1667785f,-0.1520977f,\ - -0.0087917f,-0.1656533f,0.0463118f,0.4459719f,-0.1475134f,-0.2804235f,-0.2214265f,-0.3674264f,\ - 0.2137918f,0.7380489f,0.0643087f,-0.4993311f,0.0903295f,-0.2392031f,-0.0495192f,0.4715900f,\ - 0.0560724f,-0.0850974f,0.1811686f,0.0572052f,-0.0733149f,-0.3059423f,-0.1168040f,0.4098819f,\ - -0.1070201f,-0.4125769f,-0.0502986f,-0.4541070f,0.1923829f,0.9167427f,-0.0450642f,-0.3861262f,\ - -0.0551742f,-0.2979827f,-0.0868854f,0.4011319f,0.1660530f,-0.1986059f,0.2734969f,-0.0263159f,\ - 0.0112668f,-0.0763537f,-0.1452256f,0.5250867f,-0.1852298f,-0.3335027f,-0.1114010f,-0.4129438f,\ - 0.1639697f,0.7177437f,-0.1688863f,-0.4391817f,-0.0468476f,-0.2069082f,-0.0635808f,0.4981539f,\ - -0.0965365f,-0.2057104f,0.2059908f,-0.2499686f,-0.0270036f,-0.0794378f,-0.0264147f,0.3461999f,\ - -0.0746288f,-0.3044705f,-0.1251745f,-0.2032644f,0.0744516f,0.7004425f,-0.1367678f,-0.5699592f,\ - -0.0909027f,-0.3123118f,0.0731459f,0.3900814f,-0.0056685f,-0.0145168f,0.1415849f,-0.0899785f,\ - -0.0770252f,-0.1568634f,0.0146449f,0.2642178f,-0.0843896f,-0.2369412f,0.0091955f,-0.2899846f,\ - 0.0811130f,0.6213581f,-0.2800630f,-0.3767941f,-0.0630885f,-0.155981f,0.0395355f,0.3978243f};*/ - - float la[15*16*1*1],lb[15*16*1*1],sig[15*1*1]; - - slevina(n,cov,128,1,la,sig,lb); - - -/* for (i=0;i<15*16*2*2;i++){ - printf("indice : %d valeur : %f - ",i,la[i]); - printf("\n"); - if((i+1)%64==0)printf("------------------------------------\n"); - if((i+1)%16==0)printf("###############\n"); +static void dlevinaTest(void) { + + int i=0; + + float in[20]={0.9932627780362963676453f,0.8074779896996915340424f,0.8554796632379293441773f, + 0.5031460602767765522003f,0.0963323051109910011292f,0.7058098311536014080048f,0.8630577065050601959229f, + 0.0076185003854334354401f,0.8048951094970107078552f,0.5963762304745614528656f,0.1176836211234331130981f, + 0.8010095250792801380158f,0.5132340090349316596985f,0.2010910022072494029999f,0.7860820889472961425781f, + 0.7865035482682287693024f,0.6951530007645487785339f,0.4248132123611867427826f,0.3446625452488660812378f, + 0.6497785751707851886749f}; + + float result_la[48]={1.0f,-0.3865652298877474413175f,0.0f,0.0f, + 0.0f,- 0.3434956227371184778185f,0.0f,0.0f, + 0.0f,- 0.5839401384584462784133f,0.0f,0.0f, + 1.0f, - 0.2005808775714553182645f,0.0f,0.0f, + 1.0f, - 0.9800896173744618744550f, 1.690821697485581420750f,0.0f, + 0.0f,- 0.0829753946826485844213f, 0.1706850739778944525682f,0.0f, + 0.0f,- 1.5024216979529190219012f, - 0.2246231721723708774086f,0.0f, + 1.0f, - 0.1137930279260921523354f, - 0.9252347371003220022345f,0.0f, + 1.0f, 0.9890664402902992202726f, 0.5787159455904740124055f,1.2930051366411721147642f, + 0.0f,- 0.8505434486601569643582f,0.6053315910573954239382f, - 0.5028225952598519565839f, + 0.0f,2.1236994816779066752588f, - 2.0487578989503822946006f, - 3.9701563399198689374714f, + 1.0f, - 1.4716550983021570164766f, - 0.2144135496153387610008f, 1.4891952441184541644503f}; + + float result_sig[12]={0.9932627780362963676453f, 0.8074779896996915340424f,0.3628661470549920387008f,0.4106795421050958294629f, + - 0.6299693698364057237171f,- 0.0327761932052800242232f,0.1176836211234331130981f,0.8010095250792801380158f, + - 0.1942402590062223821654f, 0.5878460460823274891240f, 0.3391635613203383137204f,0.1291488276492920306282f}; + + float result_lb[48]={- 0.3981923483861428136876f,1.0f,0.0f,0.0f, + - 0.3550295998674473652024f,0.0f,0.0f,0.0f, + - 0.5696378489005990974903f,0.0f,0.0f,0.0f, + - 0.1988863157065166586968f,1.0f,0.0f,0.0f, + 1.62419596196504145702f, - 0.9819754657045941526050f,1.0f,0.0f, + 0.0329804805798983302623f, - 0.0396945499933941681192f,0.0f,0.0f, + - 0.1283118770193089619447f, - 1.492334154918740996010f,0.0f,0.0f, + - 0.9551334433810730883963f, - 0.0265634378315470209841f,1.0f,0.0f, + 1.1913835764722526810999f,0.0301096362936850159286f, 1.909619275538441574014f,1.0f, + 0.4767865147665533709365f ,- 0.2016469880890300325760f,0.2878592385656049135179f,0.0f, + 5.1391578635011887499218f, - 2.5030727471739586675881f, - 6.5148738878935787965929f,0.0f, + - 2.8040366068494293472213f ,- 1.3523880325486907771904f, 2.4607313355305917568217f,1.0f}; + + float la[48],lb[48],sig[12]; + + slevina(3,in,10,2,la,sig,lb); + + /* FIXME : assert à 10^-5 */ + /* FIXME : sig est rangé différemment qu'à l'habitude */ + + for (i=0;i<48;i++){ + if (la[i]!=0) + assert( (fabs(la[i]-result_la[i]) / fabs(la[i]) ) <1e-5); + else + assert( fabs(la[i]-result_la[i]) == 0); } - printf("\n"); - printf("\n"); - printf("\n"); - for (i=0;i<15;i++){ - printf("i : %d - lb = ",i); - for (j=0;j<15;j++) printf(" %f - ",lb[15*i+j]); - printf("\n"); + + for (i=0;i<12;i++){ + if (sig[i]!=0) + assert( (fabs(sig[i]-result_sig[i]) / fabs(sig[i]) ) <1e-5); + else + assert( fabs(sig[i]-result_sig[i]) == 0); } - printf("\n"); - printf("\n"); - printf("\n"); - - - for (i=0;i<15*1;i++){ - printf("indice : %d %f\n",i,sig[i]); + + + for (i=0;i<48;i++){ + if (lb[i]!=0) + assert( (fabs(lb[i]-result_lb[i]) / fabs(lb[i]) ) <1e-5); + else + assert( fabs(lb[i]-result_lb[i]) == 0); } -*/ - + } static int levinTest(void) { printf("\n>>>> Levin Tests\n"); - slevinaTest(); + dlevinaTest(); return 0; } |