Step counting method and device based on three-axis accelerometer
Technical Field
The invention belongs to the technical field of wearable equipment, and particularly relates to a step counting method and device based on a three-axis accelerometer.
Background
Wearable devices are portable devices that can be worn directly on the body, or integrated into clothing or other accessories. Meanwhile, wearable devices generally use a three-axis accelerometer as a counting device to complete a step-counting function. The three-axis accelerometer of the wearable device can measure the acceleration of human body movement in three directions, namely the forward direction, the lateral direction and the vertical direction. Wherein, referring to fig. 1, fig. 1 is a sample diagram of three-axis acceleration curves obtained by walking a handheld wearable device, referring to fig. 2, and fig. 2 is a sample diagram of three-axis acceleration curves obtained by running a handheld wearable device, the three-axis acceleration curves including acceleration curves of x-axis, y-axis, and z-axis.
However, the existing step counting algorithm based on the three-axis accelerometer cannot accurately count the number of steps taken by the wearer from three curves output by the three-axis accelerometer of the wearable device. The reason for this is that in the wearable device, there are many available choices for the installation position of the triaxial accelerometer, and therefore there are also many choices for identifying the three directions of the triaxial accelerometer, and therefore in the three directions, the probability of erroneously identifying the principal direction of the triaxial accelerometer is also high, and when the principal direction of the triaxial accelerometer is erroneously identified, the erroneously counted number of steps that can be obtained consumes the time for counting the number of steps that the wearer is traveling, reduces the efficiency for counting the number of steps that the wearer is traveling, and reduces the accuracy for counting the number of steps that the wearer is traveling.
Disclosure of Invention
The embodiment of the invention aims to provide a step counting method based on a three-axis accelerometer, and aims to solve the problem that the step number of a wearer cannot be accurately counted from three curves output by the three-axis accelerometer of wearable equipment in the conventional step counting algorithm based on the three-axis accelerometer.
The embodiment of the invention is realized in such a way that a step counting method based on a three-axis accelerometer comprises the following steps:
acquiring acceleration curves of an x axis, a y axis and a z axis generated in a three-axis accelerometer in real time, acquiring the axis with the strongest regularity of the acceleration curves from the acceleration curves of the x axis, the y axis and the z axis, taking the direction of the axis with the strongest regularity as a main direction, and taking the acceleration curve of the axis with the strongest regularity as an acceleration curve of the main direction;
adopting a preset filter to filter the acceleration curve in the main direction;
selecting an unprocessed wave crest on the acceleration curve of the main direction, adding one to the counting step number when the unprocessed wave crest appears beyond a preset time threshold value of the processed wave crest and the acceleration value of the unprocessed wave crest is greater than a preset acceleration threshold value, or selecting the unprocessed wave crest on the acceleration curve of the main direction, and adding one to the counting step number when the unprocessed wave crest appears beyond the preset time threshold value of the processed wave crest and the difference value between the acceleration value of the unprocessed wave crest and the preset acceleration threshold value is less than a preset value.
Another object of an embodiment of the present invention is to provide a step-counting device based on a three-axis accelerometer, including:
the acceleration curve acquisition module is used for acquiring acceleration curves of an x axis, a y axis and a z axis which are generated in the three-axis accelerometer in real time, acquiring the axis with the strongest regularity of the acceleration curve from the acceleration curves of the x axis, the y axis and the z axis, taking the direction of the axis with the strongest regularity as a main direction, and taking the acceleration curve of the axis with the strongest regularity as an acceleration curve of the main direction;
the filtering module is used for filtering the acceleration curve in the main direction by adopting a preset filter;
and the counting step number module is used for selecting an unprocessed wave crest on the acceleration curve of the main direction, adding one to the counting step number when the unprocessed wave crest appears beyond a preset time threshold value of the processed wave crest and the acceleration value of the unprocessed wave crest is greater than a preset acceleration threshold value, or selecting the unprocessed wave crest on the acceleration curve of the main direction, and adding one to the counting step number when the unprocessed wave crest appears beyond the preset time threshold value of the processed wave crest and the difference value between the acceleration value of the unprocessed wave crest and the preset acceleration threshold value is less than a preset value.
In the embodiment of the invention, the axis with the strongest regularity of the acceleration curve is obtained, the direction of the axis with the strongest regularity is taken as the main direction, the acceleration curve of the axis with the strongest regularity is taken as the acceleration curve of the main direction, and the unprocessed peak is selected on the acceleration curve of the main direction, so that the problem that the step number of the wearer cannot be accurately counted from three curves output by a three-axis accelerometer of wearable equipment by the conventional step counting method based on the three-axis accelerometer is solved, the time for counting the step number of the wearer can be saved, and the accuracy for counting the step number of the wearer can be improved.
Drawings
FIG. 1 is a sample graph of three axis acceleration curves obtained by walking a handheld wearable device;
fig. 2 is a sample graph of three axis acceleration profiles obtained by running a handheld wearable device;
FIG. 3 is a flowchart of an implementation of a step counting method based on a three-axis accelerometer according to an embodiment of the present invention;
FIG. 4 is a flowchart of a step S301 of a three-axis accelerometer-based step counting method according to an embodiment of the present invention;
FIG. 5 is a flow chart illustrating the implementation of the preset acceleration threshold according to an embodiment of the present invention;
FIG. 6 is a flow chart illustrating an implementation of updating an acceleration threshold provided by an embodiment of the present invention;
fig. 7 is a block diagram of a step counting device based on a three-axis accelerometer according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Example one
Referring to fig. 3, fig. 3 is a flowchart of an implementation of a step counting method based on a three-axis accelerometer according to an embodiment of the present invention, which is detailed as follows:
in step S301, acceleration curves of an x axis, a y axis, and a z axis generated in real time in the three-axis accelerometer are obtained, an axis with the strongest regularity of the acceleration curves is obtained from the acceleration curves of the x axis, the y axis, and the z axis, a direction in which the axis with the strongest regularity is located is taken as a main direction, and the acceleration curve of the axis with the strongest regularity is taken as an acceleration curve of the main direction;
the axis with the strongest regularity of the acceleration curve represents the axis with the strongest periodicity of the acceleration curve.
In step S302, a preset filter is used to filter the acceleration curve in the main direction;
the center frequency and the bandwidth of the preset filter can be set by a user or default by a system.
In step S303, an unprocessed peak is selected on the acceleration curve in the main direction, and when the unprocessed peak is outside the preset time threshold of the processed peak and the acceleration value of the unprocessed peak is greater than the preset acceleration threshold, the number of the statistical steps is incremented by one, or, when the unprocessed peak is outside the preset time threshold of the processed peak and the difference between the acceleration value of the unprocessed peak and the preset acceleration threshold is smaller than the preset value, the number of the statistical steps is incremented by one. Wherein the preset time threshold is set according to the empirical value. The preset time threshold comprises a walking preset time threshold and a running time threshold. The basis for setting the preset time threshold is as follows: people generally can not walk slower than one step every two seconds, and can not exceed five steps every second when running. With the above-mentioned basis, it is preferable that the walking preset time threshold is 0.5 seconds, and the running time threshold is 0.2 seconds.
The method comprises the steps of detecting a thread which generates acceleration curves of an x axis, a y axis and a z axis in a three-axis accelerometer in real time, stopping counting steps when the acceleration curves of the x axis, the y axis and the z axis are detected to stop being generated in the three-axis accelerometer, and outputting the counted steps to a screen or a voice device of equipment where the three-axis accelerometer is located so that the counted steps are displayed on the screen of the equipment where the three-axis accelerometer is located or the counted steps are played by the voice device of the equipment where the three-axis accelerometer is located.
In the embodiment of the invention, the axis with the strongest regularity of the acceleration curve is obtained, the direction of the axis with the strongest regularity is taken as the main direction, the acceleration curve of the axis with the strongest regularity is taken as the acceleration curve of the main direction, and the unprocessed peak is selected on the acceleration curve of the main direction, so that the problem that the step number of the wearer cannot be accurately counted from three curves output by a three-axis accelerometer of wearable equipment by the conventional step counting method based on the three-axis accelerometer is solved, the time for counting the step number of the wearer can be saved, and the accuracy for counting the step number of the wearer can be improved.
Example two
Referring to fig. 4, fig. 4 is a flowchart of an implementation of step S301 of the step counting method based on a three-axis accelerometer according to the embodiment of the present invention, which is detailed as follows:
in step S401, acquiring acceleration curves of an x axis, a y axis, and a z axis generated in real time in a three-axis accelerometer, and selecting a preset number of peaks from the acceleration curves of the x axis, the y axis, and the z axis, respectively;
the preset number may be user-set or default.
In step S402, obtaining a time interval between every two peaks in the selected preset number of peaks, and generating a standard deviation of a difference value of the time interval between every two peaks as a first parameter set describing regularity of an acceleration curve, where the first parameter set includes first parameters of the x-axis, the y-axis, and the z-axis;
in step S403, sampling acceleration curves at two ends between three consecutive peaks according to a preset sampling interval in the selected preset number of peaks to generate discrete point acceleration values, acquiring the discrete point acceleration values at intervals of a preset time, and generating a standard deviation of a difference value between the discrete point acceleration values at every two intervals of the preset time as a second parameter set describing regularity of the acceleration curve of the axis, where the second parameter set includes second parameters of the x-axis, the y-axis, and the z-axis;
in step S404, generating a detection parameter set according to the first parameter set, the second parameter set, and a preset detection main direction model, where the detection parameter set includes detection parameters of the x-axis, the y-axis, and the z-axis;
in step S405, an axis with the strongest regularity of the acceleration curve is obtained in the x axis, the y axis, and the z axis according to the detection parameter set, the direction of the axis with the strongest regularity is taken as the main direction, and the acceleration curve of the axis with the strongest regularity is taken as the acceleration curve of the main direction.
In the embodiment of the invention, the input data is the acceleration value output by the three-axis accelerometer in real time, and the acceleration curve is suitable for all three-axis accelerometer Micro Electro Mechanical Systems (MEMS), so that the acceleration curve has good portability, an axis with the strongest regularity of the acceleration curve can be obtained in any three-axis accelerometer MEMS system, the direction of the axis with the strongest regularity can be taken as the main direction, and the acceleration curve of the axis with the strongest regularity can be taken as the acceleration curve of the main direction.
EXAMPLE III
The embodiment of the invention mainly describes an implementation process for establishing a detection main direction model, which is detailed as follows:
establishing a detection main direction model;
wherein,representing a proportionality coefficient, i representing a serial number, i having a value ranging from 1 to 3, α i representing the ith first parameter in the first parameter set, α1、α2、α3Respectively representing first parameters of x-axis, y-axis and z-axis, and theta i represents ith second parameter in the second parameter set1、θ2、θ3Respectively representing second parameters of x-axis, y-axis and z-axis, and Δ i representing ith detection parameter of the detection parameter set, and Δ1、Δ2、Δ3The detection parameters of the x-axis, the y-axis and the z-axis are respectively shown.
In the embodiment of the invention, the acceleration curve of the axis with the strongest regularity can be conveniently used as the acceleration curve of the main direction in the follow-up process by establishing the detection main direction model, and then the unprocessed wave crest is selected on the acceleration curve of the main direction to complete the step number statistics.
Example four
Referring to fig. 5, fig. 5 is a flowchart illustrating an implementation of presetting an acceleration threshold according to an embodiment of the present invention, which is detailed as follows:
in step S501, in the acceleration curve in the main direction, acceleration values of a preset number of peaks are extracted;
in step S502, a median of the acceleration values of the preset number of peaks is selected as an acceleration threshold.
Wherein, the acceleration value of the crest of the quantity of predetermineeing is drawed, specifically is:
and extracting the wave crests with preset number according to the sequence of wave crest generation in the acceleration curve in the main direction.
Optionally, as another implementation manner of the embodiment of the present invention, the preset acceleration threshold may also be an average value of acceleration values of a preset number of peaks as the acceleration threshold.
In the embodiment of the present invention, since the acceleration threshold is established on the basis of the acceleration curve according to the principal direction, the acceleration threshold has a higher accuracy.
EXAMPLE five
Referring to fig. 6, fig. 6 is a flowchart of an implementation of updating an acceleration threshold according to an embodiment of the present invention, which is detailed as follows:
in step S601, subtracting the acceleration value of the processed peak from the acceleration threshold in real time to generate an acceleration difference;
the acceleration values of the processed wave crests are sequenced according to the generation time of the acceleration values of the processed wave crests and the sequence of the generation time, and the acceleration value of the processed wave crest with the generation time closest to the existing time is extracted.
And subtracting the acceleration value of the processed wave crest with the extracted generation time closest to the existing time from the acceleration threshold value in real time to generate an acceleration difference value.
In step S602, it is determined whether the absolute value of the acceleration difference is greater than a preset determination threshold, if so, the acceleration value of the processed peak is added to the acceleration threshold to generate an added value, and the acceleration threshold is updated to half of the added value, otherwise, no processing is performed.
The judgment threshold is represented by a parameter C, which can be generated according to the following formula, which is detailed as follows:
wherein, XmaxFor maximum acceleration value, X, in the sampled peaksminIs the smallest acceleration value among the sampled peaks.
Wherein, the acceleration threshold is updated to be half of the added value, and the specific implementation flow is as follows:
Atas a raw acceleration threshold, At+1For an updated acceleration threshold, B represents the acceleration value that generated the processed peak whose time was closest to the existing time.
Wherein, whether the absolute value of the acceleration difference is larger than a preset judgment threshold value C is judged, namely, the judgment means that in the waveform, whether B is A or nottAbove or below when AtWhen the distance between the acceleration threshold value A and the acceleration threshold value B is larger than the judgment threshold value C, the acceleration threshold value is required to be updated to obtain an updated acceleration threshold value At+1。
In the embodiment of the invention, the quick response can be made to the input acceleration curve, and the acceleration threshold value is adjusted in real time according to the change of the movement mode of the wearer, so that the counting accuracy is ensured; secondly, input data of the algorithm is an acceleration value output by the triaxial accelerometer in real time, and the algorithm is suitable for all triaxial accelerometer MEMS systems and has good portability.
EXAMPLE six
This embodiment mainly describes the processing flow of the acceleration curve of the present invention when a person walks, and for convenience of description, fig. 1 and fig. 3 are taken as examples, and detailed descriptions are as follows:
(1) and calculating the regularity of an x axis, a y axis and a z axis. Firstly, the first 10 highest points of the axis are taken, and the standard deviation of the difference value of the time intervals between every two points is calculated to be used as a first parameter for evaluating the periodicity of the axis. Secondly, analog-to-digital conversion is respectively carried out on curves at two ends between the three highest points, the sampling frequency can be set by a system or can be set by a user, the sampling frequency includes but is not limited to 2400Hz, 4800Hz, 9600Hz, 22100Hz, 44200Hz and 48000Hz, and the standard deviation of the numerical value position difference values of the discrete points at corresponding positions (equal relative time) is calculated to serve as a second parameter for evaluating the periodicity of the axis.
(2) The principal direction is calculated. By adopting the main direction detection model and comparing the x axis, the y axis and the z axis, the regularity of the acceleration of the person in the x axis direction is strong when the person walks, and therefore the x axis is taken as the main direction of counting.
(3) And (6) filtering. And taking an acceleration curve of an x axis, and filtering the acceleration curve by using a wiener filter to remove the influence of clutter on the algorithm.
(4) An acceleration threshold is calculated. And taking the acceleration values of the first 10 wave crests, and calculating the acceleration threshold value to be about 0.85 g.
(5) And (6) counting. Taking the unprocessed peak on the curve, if this peak occurs 0.2 seconds outside the processed peak and its value is greater than the acceleration threshold, the statistical step count is incremented by one.
(6) The acceleration threshold is updated. And (4) if the difference value between the wave peak value processed in the step (4) and the acceleration threshold value is larger than the acceleration threshold value, updating the acceleration threshold value to be half of the sum of the wave peak value and the acceleration threshold value, and otherwise, not performing any processing.
(7) And (5) repeating the steps (4) to (5) to obtain the statistical step number of 15 steps.
EXAMPLE seven
The present embodiment mainly describes the processing flow of the acceleration curve of the present invention when a person walks, which is convenient for explanation, and takes fig. 2 and fig. 4 as an example, which is detailed as follows:
(1) and calculating the regularity of an x axis, a y axis and a z axis. Firstly, the first 10 highest points of the axis are taken, and the standard deviation of the difference value of the time intervals between every two points is calculated to be used as a first parameter for evaluating the periodicity of the axis. Secondly, analog-to-digital conversion is respectively carried out on curves at two ends between the three highest points, the sampling frequency can be set by a system or can be set by a user, the sampling frequency includes but is not limited to 2400Hz, 4800Hz, 9600Hz, 22100Hz, 44200Hz and 48000Hz, and the standard deviation of the numerical value position difference values of the discrete points at corresponding positions (equal relative time) is calculated to serve as a second parameter for evaluating the periodicity of the axis.
(2) The principal direction is calculated. And taking the direction of the y axis with the strongest regularity as the main direction of counting by comparison.
(3) And (6) filtering. And taking an acceleration curve of a y axis, and filtering the acceleration curve by using a wiener filter to remove the influence of clutter on the algorithm.
(4) An acceleration threshold is calculated. The acceleration values of the first 10 peaks are taken as sample values, and the acceleration threshold is calculated to be about 0.72 g.
(5) And (6) counting. Taking the unprocessed peak on the curve, if this peak occurs outside the processed peak for 0.2 seconds and its value is greater than the acceleration threshold or its difference from the acceleration threshold is less than 0.1g, the statistical step number is incremented by one.
(6) The acceleration threshold is updated. And (4) if the difference value between the wave peak value processed in the step (4) and the acceleration threshold value is larger than the acceleration threshold value, updating the acceleration threshold value to be half of the sum of the wave peak value and the acceleration threshold value, and otherwise, not performing any processing.
(7) And (5) repeating the step (4) to the step (5) to obtain the statistical step number of 25 steps.
Example eight
Fig. 7 is a block diagram of a step-counting device based on a three-axis accelerometer according to an embodiment of the present invention, where the device may be operated in a terminal. For convenience of explanation, only the portions related to the present embodiment are shown.
Referring to fig. 7, the three-axis accelerometer-based step counting apparatus includes:
the acceleration curve acquiring module 71 is configured to acquire acceleration curves of an x axis, a y axis and a z axis generated in the three-axis accelerometer in real time, acquire an axis with the strongest regularity of the acceleration curve from the acceleration curves of the x axis, the y axis and the z axis, use the direction of the axis with the strongest regularity as a main direction, and use the acceleration curve of the axis with the strongest regularity as an acceleration curve of the main direction;
the filtering module 72 is configured to filter the acceleration curve in the main direction by using a preset filter;
the step number counting module 73 is configured to select an unprocessed peak on the acceleration curve in the main direction, add one to the counting step number when the unprocessed peak is outside a preset time threshold of the processed peak and the acceleration value of the unprocessed peak is greater than a preset acceleration threshold, or add one to the counting step number when the unprocessed peak is outside the preset time threshold of the processed peak and the difference between the acceleration value of the unprocessed peak and the preset acceleration threshold is smaller than a preset value.
In a first implementation manner of this embodiment, in the step counting device based on a three-axis accelerometer, the acceleration curve obtaining module includes:
the wave crest selecting unit is used for acquiring acceleration curves of an x axis, a y axis and a z axis generated in the three-axis accelerometer in real time, and selecting a preset number of wave crests from the acceleration curves of the x axis, the y axis and the z axis respectively;
the first parameter set generating unit is used for acquiring the time interval between every two wave crests from the selected preset number of wave crests, and generating the standard deviation of the difference value of the time interval between every two wave crests as a first parameter set for describing the regularity of the acceleration curve, wherein the first parameter set comprises first parameters of the x axis, the y axis and the z axis;
the second parameter set generating unit is used for sampling acceleration curves at two ends between three continuous wave crests in the selected wave crests in the preset number according to a preset sampling interval to generate discrete point acceleration values, acquiring the discrete point acceleration values at intervals of preset time, and generating a standard difference of a difference value of the discrete point acceleration values at every two intervals of preset time as a second parameter set for describing the regularity of the acceleration curves of the shaft, wherein the second parameter set comprises second parameters of the x-axis, the y-axis and the z-axis;
a detection parameter set detection unit, configured to generate a detection parameter set according to the first parameter set, the second parameter set, and a preset detection main direction model, where the detection parameter set includes detection parameters of the x-axis, the y-axis, and the z-axis;
and the acceleration curve acquisition unit is used for acquiring the axis with the strongest regularity of the acceleration curve from the x axis, the y axis and the z axis according to the detection parameter set, taking the direction of the axis with the strongest regularity as the main direction, and taking the acceleration curve of the axis with the strongest regularity as the acceleration curve of the main direction.
In a second implementation manner of this embodiment, the step-counting device based on a three-axis accelerometer further includes:
the establishing module is used for establishing a detection main direction model;
wherein,representing a proportionality coefficient, i representing a serial number, i having a value ranging from 1 to 3, α i representing the ith first parameter in the first parameter set, α1、α2、α3Respectively representing first parameters of x-axis, y-axis and z-axis, and theta i represents ith second parameter in the second parameter set1、θ2、θ3Respectively representing second parameters of x-axis, y-axis and z-axis, and Δ i representing ith detection parameter of the detection parameter set, and Δ1、Δ2、Δ3The detection parameters of the x-axis, the y-axis and the z-axis are respectively shown.
In a third implementation manner of this embodiment, the step-counting device based on a three-axis accelerometer further includes:
the acceleration value extraction module is used for extracting the acceleration values of the wave crests in a preset number from the acceleration curve in the main direction;
and the acceleration threshold generating module is used for extracting the median of the acceleration values of the wave crests of the preset number as the acceleration threshold according to the preset number and the extracted acceleration values.
In a fourth implementation manner of this embodiment, the step-counting device based on a three-axis accelerometer further includes:
the acceleration difference generating module is used for subtracting the acceleration value of the processed wave crest from the acceleration threshold value in real time to generate an acceleration difference;
and the acceleration threshold updating module is used for judging whether the absolute value of the acceleration difference is greater than a preset judgment threshold, if so, adding the acceleration value of the processed wave peak and the acceleration threshold to generate an added value, and updating the acceleration threshold to be half of the added value, otherwise, not performing any processing.
The apparatus provided in the embodiment of the present invention may be applied to the corresponding method embodiments, and for details, reference is made to the description of the embodiments above, and details are not repeated here.
Through the above description of the embodiments, those skilled in the art will clearly understand that the present invention can be implemented by software plus necessary general hardware. The program may be stored in a readable storage medium, such as a random access memory, a flash memory, a read only memory, a programmable read only memory, an electrically erasable programmable memory, a register, and the like. The storage medium is located in a memory, and a processor reads information in the memory and performs the method according to the embodiments of the present invention in combination with hardware thereof.
The above description is only for the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.