I need to count the number of 'patterns per second' in a signal. The problem is that the signal changes 'shape' a lot and unpredictably. It is still easy for a person to see the the pattern, but I don't know how to do this with code.

EDIT For extra clarity: say the first sample is 1 second. There are 17 copies of the pattern in this sample. So I want to compute "17 (patterns per second)". Also, it might be worth noting the samples below are from a continuous measurement, in this order.

Any ideas how to tackle this?

(It needs to count the pattern in realtime.)

Here are some samples of the signal. (Zoom level in both directions is identical for all images.)

sample 1

sample 2

sample 3

sample 4

sample 5

  • $\begingroup$ it's not quite clear what you mean by pulse. Can you mark each pulses on your samples? (For example by red circle). It will be especially useful for last and first sample $\endgroup$ – SergV Jan 14 '13 at 9:59
  • $\begingroup$ I'm sorry for not being clear. I need to count the number of 'patterns' in a certain amount of time (say 1 second). A pattern in the first sample is 3 peaks, in the last one (and all in between) it's two peaks. This inconsistency in peaks per pattern makes it hard, otherwise I could just count the peaks and divide by 2. $\endgroup$ – Jongsma Jan 14 '13 at 10:25

You can trying using a musical pitch detection/estimation algorithm, which may be more robust in some cases than just a simple autocorrelation (especially in one of your examples that includes a slightly inharmonic overtone). From the frequency or period of the estimated "pitch" you can compute the number of pattern repetitions per second.

A bunch of pitch estimation methods are mentioned in my answer to this question: https://stackoverflow.com/questions/7181630/fft-on-iphone-to-ignore-background-noise-and-find-lower-pitches

| improve this answer | |

Since you have a periodic signal, you can look at the autocorrelation. The lag of the peaks will tell you the periods of the components. If by "patterns" you mean the peaks within each period, you can simply do another round of peak detection.

| improve this answer | |
  • $\begingroup$ Thank you for your answer! SergV pointed out that my question wasn't clear. (I think I used the word pattern incorrectly.) To be clear: I want to count the number of COPIES of the visible pattern in the samples. Would autocorrelation still be the recommended approach? $\endgroup$ – Jongsma Jan 14 '13 at 10:36
  • 1
    $\begingroup$ Yes, because the autocorrelation will give you the number of samples between repeats, and you know how many samples the whole things is, so divide the second by the first to get your answer. $\endgroup$ – Emre Jan 14 '13 at 10:49
  • $\begingroup$ Autocorrelation can be only first step in your algorithm. If T is period of your signal, autocorrelation will have peaks on T, 2*T ... n*T and on T/2, T/3... T/n (harmonic of your signal). So you need to have good algorithm to find valid T. $\endgroup$ – SergV Jan 15 '13 at 3:13

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.