Not a software fix: How about a simple RC filter ?
(dedicated counters sometimes have a analog threshold setting... , but that doesn't help here unless you build a comparator with settable threshold)
and isn't there a debounce filter for the counters, that maybe work? Depending on the actual pulse and spike timings you didn't 'valued' 😉
A software solution would be the median filter as a preprocessing for the analog pulse counter, that will remove spikes and 'sharpen' the edges.
Greetings from Germany
Henrik
LV since v3.1
“ground” is a convenient fantasy
'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'