Disclosure of Invention
The present invention is directed to solving, at least to some extent, one of the technical problems in the related art. To this end, it is an object of the present invention to provide a step-counting method, apparatus, device and storage medium
The technical scheme adopted by the invention is as follows:
a step counting method comprising the steps of:
s1: collecting motion data of a sensor in a motion process, wherein the sensor is a three-axis acceleration sensor; s2: acquiring a characteristic value of the collected motion data, and calculating step-counting motion data; s3: carrying out standardization processing on the characteristic value to obtain a standardized characteristic value; s4: judging a step counting state by using a step counting model according to the standardized characteristic value; s5: if the step counting state is in, counting steps according to the peak value of the step counting movement data and the size of the reference threshold value; the motion data includes: the acceleration value of the x axis, the acceleration value of the y axis, the acceleration value of the z axis and the three-axis synthetic acceleration square value; the step-counting motion data is a three-axis synthesized acceleration square value.
Further, in step S2, the characteristic values include the following characteristic values:
the mean value of the square value of the three-axis synthesized acceleration, the mean value of the acceleration value of the x axis, the mean value of the acceleration value of the y axis, the mean value of the acceleration value of the z axis,
The variance of the square of the three-axis composite acceleration, the variance of the x-axis acceleration, the variance of the y-axis acceleration, the variance of the z-axis acceleration, and the variance of the three-axis composite acceleration within the time window,
The maximum value of the square value of the three-axis synthesized acceleration, the maximum value of the x-axis acceleration value, the maximum value of the y-axis acceleration value, the maximum value of the z-axis acceleration value in the time window,
The minimum value of the square value of the three-axis synthesized acceleration, the minimum value of the acceleration value of the x axis, the minimum value of the acceleration value of the y axis, the minimum value of the acceleration value of the z axis in the time window,
And the difference value of the maximum value and the minimum value of the three-axis synthesized acceleration square value, the difference value of the maximum value and the minimum value of the x-axis acceleration value, the difference value of the maximum value and the minimum value of the y-axis acceleration value and the difference value of the maximum value and the minimum value of the z-axis acceleration value in the time window.
Further, the formula of the normalization process in step S3 is specifically:
wherein,representing the characteristic value data, X, after normalizationiRepresenting the characteristic value, mu, of the ith dimensioniAnd σiTo normalize the parameters, n represents the dimension of the eigenvalues.
Further, the muiAnd σiThe calculation formula is specifically as follows:
where m represents the number of samples in the training set, xi(j)Representing the ith dimension feature value of the jth sample.
Further, the step S4 of determining the step counting state specifically includes:
s41: judging the step counting state of the characteristic value data subjected to the standardization processing in the step counting model S3 by using the step counting model, wherein the step counting model specifically comprises the following steps:
wherein,a vector composed of normalized feature values obtained in step S3, W representing a vector composed of coefficients, and T representing a transpose of the vector;
the calculation formula of W is as follows:
wherein m represents the number of samples in the training set,normalized feature value, y, representing the ith sample(i)representing the marking value of the ith sample, wherein α is a regularization parameter, and solving by a gradient descent method to obtain a W value;
s42: the step counting state is judged according to the step counting state value obtained by the step counting model,
if F (X) >0.5 in S41, determining as a step counting state and executing S5;
if F (X) in S41 is less than or equal to 0.5, the step counting state is judged to be not step counting state and the step counting is restarted by returning to S1.
Further, before step S5, data filtering is further included, specifically:
and filtering the step-counting movement data by a fast Fourier transform principle.
Further, the reference threshold includes a dynamic peak threshold and a first preset threshold, and step S5 specifically includes:
s51: judging the peak value of the step-counting movement data, specifically:
ai>ai-1and a isi>ai+1
Wherein a isiFor step-counting movement data of the current moment, ai-1As step-counting movement data of the previous moment, ai+1Step counting movement data at the next moment;
s52: calculating a dynamic peak threshold according to the peak, specifically:
where B is the dynamic peak threshold, N is the number of peaks in the time window, AiThe value of the ith peak in the time window, C is a coefficient;
s53: counting steps, specifically:
each peak value within the time window is compared to a dynamic peak threshold B and a first preset threshold a, and if the peak value is greater than both a and B, the number of steps is incremented by one.
In another aspect, the present invention further provides a step counting device, including:
the acquisition device: the device is used for acquiring motion data of the sensor in the motion process;
the characteristic value acquisition device: the characteristic value of the collected motion data is acquired;
the characteristic value normalization device: carrying out standardization processing on the characteristic value to obtain a standardized characteristic value;
step counting state judgment device: the step counting module is used for judging a step counting state by utilizing a step counting model according to the standardized characteristic value;
and the step counting device is used for counting steps according to the peak value of the step counting movement data and the size of the reference threshold value if the step counting device is in the step counting state.
In another aspect, the present invention further provides a control device of a step counting method, including:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform a step counting method as claimed in any one of the preceding claims.
In another aspect, the present invention also provides a computer-readable storage medium storing computer-executable instructions for causing a computer to perform the step counting method according to any one of the above.
The invention has the beneficial effects that:
the step counting method of the invention acquires the characteristic value of the acquired motion data by acquiring the motion data of the three-axis acceleration sensor in the motion process, the feature values are normalized to obtain normalized feature values, and then the normalized feature values are subjected to a machine learning method (local linear classifier), judging the step counting state according to the standardized characteristic value, counting steps according to the peak value of the step counting movement data and the size of a preset threshold value when the step counting state is in the step counting state, wherein, as the user has a plurality of activity states, such as walking, running, riding, sitting, swimming and the like, therefore, whether step counting is started or not is difficult to accurately judge only by using a small amount of characteristics, and the step counting is inaccurate.
The first embodiment is as follows:
as shown in fig. 1, it is a basic flowchart of the step counting method of the present embodiment, which includes S11: collecting motion data of a sensor in a motion process, wherein the sensor is an acceleration sensor; s12: acquiring a characteristic value of the collected motion data, and calculating step-counting motion data, wherein the step-counting motion data is a three-axis synthetic acceleration square value; s13: carrying out standardization processing on the characteristic value to obtain a standardized characteristic value; s14: judging a step counting state by using a step counting model according to the standardized characteristic value; s15: filtering the step motion data in the step motion step S12, namely the three-axis synthetic acceleration square value data, by using a fast Fourier transform principle; s16: and counting steps.
The motion data in step S11 includes: acceleration value of x-axisAcceleration value of y axisz-axis acceleration valueSum of three axes to the square value of acceleration aiWherein
The feature values of the motion data in step S12 include, but are not limited to, the following 20-dimensional feature values, and the calculation formula thereof is as follows:
mean of the three-axis synthetic acceleration squared values:
mean of x-axis acceleration values meanx:
Mean of acceleration values of the y-axisy:
Mean z-axis acceleration value meanz:
variance σ of the three-axis composite acceleration squared value:
variance σ of acceleration value of x-axisx:
Variance σ of acceleration value of y-axisy:
Variance σ z of z-axis acceleration value:
maximum MAX of the three-axis composite acceleration squared value: MAX (a)i),i∈{1,2…,n} (10)
Maximum MAX of x-axis acceleration valuesx:MAXx=max(aix),i∈{1,2…,n} (11)
Maximum value MAX of acceleration value of y axisy:MAXy=max(aiy),i∈{1,2…,n} (12)
Maximum value MAX of z-axis acceleration valuez:MAXz=max(aiz),i∈{1,2…,n} (13)
Minimum MIN of the triaxial composite acceleration squared value: MIN is MIN (a)i),i∈{1,2…,n} (14)
Minimum MIN of x-axis acceleration valuesx:MINx=min(aix),i∈{1,2…,n} (15)
Minimum MIN of y-axis acceleration valuey:MINy=min(aiy),i∈{1,2…,n} (16)
Minimum value MIN of z-axis acceleration valuez:MINz=min(aiz),i∈{1,2…,n} (17)
The difference value R between the maximum value and the minimum value of the triaxial composite acceleration square value is as follows: r ═ MAX-MIN | (18)
Maximum and minimum difference R of x-axis acceleration valuesx:Rx=|MAXx-MINx| (19)
Maximum and minimum difference R of acceleration values of y axisy:Ry=|MAXy-MINy| (20)
Maximum and minimum difference R of z-axis acceleration valuesz:Rz=|MAXz-MINz| (21)
Besides the above-mentioned 20-dimensional characteristic values, the characteristic values may also include dominant frequency, energy, x-axis and z-axis correlation coefficients, interval distribution of x, y, z triaxial acceleration and composite acceleration square, and the like.
The following describes a specific flow of the step-counting algorithm according to the present invention with reference to fig. 2.
1) Firstly, initializing parameters including a step number Num, a time window T (unit is second), a sampling frequency F (unit is Hz) and a first preset threshold a, in some embodiments, the sampling frequency F may be 20Hz, 25Hz or 30Hz, the initialization of the step number Num is divided into two types, the first type is to start up to count steps, the Num is 0, the other type is to continue counting steps after starting counting steps, and the Num is the step number of the previous step.
The first preset threshold value A is obtained through grid search, the grid search refers to traversing all possible values of the first preset threshold value A, and the most accurate value of the step counting data is selected from the values as the final value of the parameter A. For example, a lot of walking data are collected, and it is known that a in these data is the number of steps actually taken by the user, at this time, it may be assumed that a is (1.5, 1, 5, 10, 15, 20, …, 100), the actual number of steps is 20000, each possible value of a is substituted into the step counting algorithm of the present embodiment, the calculated step counting number is, for example, 10000 when a is 1, 19000 when a is 5, … when a is 15, 15000 when a is 15, it may be known that the step counting number is 10000 when a is 1, the actual number of steps is 20000, the error is 10000 when a is 5, 19000 when a is 5, 1000 when a is 15, 15000 when a is 15, the error is 5000, and therefore a is 5, the error is the smallest, the calculated value is the most approximate to the actual value of steps, and when a is 5, a large number of steps should be searched for a suitable grid, in particular, the value a is not changed once it is calculated, and is used as an empirical constant, where a is 2 in this embodiment.
2) The method comprises the following steps of collecting motion data of a sensor in the motion process, wherein the motion data comprises: the acceleration value of the x axis, the acceleration value of the y axis, the acceleration value of the z axis and the three-axis synthetic acceleration square value.
The number of samples in each time window is: for example, a 10-second segment of motion data is obtained from the acceleration sensor, the set time window T is 2s, and the sampling frequency F is 50HZ, then according to the timestamp generated during data acquisition, the start time T1 and the end time T2 of the acquired motion data can be obtained, then the 10s segment of data is divided into 5 time windows without data overlapping according to the time window T, the time range of the first time window is [ T1, T1+ 2], that is, T1 ≦ T1+2, the time range of the last time window is (T2-2, T2], that is, T2-2 ≦ T2, and the number M of sampling samples in each time window is 100 ═ 2s ≦ 50 HZ.
3) And acquiring the characteristic value of the acquired motion data, namely extracting a 20-dimensional characteristic value according to the formulas (1) to (21) through an x-axis acceleration value, a y-axis acceleration value, a z-axis acceleration value and a three-axis synthesized acceleration square value.
4) The characteristic value is normalized to obtain a normalized characteristic value, and the formula of the normalization processing is specifically as follows:
wherein,representing the characteristic value data, X, after normalizationiRepresenting the characteristic value, mu, of the ith dimensioniAnd σiTo normalize the parameters, n represents the dimension of the eigenvalues.
Wherein muiAnd σiThe calculation formula is specifically as follows:
where m represents the number of samples in the training set, xi(j)Representing the ith dimension feature value of the jth sample.
In a practical algorithm, μ can be obtained in advance through a large number of sample dataiAnd σiIt can be used as a constant in equation (22).
5) Judging whether the step counting state is the step counting state, and specifically comprising the following steps:
firstly, judging a step counting state of characteristic value data subjected to standardization treatment by using a step counting model, wherein the step counting model specifically comprises the following steps:
wherein,a vector composed of normalized feature values subjected to normalization processing in step 4), T denotes a transpose of the vector, and W denotes a vector composed of coefficients.
For example, in the present embodiment, the 20-dimensional feature values within one time window calculated in step 3) are (-0.91427, -0.22424, -0.29868, -0.74205), respectively, thenCan be unfolded intoNormalized characteristic value, W, representing the nth dimensionnDenotes the nth coefficient, and n denotes the number of eigenvalues, i.e., n dimensions.
The formula for calculating the vector W of coefficients is:
where m represents the number of samples in the training set,normalized feature value, y, representing the ith sample(i)the value of the marker indicating the ith sample is generally 1 or-1, α is a regularization parameter and is 0.1, the value of W is obtained by solving through a gradient descent method, the value of W is affected by many factors such as the number of samples of a machine learning model and a training set, and the optimal values of W obtained under different conditions are different, for example, the value of W after machine learning in one embodiment is (-3.691413e-2, -8.136777e-2, …,1.968664e +00), and as the first preset threshold a, the value of W is not changed once calculated, and is applied to the formula (25) as a constant.
Then, the step counting state value is obtained according to the step counting model to judge the step counting state,
when F (X) >0.5, judging that the step counting state is in a step counting state and continuing to count the steps;
and when the F (X) is less than or equal to 0.5, judging the step counting state is not counted, returning to the step 1) to initialize the parameters, and restarting counting the steps.
6) Synthesizing a square value a of acceleration for three axes by a fast Fourier transform principleiFiltering is carried out, because the acceleration sensor can shake in a certain disorder mode in the motion process of the human body, larger noise can be introduced into the collected data, but the human body does not shake in the disorder modeThe frequency of the motion process is in a certain range, so that the frequency signals which are not in the normal motion frequency range of the human body can be filtered by adopting fast Fourier transform, for example, the frequency range of the human body when walking is 0.5-5 HZ, and the signals which are higher than 5HZ or lower than 0.5HZ are defined as useless noise, and the acquired three-axis synthetic acceleration square value a is obtained by the fast Fourier transformiConverting a signal from a time domain to a frequency domain, setting the amplitude of the signal out of the frequency range of 0.5-5 HZ to be 0, and finally converting frequency domain data into time domain data through fast Fourier inversion, namely completing the triaxial synthesis acceleration square value aiFiltering the data of (1).
7) Comparing the peak value of the step-counting movement data with the reference threshold value to count steps, specifically comprising:
firstly, judging the square value a of the three-axis synthetic accelerationiThe peak value of the data of (1) and the peak value judgment formula are as follows:
ai>ai-1and a isi>ai+1(26)
Wherein a isiFor step-counting movement data of the current moment, ai-1As step-counting movement data of the previous moment, ai+1Step counting movement data at the next moment;
then, a dynamic peak threshold value B is calculated according to the peak value, and the specific formula is as follows:
where N is the number of peaks in the time window, AiThe value of the ith peak in the time window, C is a coefficient;
and finally, counting the steps, comparing each peak value in the time window with a dynamic peak value threshold value B and a first preset threshold value A, and if the peak value is greater than A and greater than B, adding one to the step count.
The machine learning algorithm used in this embodiment is a local linear classifier, which can also be replaced by other machine learning algorithms such as random forest, decision tree, support vector base, and the like.