-
Notifications
You must be signed in to change notification settings - Fork 1
/
cosineFilterMex.c
33 lines (25 loc) · 980 Bytes
/
cosineFilterMex.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "mex.h"
#define PI 3.14159265
void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *spikes, *samples, *values, width;
int iiSpike, iiSample, iiLeft, nSamples, nSpikes;
spikes = mxGetPr(prhs[0]);
samples = mxGetPr(prhs[1]);
width = *mxGetPr(prhs[2]);
nSpikes = mxGetM(prhs[0]) * mxGetN(prhs[0]);
nSamples = mxGetM(prhs[1]) * mxGetN(prhs[1]);
plhs[0] = mxCreateDoubleMatrix(mxGetM(prhs[1]),mxGetN(prhs[1]),mxREAL);
values = mxGetPr(plhs[0]);
iiLeft = 0;
for(iiSample=0; iiSample<nSamples; iiSample++) {
while(iiLeft<nSpikes && spikes[iiLeft]<samples[iiSample]-width/2) {
iiLeft++;
}
for(iiSpike=iiLeft; iiSpike<nSpikes && spikes[iiSpike]<samples[iiSample]+width/2; iiSpike++) {
values[iiSample] += (cos((spikes[iiSpike]-samples[iiSample])/width*2*PI)+1)/2;
}
}
}