<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />Hi,
I have process signal traces and identify pulse traces against random wafer forms. In the plot below , only signal values with adjacent sampling points have non-zero value, but if 1 sample point has non-zero values it is to be discarded.
Secondly, only pulse traces with a threshold above a certain value , say 1.5 like here, are to be counted.
I am looking to develop a simple script for this. The signalv, samples and traces are stored as columns .

No doubt there are more efficient ways to do this, but the code below may get you started:
NamesDefaultToHere(1);
// Function to count 'signals' in a data vector
countSignals =
Function({vec, val}, {Default Local},
// Locate points above the value 'val'
plusPos = Loc(vec > val);
zeroPos = Loc(vec <= val);
// Recode points appropriately
vec[plusPos] = 1;
vec[zeroPos] = 0;
// Count the number of signals (runs of two or more values of +1): Initialise variables
nSignals = 0;
isSignal = 0;
previous = vec[1];
// Loop over the elements of vec starting with the second . . .
For(e=2, e<=NRow(vec), e++,
if(!isSignal,
// If we are not already in the 'middle' of a signal, start one
if(vec[e] == previous & previous == 1, isSignal = 1),
// If we are already in the 'middle' of a signal, has it come to an end? If so count it, and reset.
if(vec[e] == 0, nSignals++; isSignal = 0)
);
// If we are at the end of vec and are in the'middle' of a signal, we still need to count it
if(e == NRow(vec) & isSignal, nSignals++);
// Update 'previous' value ready for next iteration
previous = vec[e];
);
// Return the number of signals
nSignals;
);
/*
// This test vector has four runs (using a threshold of 0.5):
v = [0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1];
Print(countSignals(v, 0.5));
*/
// Make somw dummy data . . .
n = 100;
data = RandomShuffle(J(n/2, 1, RandomNormal(4, 1))|/J(n/2, 1, 0));
dt = AsTable(data);
dt << setName("Test Data for Signal Counting");
Column(dt, "Col1") << setName("Value");
// Plot it . . .
NewWindow("This data has "||Char(countSignals(data, 1.0))||" Signals",
dt << Graph Builder(
Show Control Panel( 0 ),
Show Legend( 0 ),
Variables( X( Transform Column( "Row", Formula( Row() ) ) ), Y( :Value ) ),
Elements( Line( X, Y, Legend( 4 ) ), Points( X, Y, Legend( 5 ) ) ),
SendToReport(
Dispatch( {}, "Value", ScaleBox, {Add Ref Line( 1, "Solid", "Red", "", 1 )} )
)
);
);