Forums › General Discussions › MAX HOLD configuration using Python SDK › Reply To: MAX HOLD configuration using Python SDK
Andrew
Moderator
The way that max hold works in Spike, is that each time a new sweep is performed, each bin in the sweep is max held with that same bin in the max held sweep.
Your algorithm might look like this,
1) Configure device
2) Capture first sweep and set as max hold sweep
3) Capture next sweep into variable “temp”. For each bin in the max hold sweep, set that bin to the max of either temp or max hold.
// Pseudo-code for #3
for(int i = 0; i < sweepSize; i++) {
maxHoldSweep[i] = (maxHoldSweep[i] > temp[i]) ? maxHoldSweep[i] : temp[i];
}
4) Repeat #3 until desired number of sweeps or time elapsed, or after ping has been sent.
5) To determine the peak value in the sweep, simply iterate over the max hold sweep and look for the max value.
// Pseudocode for #5
int maxIndex = 0;
for(int i = 1; i < sweepSize; i++) {
if(maxHoldSweep[i] > maxHoldSweep[maxIndex]) {
maxIndex = i;
}
}
double maxValue = maxHoldSweep[maxIndex];
Hope this helps
