I have a signal made of a perturbed square wave, sampled so that there are at least six samples per period, for a total of 15 to 50 periods. The sampling frequency and the signal frequency are unrelated.

The perturbations are of several types:

  • jitter in the period (say 10%),

  • variable amplitude of the squares (say from 1 to 3),

  • additional arbitrary signal with an amplitude below 1, often localized.

I am looking for a simple, fast but robust computational procedure to estimate the average period (preferaby without a DFT or autocorrelation).

Typical example:

enter image description here

  • $\begingroup$ How about locating each rising edge and then averaging (or, maybe, median?) the time differences between their locations? The reciprocal of that average might be a good estimate of the fundamental frequency of the square wave. $\endgroup$
    – Atul Ingle
    Commented Oct 9, 2017 at 19:15
  • $\begingroup$ @AtulIngle: yes, this looks like a good option. In a few cases, some rising edges may be missing, but using the median of the deltas will cope. Now I must find a robust way to detect these edges (actually the scale of amplitudes is unknown beforehand). $\endgroup$
    – user7657
    Commented Oct 9, 2017 at 19:20
  • $\begingroup$ Use a threshold - any jump that exceeds the threshold indicates a rising edge. Use the first few cycles of incoming data to "train" this threshold. $\endgroup$
    – Atul Ingle
    Commented Oct 9, 2017 at 19:33
  • $\begingroup$ @AtulIngle: the processing is off-line, so I have the option of taking some spread statistic to estimate a threshold. $\endgroup$
    – user7657
    Commented Oct 9, 2017 at 20:26

1 Answer 1


You can locate each rising edge and use that as the start time of each new cycle. Then compute the time differences between their locations and then take reciprocal of the average (or median, for more robustness against outliers) of these time differences to estimate frequency.

Locating the rising edges can be achieved by checking if the difference in consecutive data points exceeds a predetermined threshold. This threshold can be set adaptively from data. For instance, if you make a scatter plot of all your data samples it should look bimodal: the higher values correspond to the peaks of the square wave and the lower values to the valleys.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.