# Cleaning a signal and computing period

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,

-

2
You should not ask the same question on two different stackexchanges. Please contact the moderators (click on the link marked `flag` at 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

## 1 Answer

Here's what I would do:

1. Lowpass filter the signal to remove the high-frequency noise.
2. Once you lowpass filter the original signal, it won't look like a square wave anymore. The infinitely sharp transitions will be damped. Thus, apply a $1$-bit quantizer (with hysteresis) to the output of the lowpass filter, so that you "binarize" the lowpass filtered signal.
3. Differentiate the "binarized" signal, in order to obtain a train of impulses. Compute the duration of the time intervals between successive impulses, compile a list of such durations, then compute a histogram, normalize the histogram, and then compute the 1st moment of the normalized histogram (which is an estimate of the expected value of the period).
-
Dear Rod, I fully understand your answer and I guess it will work well. I will try it immediately. Thanks for your answer. – Dídac Pérez Feb 19 at 11:49

1
A median filter (instead of an average) could be better for step 1. – leonbloy Feb 19 at 14:57
@leonbloy: It's hard to implement a median filter using analog electronics, though. – Rod Carvalho Feb 19 at 19:12
@RodCarvalho Sure - it's also hard to compute histograms. But I don't see anything about analog electronics in the OP. – leonbloy Feb 19 at 20:43
@leonbloy: You're right. The solution I proposed is arguably ugly, but implementable using analog electronics. It's how digital signals are regenerated (if I remember my communication systems classes properly). – Rod Carvalho Feb 19 at 20:56
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9218964576721191, "perplexity_flag": "middle"}