I am working with a signal which is a periodic square signal with some kind of noise and some outliers. I would like to know which is the best solution in order to get the period and clean the outliers that can be seen in the image:

The final goal is to binarize the signal.
Thanks in advance,
flagat the bottom of your post) and ask them to migrate this question to dsp.SE which is a better fit. – Dilip Sarwate Feb 19 at 14:11