In: Computer Science
So, I'm trying to get revolutions/second from a given binary data.
for example, the input binary data is:
V=[0 1 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0 1 0 ]
let's say the distance between each value is arbitrary (for this example, you can use 0.1). Each 1 represents a full rotation of a bike pedal, and I'm trying to calculate the pedal rate from a given binary dataset in Matlab. How would I do so?
EDIT for clarification:
So, I'll be receiving data from a bike as a binary vector (0s and 1s). Each 0 or 1 represent a measurement. I think each number represents like a certain time. So the vector [0 1 0 0 1 ] would mean two rotations and just a guess at the time between each value is .1 seconds. So the cadence would be 1 rev/.3s.
I'm trying to figure out how to write a program to read the given vector and output a cadence.
I'm assuming that at every occurrence of 1 in the data set, the bike pedal completes its one rev.
so to calculate rev/s we need total revolutions completed in 'T' time::
so for revolutions we we will calculate number of 1's in data set and subtract 1 from it(since we dont know exactly how much time it took for the first revolution).
To calculate time: we will take difference of indices of first and last occurrence of 1 in given vector, this will give us our time period
eg. in our dataset [0 1 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0 1 0 ] -> we have 5 rev and
index of first 1 is 2; index of last 1 is18 T=16
rev/s= 5/16
V=[0 1 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0 1 0 ]
arb=0.1;
rev=sum(V) %will give total number of ones in our vector
ind=find(V) %it will return vector with indices of non-zero elements of in a matrix,
%in our case vector with indices of 1's
T=ind(end)-ind(1) %last occurence of 1 - first occurence of 1
frequency=(rev-1)/(T*arb) %calculating frequency(revolution per second)
(for any doubt in solution just leave a comment else please press the like button)