static int CheckArguments(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if (nrhs<3 || nrhs > 3 || nlhs < 7 || nlhs > 7){ printf("Incorrect calling syntax:\n [AreaF,TransF,Fmts,BW,Ampl,pdat1,pdat2] = "); printf("AMgetdata(tractcfg,phycons,p3cfg)\n"); printf("nlhs is %d, nrhs is %d.\n", nlhs, nrhs); return 1; } /*------------ Check input is not empty ------------------------------ */ if (mxGetSize(prhs[0]) != 4) return 1; if (mxGetSize(prhs[1]) != 5) return 1; if (mxGetSize(prhs[2]) != 8) return 1; pTCcfg = mxGetPr(prhs[0]); pPCcfg = mxGetPr(prhs[1]); pAMcfg = mxGetPr(prhs[2]); /*-------------------- Create the output matrix ----------------------- */ return 0; }
static int CheckArguments(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if (nrhs<4 || nrhs > 4 || nlhs < 5 || nlhs > 5){ printf("Incorrect calling syntax:\n [AreaF,TransF,Fmts,BW,Ampl] = "); printf("AS2F(tractcfg,phycons,safcfg,anc)\n"); printf("nlhs is %d, nrhs is %d.\n", nlhs, nrhs); return 1; } /*------------ Check input is not empty ------------------------------ */ if (mxGetSize(prhs[0]) != 4) return 1; if (mxGetSize(prhs[1]) != 5) return 1; size = mxGetSize(prhs[2])/2; if (mxGetSize(prhs[3]) != 2) return 1; pTCcfg = mxGetPr(prhs[0]); pPCcfg = mxGetPr(prhs[1]); pAFcfg = mxGetPr(prhs[2]); pAFcfgmisc = mxGetPr(prhs[3]); /*-------------------- Create the output matrix ----------------------- */ return 0; }
static int CheckArguments(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if (nrhs < 2 || nrhs > 3 || nlhs > 2){ mexPrintf("Incorrect calling syntax : [output,state] = %s", MexFunctionName); mexPrintf("(input, Coeffs, state)\n"); mexPrintf(" input is C x N\n"); mexPrintf(" Coeffs is 2 x S (targets;epsilons)\n"); mexPrintf(" state is C x S\n"); mexPrintf(" output is C x N\n"); return 1; } /*------------ Check that input is not empty ---------------------- */ nSamples = mxGetN(pINPUTM); nChannels = mxGetM(pINPUTM); if(nSamples == 0 || nChannels == 0) { mexPrintf("Input array is empty\n"); return 1; } inputData = mxGetPr(pINPUTM); /*------------ Get the number of AGC stages ----------------------- */ nStages = mxGetN(pCOEFFSM); if ( mxGetM(pCOEFFSM) != 2) { mexPrintf("Coefficient Matrix must have 2 rows: " "Coeffs=[target;epsilon]"); return 1; } agcParms = mxGetPr(pCOEFFSM); /*------------ Allocate the Output Matrix ------------------------- */ outputMatrix = mxCreateDoubleMatrix(nChannels, nSamples, mxREAL); outputData = mxGetPr(outputMatrix); /*---- Create the state matrix, fill in the input values if specified --*/ stateMatrix = mxCreateDoubleMatrix(nChannels, nStages, mxREAL); stateArray = mxGetPr(stateMatrix); if ( nrhs >= 3 ) { DOUBLE *inputStateArray; int i; if ( mxGetM(pSTATEM) != nChannels || mxGetN(pSTATEM) != nStages){ mexPrintf("MEX file %s got a bad state " "input. Should be size %dx%d.\n", mexFunctionName, nChannels, nStages); mexPrintf(" Got %dx %d.\n", mxGetM(pSTATEM), mxGetN(pSTATEM)); return 1; } inputStateArray = mxGetPr(pSTATEM); for (i=0; i<mxGetSize(pSTATEM); i++) stateArray[i] = inputStateArray[i]; } return 0; }
static int CheckArguments(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int i; DOUBLE *stateData; if (nrhs < 2 || nrhs > 4 || nlhs > 2){ mexPrintf("Incorrect calling syntax:\n [output, state] = "); mexPrintf("invsoscascade(input, Coeffs, gains, state)\n"); mexPrintf(" input has C x N samples\n"); mexPrintf(" Coeffs is C x 5 where C is the number of " "channels\n"); mexPrintf(" gains is a C x 1 array of channel gains\n"); mexPrintf(" state is C x 2"); mexPrintf(" output is 1 x N\n"); return 1; } /*------------ Check input is not empty ------------------------------ */ nSamples = mxGetN(pINPUTM); if(nSamples == 0) { mexPrintf("Input array is empty.\n"); return 1; } inputData = mxGetPr(pINPUTM); nChannels = mxGetM(pINPUTM); /*------------ Check to See if Coeffs Matrix Is the right Size ------- */ if ( mxGetN(pCOEFFSM) != 5) { mexPrintf("Coefficient Matrix Must have 5 Columns: "); mexPrintf("Coeffs=[A0 A1 A2 B1 B2]\n"); return 1; } if ( mxGetM(pCOEFFSM) != nChannels) { mexPrintf("Number of input channels must be same as number"); mexPrintf(" of filter channels (rows).\n"); return 1; } a0 = &(mxGetPr(pCOEFFSM)[0*nChannels]); a1 = &(mxGetPr(pCOEFFSM)[1*nChannels]); a2 = &(mxGetPr(pCOEFFSM)[2*nChannels]); b1 = &(mxGetPr(pCOEFFSM)[3*nChannels]); b2 = &(mxGetPr(pCOEFFSM)[4*nChannels]); if ( nrhs > 2 ){ int i = mxGetM(pGAINM) * mxGetN(pGAINM); if (i == nChannels){ gains = mxGetPr(pGAINM); } else { mexPrintf("Number of gain terms must be same as " "number of filter channels (rows).\n"); return 1; } } else { gains = 0; } /*------------ Allocate the output matrix ------------------------------- */ outputMatrix = mxCreateDoubleMatrix((INT)1, nSamples, mxREAL); outputData = mxGetPr(outputMatrix); /*---- Create the state matrix, fill in the input values if specified --*/ stateMatrix = mxCreateDoubleMatrix(nChannels, kNumStateVars, mxREAL); stateData = mxGetPr(stateMatrix); if ( nrhs >= 4 ) { DOUBLE *inputStateArray; int i; if ( mxGetM(pSTATEM) != nChannels || mxGetN(pSTATEM) != kNumStateVars){ mexPrintf("MEX file soscascade got a bad state " "input. Should be size %dx%d.\n", nChannels, kNumStateVars); return 1; } inputStateArray = mxGetPr(pSTATEM); for (i=0; i<mxGetSize(pSTATEM); i++) stateData[i] = inputStateArray[i]; } stateData = mxGetPr(stateMatrix); state1 = &stateData[0*nChannels]; state2 = &stateData[1*nChannels]; return 0; }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { // INPUT: float *pfY, *pfBias, *pfWeight; // OUTPUT: float *pfYout; mwSize ndims_out, *dims_out; // Local: const mxArray * pArg; // mwSize nrowsX,ncolsX, nrowsY1, ncolsY1, nrowsY2, ncolsY2; //long Nx, nshift, Nvecs, Ny; long h, w, kH, kW, dH, dW, nInputPlanes, nInputPlanes_y, h_out, w_out, nOutputPlanes; long nBias; /* --------------- Check inputs ---------------------*/ if (nrhs != 5) mexErrMsgTxt("5 inputs required"); if (nlhs > 1) mexErrMsgTxt("only one output allowed"); /// ------------------- Y ---------- pArg = prhs[0]; if (!mxIsNumeric(pArg) || !mxIsSingle(pArg) || mxIsEmpty(pArg) || mxIsComplex(pArg) ) mexErrMsgTxt("Input 1 (Y) must be a noncomplex matrix of singles."); pfY = (float*) mxGetData(prhs[0]); h = mxGetM(pArg); w = mxGetSize(pArg, 2); nInputPlanes_y = (long) mxGetSize(pArg, 3); //mexPrintf("Size Y = %d x %d x %d\n", mxGetSize(pArg, 1), mxGetSize(pArg, 2), mxGetSize(pArg, 3)); /// ------------------- Bias ---------- pArg = prhs[1]; if(!mxIsNumeric(pArg) || !mxIsSingle(pArg) || mxIsEmpty(pArg) || mxIsComplex(pArg) ) { mexErrMsgTxt("Input 2 (Bias) must be a noncomplex single matrix."); } pfBias = (float*) mxGetData(pArg); nBias = (long) mxGetNumberOfElements(pArg); /// ------------------- Weight ---------- pArg = prhs[2]; if(!mxIsNumeric(pArg) || !mxIsSingle(pArg) || mxIsEmpty(pArg) || mxIsComplex(pArg) ) { mexErrMsgTxt("Input 3 (Weight) must be a noncomplex single matrix."); } pfWeight = (float*) mxGetData(pArg); kH = mxGetM(pArg); kW = mxGetSize(pArg, 2); nInputPlanes = mxGetSize(pArg, 3); nOutputPlanes = mxGetSize(pArg, 4); if (nInputPlanes_y != nInputPlanes) { mexPrintf("number of input planes in weight mtx: %d. number of input planes in y : %d\n", nInputPlanes, nInputPlanes_y); mexErrMsgTxt("number of input planes in weight mtx must be the same as the number of input planes in y"); } if (nBias != nOutputPlanes) { mexPrintf("number of elements in Bias : %d. size3 = %d\n", nBias, nOutputPlanes); mexErrMsgTxt("number of elements in Bias must be the same size of dimension 3 of weights"); } //mexPrintf("Size Weight = %d x %d x %d\n", kH, kW, nOutputPlanes); //mexPrintf("Size Weight = %d x %d x %d\n", mxGetSize(pArg, 1), mxGetSize(pArg, 2), mxGetSize(pArg, 3)); /// ------------------- dH ---------- pArg = prhs[3]; if(!mxIsNumeric(pArg) || !mxIsSingle(pArg) || mxIsEmpty(pArg) || mxIsComplex(pArg) || (mxGetNumberOfElements(pArg) > 1) ) { mexErrMsgTxt("Input 4 (dH) must be a noncomplex single scalar."); } dH = (long) mxGetScalar(pArg); /// ------------------- dW ---------- pArg = prhs[4]; if(!mxIsNumeric(pArg) || !mxIsSingle(pArg) || mxIsEmpty(pArg) || mxIsComplex(pArg) || (mxGetNumberOfElements(pArg) > 1) ) { mexErrMsgTxt("Input 5 (dW) must be a noncomplex single scalar."); } dW = (long) mxGetScalar(pArg); h_out = floor( (h - kH)/ dH) + 1; w_out = floor( (w - kW)/ dW) + 1; //mexPrintf("h, w, kH, kW, dH, dW = %d, %d, %d, %d, %d, %d\n", h, w, kH, kW, dH, dW); // y_out1 = zeros(h_out, w_out, nOutputPlanes); // pfYout = (float***) mxCalloc(h_out * w_out * nOutputPlanes); /// ------------------- Yout (OUTPUT)---------- ndims_out = 3; dims_out = (mwSize*) mxCalloc(ndims_out, sizeof(mwSize)); dims_out[0] = (mwSize) h_out; dims_out[1] = (mwSize) w_out; dims_out[2] = (mwSize) nOutputPlanes; //mexPrintf("Creating output ... \n"); //mexPrintf("Size Yout (before) (a) = %d x %d x %d\n", h_out, w_out, nOutputPlanes); //mexPrintf("Size Yout (before) (b) = %d x %d x %d\n", dims_out[0], dims_out[1], dims_out[2]); plhs[0] = mxCreateNumericArray(ndims_out, dims_out, mxSINGLE_CLASS, mxREAL); pfYout = (float*) mxGetData(plhs[0]); //mexPrintf("Size Yout = %d x %d x %d\n", mxGetSize(plhs[0], 1), mxGetSize(plhs[0], 2), mxGetSize(plhs[0], 3)); nn_spatialConvolution(pfY, pfBias, pfWeight, dH, dW, h, w, kH, kW, nInputPlanes, nOutputPlanes, pfYout); }