I have a sampled square wave (with 80% duty cycle supposedly) as input, and I need to check if the period of the signal is 20 second. Since I sample every 100 ms, I have saved the signal in an array of 200. The array would then look something like this:
int signal_buffer [200] = {0,0, . . . , 1500,1500,1500, . . . , 0}
With 1500 being my 'high' state. Of course this signal buffer could look different if the high part of the wave starts at the beginning of the recorded buffer or somewhere in the middle, then I would have something like:
int signal_buffer [200] = {1500,1500, . . . , 0,0,0, . . . , 1500,1500}
My question now is what would be a good algorithm to actually check that the period of this signal is actually 20 seconds? I tried counting the zeros in between the highs and tried to infer the period from there, is the task even possible with a buffer that covers exactly 20 seconds?
… is the task even possible with a buffer that covers exactly 20 seconds?
A function f is periodic with period p iff f(x+p) = f(x) (and hence f(x+kp) = f(x) for any integer k). In order to test this, you must at least have the value of the function at some point x and another point x+p. If you have only the values of the function over one period, you do not have the values at the necessary points and cannot test this property.
It is possible the interval you do have would contain either all of one duty portion (value 1500) or all of one off-duty portion (value 0), and you could test that that portion is the expected duration. But you would not be able to test that the complementary portion is the right length, since you have no indication of where it begins or ends outside the interval you have.
Also, there is some question about whether only the values 0 or 1500 would be observed. Physical measurements tend to vary. Even if the signal were well controlled so that it was exactly 1500 units and your measuring device measured that correctly, it would be expected that during an interval of transition from 0 to 1500 or vice-versa that the measurement device would report some value in between. You would want to allow some tolerance for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With