void PulseDet(void* ptrIn, void* ptrOut, long nLen, long nNumTrace) {
#define x ((long*)ptrIn)
#define y ((long*)ptrOut)
extern float AmpThreshold;
extern int thresh_sum;
extern int RunLen;
extern long PulseWidth;
extern float FilterGainFactor;
extern float NoiseFloor;
extern float DigScaleFactor;
extern int Save[];
#define SaveLength 20
#define thresh_pulse 50
int n,nIndex,j,k,sum,pulse_count, pulse_visible;
float thresh;
pulse_count = 0;
pulse_visible = 0;
for (n=0; n<nLen; n++) {
nIndex = nNumTrace*n;
/* show traces 0 and 1 as raw data */
x[nIndex] = DigScaleFactor*x[nIndex];
if (nNumTrace > 1) {
x[nIndex+1] = DigScaleFactor*x[nIndex+1];
}
/* bias trace 1 and 2, subtract trace 1 from trace 0, show as trace 2 */
if (nNumTrace > 2) {
x[nIndex+2] = abs((x[nIndex] + 32768) - (x[nIndex+1] +
32768));
}
/* update very long-term average */
thresh_sum = FilterGainFactor*x[nIndex+2] +
(1-FilterGainFactor)*thresh_sum;
/* apply running sum pulse filter, show as trace 3 */
sum = 0;
k = SaveLength-1;
for (j=0; j<RunLen; j++) {
if ((n-j) < 0) sum += Save[k--];
else sum += x[nNumTrace*(n-j)+2];
}
sum >>= 3;
if (sum > AmpThreshold*thresh_sum + NoiseFloor) {
if (nNumTrace > 3) x[nIndex+3] = 10000;
// pulse = 1
pulse_count++;
}
else {
if (nNumTrace > 3) x[nIndex+3] = 0; // pulse = 0
if (pulse_count > PulseWidth) {
if (nNumTrace > 4)
x[nIndex+4] = 10000;
pulse_visible = 20; // arbitrary
pulse width; just needs to be visible
}
pulse_count = 0;
}
// extend pulse; make sure visible on screen
if (pulse_visible > 0) {
if (nNumTrace > 5) x[nIndex+4] = 10000;
pulse_visible--;
}
else if (nNumTrace > 5) x[nIndex+4] = 0;
}
// save end of each frame for use with next frame
for(n=nLen-1; n>=(nLen - SaveLength); n--) {
nIndex = n*nNumTrace;
Save[SaveLength-(n-nLen)] = x[nIndex+2];
}
} // end of function
1) y is output; i.e. output coming out of board (for example, speaker)
2) x is input; i.e. going into board; for example pulse generator
3) Both x and y are interleaved; i.e ch0,ch1,ch2...,chN-1 where N is the
number of channels.
4) if you modify x traces, you see it in the host display
5) if you modify y traces, you only know it if you look at the board's output
*/