/* Copyright (c) 2005, International Computer Science Institute (ICSI) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of ICSI nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /*Correlation shaping gradient calculation*/ /*June 2005, Marc Ferras, International Computer Science Institute*/ #include "math.h" #include "mex.h" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /*MEX I/O parameters*/ mxArray *csLengthData; mxArray *filLengthData; mxArray *minTauData; mxArray *corrYYData; mxArray *corrYXData; mxArray *wData; /*C input pointers to parameters*/ double *pCsLength; double *pFilLength; double *pMinTau; double *corrYY; double *corrYX; double *w; /*C output parameters*/ double *outArray; int oaColLen, oaRowLen, oaLen; /*C local variables*/ int i,l,tau; double acc; /*C input parameters*/ int csLength; int filLength; int minTau; int absTau; int minCorrLag; int maxCorrLag; int corrOffset; /*Get MEX input parameters*/ /*Parameter 1: corrYY*/ corrYYData = (mxArray *)prhs[0]; corrYY = mxGetPr(corrYYData); /*Parameter 1: corrYX*/ corrYXData = (mxArray *)prhs[1]; corrYX = mxGetPr(corrYXData); /*Parameter 1: csLength (correlation Shaping length)*/ csLengthData = (mxArray *)prhs[2]; pCsLength = mxGetPr(csLengthData); csLength=(int)(*pCsLength); /*Parameter 1: csLength (correlation Shaping length)*/ filLengthData = (mxArray *)prhs[3]; pFilLength = mxGetPr(filLengthData); filLength=(int)(*pFilLength); /*Parameter 2: minTau*/ minTauData = (mxArray *)prhs[4]; pMinTau = mxGetPr(minTauData); minTau=(int)(*pMinTau); /*Parameter 5: corrE*/ wData = (mxArray *)prhs[5]; w = mxGetPr(wData); /*Output parameters*/ oaColLen=1; oaRowLen=filLength; oaLen=oaColLen; plhs[0] = mxCreateDoubleMatrix(oaColLen, oaRowLen, mxREAL); outArray = mxGetPr(plhs[0]); minCorrLag=-csLength; maxCorrLag=csLength; corrOffset=csLength; for (l=0;l=minCorrLag && (l+tau)<=maxCorrLag ) { acc=acc+w[tau]*corrYY[tau+corrOffset]*corrYX[l+tau+corrOffset]; } if ( (l-tau)>=minCorrLag && (l-tau)<=maxCorrLag ) { acc=acc+w[tau]*corrYY[tau+corrOffset]*corrYX[l-tau+corrOffset]; } } outArray[l]=acc; } return; }