# MATLAB: get members of histogram populations EXCLUDING those inbetween

The Problem

I have a (noisy) square wave signal and need to extract the data points that make up the 'baseline' and 'plateau' ONLY. I do not want data from the rise and fall. So far I have accomplished the following:

data points designated as 'baseline' or 'plateau' superimposed onto original signal

I have defined 'baseline' data points as those from the minimum to the mean of the lowest 25% of signals + 1 standard deviation of the lowest 25% of signals.

Similarly I have defined 'plateau' data points as those from the maximum to the mean of the highest 25% of signals - 1 standard deviation of the highest 25% of signals.

This works ok, but as you can see: sometimes 1 standard deviation is not enough to encapsulate all of the baseline noise. 2 Standard deviations often encapsulate too much of the rise/fall of the signal.

Can anyone provide a more elegant solution to this?

My aim is to measure the signal to noise ratio of the square pulse, so I need to extract the populations that will give me baseline noise and the mean pulse height.

• @Suever I don't want to remove the noise. My aim here is to measure the signal:noise ratio of the square pulse. – Pete Apr 11 '16 at 16:06
• I realize you don't want to remove the noise... You remove the noise only for binning into plateau and baseline. Then you can use the un-filtered signal (after binning) to do the analysis. – Suever Apr 11 '16 at 16:07
• IEC 60469 gives several algorithms to tackle this problem exactly, if you have access to that... – RPM Apr 11 '16 at 16:18
• @Suever So use the filtered signal to find the 'cut-offs' and then apply this to the unfiltered signal? Thanks, I will try this. – Pete Apr 11 '16 at 16:21
• Yes, that is what I meant. It's simple but may be enough. – Suever Apr 11 '16 at 16:26

Assumption

Compute the histogram of your data. There will be two peaks, as in the histogram you've shown. Extract the approximate positions of the peaks and use these values as starting values to fit two Gaussian curves to both peaks, each with the fit parameters $\mu$ (mean signal, i.e. position of the Gaussian) and $\sigma$ (width of the Gaussian).