# Determining the period of a discontinuous function

I'm new to the field of DSP.

I'm trying to determine the period and shift of the function. I've tried using FFT, but haven't had much luck. Seems like it should be simple.

Signal (pastebin of Octave matrix):

# Created by Octave 3.2.4, Wed Dec 12 00:26:41 2012 PST <jjohnson@jjohnson>
# name: a
# type: matrix
# rows: 1
# columns: 495
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.529411764705882 0.945098039215686 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.415686274509804 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.556862745098039 0.890196078431372 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.72156862745098 0.749019607843137 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.862745098039216 0.611764705882353 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.933333333333333 0.470588235294118 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


Signal drawn with plot(a):

By hand I can tell that the shift is 75, and period is ~56. How do I get that from the results of the FFT?! Is there some other more appropriate algorithm?

FFT drawn with plot(abs(fft(a))):

-
@penelope: Can you post the octave matrix as well? –  Naresh Dec 12 '12 at 9:55
Thank you @penelope for fixing up my post! –  Zigner Dec 12 '12 at 9:58

This will give you a plot of the autocovariance up to lag 100 samples:

plot(autocov(a,100))


There you can clearly get the period of your signal.

Another approach is to explicitly get the time of each pulse:

pulses = a > 0.1;
periods = diff(times)

ans =
55   56   56   56   56


Explanation: pulses is 1 wherever there is a pulse. leading_edges gets a 1 only on the first sample of a pulse. times gives the sample number of each leading edge.

With this result you can perform your own statistics or estimation. This second method is computationally more efficient than using transforms. Computing time is linear with number of samples.

-
Thanks for the help. I'll give it a try, I think I may have oversimplified it by providing such a clean signal. –  Zigner Dec 12 '12 at 16:23
I'll be using the auto correlation method, thanks! –  Zigner Dec 13 '12 at 16:29

If you remove the DC offset before the FFT, the FFT result will show the low frequency peak a little more clearly.

-