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.


migrated from stackoverflow.com May 2 '16 at 21:43

This question came from our site for professional and enthusiast programmers.

  • $\begingroup$ @Suever I don't want to remove the noise. My aim here is to measure the signal:noise ratio of the square pulse. $\endgroup$ – Pete Apr 11 '16 at 16:06
  • 1
    $\begingroup$ 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. $\endgroup$ – Suever Apr 11 '16 at 16:07
  • 1
    $\begingroup$ IEC 60469 gives several algorithms to tackle this problem exactly, if you have access to that... $\endgroup$ – RPM Apr 11 '16 at 16:18
  • $\begingroup$ @Suever So use the filtered signal to find the 'cut-offs' and then apply this to the unfiltered signal? Thanks, I will try this. $\endgroup$ – Pete Apr 11 '16 at 16:21
  • 1
    $\begingroup$ Yes, that is what I meant. It's simple but may be enough. $\endgroup$ – Suever Apr 11 '16 at 16:26


Your noise is Gaussian.

Proposed solution

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).

Your signal will then be the difference in positions of the Gaussians, and your noise is given by their widths.

Yes, there will still be contributions from the sides of the rect-pulse. However, there probably is no way to fully get rid of them, since you need some criterion to tell apart plateau values from values from the side lobes, what always becomes problematic if a point is close to the baseline/plateau. You could mitigate this effect by using the histogram values not only as datapoints for the fit, but also as fit weights. By doing so, the (low number of) side lobe values gets less weight compared to the (high number of) plateau/baseline values.


I was able to solve this problem by using the approach answered here: https://stackoverflow.com/questions/36583451/matlab-signal-clipping-method-skips-array-indexes

  • $\begingroup$ You should copy part of that answer here, and mark this answer as selected. As it is, this is a link-only answer and while the link is to SO, it'd be better for the answer to this question to be here. $\endgroup$ – Peter K. May 18 '16 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.