# Finding threshold for noisy pulse train

I have a noisy signal that roughly switches between two distinct amplitude levels, i.e. looks like a pule train with irregular pulse with and small variations in the "on" and "off" amplitude over time, part of it could look something like this:

I'm looking for a robust algorithm that will produce a "good" (I'm not sure what criterion to apply here) binary decision threshold from this signal such that signal samples with amplitude above that threshold correspond to plateaus and samples with amplitude below the threshold correspond to minima.

• Can you simply look at the differential of the signal? This may help you locate the falling and rising edges. Will this do the job for you? – havakok Apr 24 at 8:17
• That sounds sensible, but I'm not sure how get a threshold value out of that. I'm thinking I could detect peaks in the derivative, use those to split the original signal into "low" and "high" regions and then calculate the average amplitudes of both categories and obtain a threshold from that. Is that what you had in mind? – Peter Apr 24 at 8:26
• Almost, I would start, as you said, by splitting. I will then continue to normalize each split separately. Normalizing will be enough by subtracting the average and dividing by the max absolute value per split. After normalization, all signals will be nested around 0 with amplitude smaller than 1. You may now concatenate them and threshold on 0This may do the trick? – havakok Apr 24 at 8:34
• What is the range of your amplitude? Your question is very vague, an answer could be put an threshold above the mean of the max and min value. It seems that epochs where the signal is going down are very short in time. You could therefor also calculate the mean and variance of the epochs in the "high" state and define the threshold based on these values ... – Irreducible Apr 24 at 8:36
• I don't really have more information about the problem than that the signal looks similar to the picture above over its complete duration, i.e. I don't have concrete limits for the "high" and "low" amplitudes. I just now tried splitting the signal by looking at the derivative but I'm finding it hard to locate the peaks in the derivative because they are not super distinct due to noise. – Peter Apr 24 at 8:57