matthiasm@8: /* matthiasm@8: * dpcore.c matthiasm@8: * Core of dynamic programming/DTW calculation matthiasm@8: * 2003-04-02 dpwe@ee.columbia.edu matthiasm@8: * $Header: /Users/dpwe/projects/dtw/RCS/dpcore.c,v 1.3 2006/01/18 20:05:51 dpwe Exp $ matthiasm@8: % Copyright (c) 2003-05 Dan Ellis matthiasm@8: % released under GPL - see file COPYRIGHT matthiasm@8: */ matthiasm@8: matthiasm@8: #include matthiasm@8: #include matthiasm@8: #include matthiasm@8: #include "mex.h" matthiasm@8: matthiasm@8: /* #define DEBUG */ matthiasm@8: matthiasm@8: #define INF HUGE_VAL matthiasm@8: matthiasm@8: void matthiasm@8: mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) matthiasm@8: { matthiasm@8: int i,j; matthiasm@8: long pvl, pvb[16]; matthiasm@8: matthiasm@8: #ifdef DEBUG matthiasm@8: mexPrintf("dpcore: Got %d lhs args and %d rhs args.\n", matthiasm@8: nlhs, nrhs); matthiasm@8: for (i=0;i 0){ matthiasm@8: mxArray *DMatrix, *PMatrix; matthiasm@8: int rows, cols, i, j, k, tb; matthiasm@8: double *pM, *pD, *pP, *pC; matthiasm@8: double d1, d2, d3, v; matthiasm@8: double *costs; matthiasm@8: int *steps; matthiasm@8: int ncosts; matthiasm@8: matthiasm@8: rows = mxGetM(prhs[0]); matthiasm@8: cols = mxGetN(prhs[0]); matthiasm@8: pM = mxGetPr(prhs[0]); matthiasm@8: matthiasm@8: DMatrix = mxCreateDoubleMatrix(rows, cols, mxREAL); matthiasm@8: pD = mxGetPr(DMatrix); matthiasm@8: PMatrix = mxCreateDoubleMatrix(rows, cols, mxREAL); matthiasm@8: pP = mxGetPr(PMatrix); matthiasm@8: plhs[0] = DMatrix; matthiasm@8: if (nlhs > 1) { matthiasm@8: plhs[1] = PMatrix; matthiasm@8: } matthiasm@8: matthiasm@8: /* setup costs */ matthiasm@8: if (nrhs == 1) { matthiasm@8: /* default C matrix */ matthiasm@8: int ii; matthiasm@8: matthiasm@8: ncosts = 3; matthiasm@8: costs = (double *)malloc(ncosts*sizeof(double)); matthiasm@8: for (ii = 0; ii= steps[2*k] && j >= steps[2*k+1] ) { matthiasm@8: d2 = costs[k]*d1 + pD[(i-steps[2*k]) + (j-steps[2*k+1])*rows]; matthiasm@8: if (d2 < v) { matthiasm@8: v = d2; matthiasm@8: tb = k+1; matthiasm@8: } matthiasm@8: } matthiasm@8: } matthiasm@8: matthiasm@8: pD[i + j*rows] = v; matthiasm@8: pP[i + j*rows] = (double)tb; matthiasm@8: v = INF; matthiasm@8: } matthiasm@8: } matthiasm@8: free((void *)costs); matthiasm@8: free((void *)steps); matthiasm@8: } matthiasm@8: matthiasm@8: #ifdef DEBUG matthiasm@8: mexPrintf("dpcore: returning...\n"); matthiasm@8: #endif /* DEBUG */ matthiasm@8: } matthiasm@8: