Esempio n. 1
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
	
	double *px, cf, binwidth, reptime, cohc, cihc;
	int    nrep, pxbins, lp, outsize[2], totalstim;

	double *pxtmp, *cftmp, *nreptmp, *binwidthtmp, *reptimetmp, *cohctmp, *cihctmp;
	
    double *ihcout;
   
	void   SingleAN(double *, double, int, double, int, double, double, double *);
	
	/* Check for proper number of arguments */
	
	if (nrhs != 7) 
	{
		mexErrMsgTxt("catmodel_IHC requires 7 input arguments.");
	}; 

	if (nlhs !=1)  
	{
		mexErrMsgTxt("catmodel_IHC requires 1 output argument.");
	};
	
	/* Assign pointers to the inputs */

	pxtmp		= mxGetPr(prhs[0]);
	cftmp		= mxGetPr(prhs[1]);
	nreptmp		= mxGetPr(prhs[2]);
	binwidthtmp	= mxGetPr(prhs[3]);
	reptimetmp	= mxGetPr(prhs[4]);
    cohctmp		= mxGetPr(prhs[5]);
    cihctmp		= mxGetPr(prhs[6]);
		
	/* Check with individual input arguments */

	pxbins = mxGetN(prhs[0]);
	if (pxbins==1)
		mexErrMsgTxt("px must be a row vector\n");
	
	cf = cftmp[0];
	if ((cf<80)|(cf>40e3))
	{
		mexPrintf("cf (= %1.1f Hz) must be between 80 Hz and 40 kHz\n",cf);
		mexErrMsgTxt("\n");
    }
	
	nrep = (int)nreptmp[0];
	if (nreptmp[0]!=nrep)
		mexErrMsgTxt("nrep must an integer.\n");
	if (nrep<1)
		mexErrMsgTxt("nrep must be greater that 0.\n");

    binwidth = binwidthtmp[0];
	
	reptime = reptimetmp[0];
	if (reptime<pxbins*binwidth)  /* duration of stimulus = pxbins*binwidth */
		mexErrMsgTxt("reptime should be equal to or longer than the stimulus duration.\n");

    cohc = cohctmp[0]; /* impairment in the OHC  */
	if ((cohc<0)|(cohc>1))
	{
		mexPrintf("cohc (= %1.1f) must be between 0 and 1\n",cohc);
		mexErrMsgTxt("\n");
	}

	cihc = cihctmp[0]; /* impairment in the IHC  */
	if ((cihc<0)|(cihc>1))
	{
		mexPrintf("cihc (= %1.1f) must be between 0 and 1\n",cihc);
		mexErrMsgTxt("\n");
	}
	
	/* Calculate number of samples for total repetition time */

	totalstim = (int)floor((reptime*1e3)/(binwidth*1e3));

    outsize[0] = 1;
	outsize[1] = totalstim;

    px = (double*)mxCalloc(outsize[1],sizeof(double)); 

	/* Put stimulus waveform into pressure waveform */

	for (lp=0; lp<pxbins; lp++)
			px[lp] = pxtmp[lp];
	
	/* Create an array for the return argument */
	
	plhs[0] = mxCreateNumericArray(2, outsize, mxDOUBLE_CLASS, mxREAL);
	
	/* Assign pointers to the outputs */
	
	ihcout  = mxGetPr(plhs[0]);
		
	/* run the model */

	SingleAN(px,cf,nrep,binwidth,totalstim,cohc,cihc,ihcout);

 mxFree(px);

}
Esempio n. 2
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{

    double *px, cf, tdres, fibertype, noiseType, implnt;
    int    nrep, pxbins, lp, outsize[2], totalstim;

    double *pxtmp, *cftmp, *nreptmp, *tdrestmp, *fibertypetmp, *noiseTypetmp, *implnttmp;

    double *meanrate, *varrate, *psth;

    void   SingleAN(double *, double, int, double, int, double, double, double, double *, double *, double *);

    /* Check for proper number of arguments */

    if (nrhs != 7)
    {
        mexErrMsgTxt("model_Synapse requires 7 input arguments.");
    };

    if (nlhs != 3)
    {
        mexErrMsgTxt("model_Synapse requires 3 output argument.");
    };

    /* Assign pointers to the inputs */

    pxtmp       = mxGetPr(prhs[0]);
    cftmp       = mxGetPr(prhs[1]);
    nreptmp     = mxGetPr(prhs[2]);
    tdrestmp    = mxGetPr(prhs[3]);
    fibertypetmp= mxGetPr(prhs[4]);
    noiseTypetmp= mxGetPr(prhs[5]);
    implnttmp   = mxGetPr(prhs[6]);

    /* Check with individual input arguments */

    pxbins = mxGetN(prhs[0]);
    if (pxbins==1)
        mexErrMsgTxt("px must be a row vector\n");

    cf = cftmp[0];

    nrep = (int)nreptmp[0];
    if (nreptmp[0]!=nrep)
        mexErrMsgTxt("nrep must an integer.\n");
    if (nrep<1)
        mexErrMsgTxt("nrep must be greater that 0.\n");

    tdres = tdrestmp[0];

    fibertype  = fibertypetmp[0];  /* spontaneous rate of the fiber */

    noiseType  = noiseTypetmp[0];  /* fixed or variable fGn */

    implnt = implnttmp[0];  /* actual/approximate implementation of the power-law functions */

    /* Calculate number of samples for total repetition time */

    totalstim = (int)floor(pxbins/nrep);

    px = (double*)mxCalloc(totalstim*nrep,sizeof(double));

    /* Put stimulus waveform into pressure waveform */

    for (lp=0; lp<pxbins; lp++)
            px[lp] = pxtmp[lp];

    /* Create an array for the return argument */

    outsize[0] = 1;
    outsize[1] = totalstim;

    plhs[0] = mxCreateNumericArray(2, outsize, mxDOUBLE_CLASS, mxREAL);
    plhs[1] = mxCreateNumericArray(2, outsize, mxDOUBLE_CLASS, mxREAL);
    plhs[2] = mxCreateNumericArray(2, outsize, mxDOUBLE_CLASS, mxREAL);

    /* Assign pointers to the outputs */

    meanrate      = mxGetPr(plhs[0]);
    varrate = mxGetPr(plhs[1]);
    psth      = mxGetPr(plhs[2]);

    /* run the model */

    mexPrintf("ANmodel: Zilany, Bruce, Ibrahim, and Carney : Auditory Nerve Model\n");

    SingleAN(px,cf,nrep,tdres,totalstim,fibertype,noiseType,implnt,meanrate,varrate,psth);

 mxFree(px);

}