Gradient resolving algorithm and system, electronic equipment and storage medium

By using a sliding window buffer and filters to process elevation and mileage data, the problem of poor real-time performance in slope calculation in traditional algorithms is solved, achieving more accurate and faster slope calculation.

CN121783090APending Publication Date: 2026-04-03QINGDAO MAGENE INTELLIGENCE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-24
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

Traditional algorithms have poor real-time performance when calculating slope, especially during low-speed climbing, where the denominator is often small, resulting in gross errors. Furthermore, low-end hardware is significantly affected by noise.

Method used

A sliding window is used to cache elevation and mileage data. The slope value to be determined is obtained by calculating the elevation gradient and mileage gradient. Outliers are filtered out by conditional judgment and filter, and the accurate slope value is output.

Benefits of technology

It improves the real-time performance and accuracy of slope calculation, shortens the calculation delay, eliminates abnormal data, and reduces the impact of noise.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121783090A_ABST
    Figure CN121783090A_ABST
Patent Text Reader

Abstract

The invention discloses a slope calculation algorithm and system, electronic equipment and a storage medium, and the method comprises the steps: collecting elevation data and mileage data in real time in a riding process; respectively carrying out sliding caching on the elevation data and the mileage data by utilizing a sliding window; calculating an elevation gradient according to the cached elevation data; calculating a mileage gradient according to the cached mileage data; obtaining an undetermined slope value based on the elevation gradient and the mileage gradient; if the absolute value of the undetermined slope value is smaller than or equal to the slope threshold value, the absolute value of the difference value between the undetermined slope value and the cache slope value at the previous moment is smaller than or equal to the slope difference threshold value, and the mileage gradient is larger than or equal to the speed threshold value, the undetermined slope value serves as the current slope value, and otherwise, the cache slope value at the previous moment serves as the current slope value; and caching the current slope value, filtering the current slope value by using a filter, and outputting the filtered current slope value. According to the method, the time delay for resolving the gradient is shortened while the resolving precision is guaranteed, and the technical problem of poor real-time performance of gradient resolving in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of motion analysis technology, specifically, it relates to a slope calculation algorithm and system, electronic equipment, and storage medium. Background Technology

[0002] Gradient is an important indicator in outdoor cycling, and the real-time elevation and mileage fed back by the bike computer are important reference data for calculating the real-time gradient.

[0003] Traditional algorithms output the slope as the ratio of elevation change to mileage change over a period of time. In general, to cope with the noise in the data generated by low-end hardware, such algorithms need to cache data for 5 to 10 seconds. This will affect the real-time performance of slope calculation and may result in gross errors due to small denominator values ​​during low-speed climbing. Summary of the Invention

[0004] This invention provides a slope calculation algorithm, which solves the technical problem of poor real-time performance in existing slope calculation technologies.

[0005] To achieve the above-mentioned technical objectives, the present invention adopts the following technical solution: Slope calculation algorithms include: S1. During the cycling process, real-time elevation and mileage data are collected; S2. Use a sliding window to perform sliding cache for elevation data and mileage data respectively; Calculate the elevation gradient based on the cached elevation data; Calculate the mileage gradient based on the cached mileage data; S3. Based on the calculated elevation gradient and mileage gradient, the slope value to be determined is obtained; S4. Determine whether the following conditions are met simultaneously: Condition 1: The absolute value of the slope to be determined is less than or equal to the slope threshold. Condition 2: The absolute value of the difference between the undetermined slope value and the buffered slope value at the previous moment is less than or equal to the slope difference threshold. Condition 3: Mileage gradient ≥ speed threshold; If so, the undetermined slope value is used as the current slope value, and the current slope value is cached; If not, then use the cached slope value from the previous moment as the current slope value, and cache the current slope value. The current slope value is filtered using a filter before being output.

[0006] In some embodiments of this application, the following steps are included before performing step S4: Determine whether the undetermined slope value has been calculated for the first time; If so, the undetermined slope value is used as the current slope value, and the current slope value is cached; If not, proceed to step S4.

[0007] In some embodiments of this application, before filtering the current slope value using a filter, the following steps are also included: Determine if this is the first time the current slope value has been obtained; If so, output the current slope value directly; If not, the current slope value is filtered using a filter before being output.

[0008] In some embodiments of this application, the filter is a Butterworth filter.

[0009] In some embodiments of this application, the slope value to be determined is obtained based on the calculated elevation gradient and mileage gradient, and the calculation formula is as follows: slope_temp=h_drag / (d_drag+a); Where slope_temp is the slope value to be determined; h_drag is the elevation gradient; d_drag is the mileage gradient; and a is a positive number lower than the preset low value.

[0010] In some embodiments of this application, the elevation gradient is calculated using the least squares method based on the cached elevation data.

[0011] In some embodiments of this application, the elevation data and mileage data are collected by a codebook.

[0012] The slope calculation system includes: The data acquisition module is used to collect elevation and mileage data in real time during cycling. The feature extraction module is used to: perform sliding caching of elevation data and mileage data using a sliding window; calculate the elevation gradient based on the cached elevation data; and calculate the mileage gradient based on the cached mileage data. The slope calculation module is used to obtain the slope value to be determined based on the calculated elevation gradient and mileage gradient. The conditional judgment module is used to determine whether the following conditions are met simultaneously: Condition 1: The absolute value of the slope to be determined is less than or equal to the slope threshold. Condition 2: The absolute value of the difference between the undetermined slope value and the buffered slope value at the previous moment is less than or equal to the slope difference threshold. Condition 3: Mileage gradient ≥ speed threshold; If so, the undetermined slope value is used as the current slope value, and the current slope value is cached; If not, then use the cached slope value from the previous moment as the current slope value, and cache the current slope value. The filtering module is used to filter the current slope value and then output it.

[0013] Electronic devices, including: Memory is used to store instructions executed by the computer; A processor is configured to execute computer execution instructions stored in the memory to implement the slope calculation algorithm.

[0014] A storage medium storing computer execution instructions, which, when executed by a processor, are used to implement the slope calculation algorithm.

[0015] Compared with the prior art, the advantages and positive effects of the present invention are as follows: The slope calculation algorithm and system, electronic device, and storage medium of the present invention collect elevation data and mileage data in real time during cycling; use a sliding window to perform sliding caching of elevation data and mileage data respectively; calculate the elevation gradient based on the cached elevation data; calculate the mileage gradient based on the cached mileage data; obtain the undetermined slope value based on the elevation gradient and mileage gradient; if the following three conditions are met simultaneously: the absolute value of the undetermined slope value ≤ slope threshold, the absolute value of the difference between the undetermined slope value and the cached slope value at the previous moment ≤ slope difference threshold, and the mileage gradient ≥ speed threshold, then the undetermined slope value is used as the current slope value; otherwise, it indicates that the undetermined slope value is abnormal and needs to be discarded, and the cached slope value at the previous moment is used as the current slope value; cache the current slope value, and output it after filtering the current slope value using a filter. Therefore, the slope calculation algorithm and system, electronic device, and storage medium of the present invention eliminate abnormal undetermined slope values ​​through three conditions, ensuring the accuracy of the data. Moreover, by using a filter to remove noise from the current slope value, the calculation accuracy is guaranteed while greatly shortening the calculation delay and improving real-time performance, thus solving the technical problem of poor real-time performance of slope calculation in the prior art.

[0016] Other features and advantages of the present invention will become clearer after reading the detailed embodiments of the invention in conjunction with the accompanying drawings. Attached Figure Description

[0017] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 This is a flowchart of an embodiment of the slope calculation algorithm proposed in this invention; Figure 2 This is a flowchart of another embodiment of the slope calculation algorithm proposed in this invention; Figure 3 This is a flowchart of another embodiment of the slope calculation algorithm proposed in this invention; Figure 4 It is a system interaction diagram; Figure 5 This is a comparison chart of the output results; Figure 6 This is a comparison chart of the output results; Figure 7 This is a comparison chart of the output results; Figure 8 This is a time delay comparison chart; Figure 9 This is a structural block diagram of an embodiment of the slope calculation system proposed in this invention. Detailed Implementation

[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0020] In the description of this application, it should be understood that the terms "center", "upper", "lower", "front", "rear", "top", "bottom", "inner", "outer", etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application.

[0021] In the description of this application, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this application, unless otherwise stated, "multiple" means two or more.

[0022] In the description of this application, it should be noted that, unless otherwise expressly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection between two components. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances. Example 1

[0023] The slope calculation algorithm in this embodiment mainly includes the following steps, see below. Figure 1 As shown.

[0024] Step S1: During the cycling process, collect elevation and mileage data in real time.

[0025] In some embodiments of this application, elevation and mileage data are collected by a codebook, making data acquisition convenient.

[0026] Step S2: Use a sliding window to perform sliding caching on the elevation data and mileage data respectively.

[0027] The elevation gradient h_drag is calculated based on the cached elevation data.

[0028] The mileage gradient d_drag is calculated based on the cached mileage data.

[0029] In some embodiments of this application, the elevation gradient h_drag is calculated using the least squares method based on the cached elevation data. The least squares method has good noise resistance and can calculate a relatively accurate elevation gradient h_drag.

[0030] Step S3: Based on the calculated elevation gradient h_drag and mileage gradient d_drag, obtain the slope value slope_temp to be determined.

[0031] In some embodiments of this application, the formula for calculating the slope value slope_temp is as follows: slope_temp=h_drag / (d_drag+a); Where slope_temp is the slope value to be determined; h_drag is the elevation gradient; d_drag is the mileage gradient; and a is a positive number lower than the preset low value.

[0032] The 'a' in the denominator is a very small positive value added to the denominator to prevent it from being zero. For example, 'a' can be set to 0.001.

[0033] The above formula can accurately calculate the slope value to be determined, and can avoid calculation errors caused by a denominator of 0, and avoid gross errors caused by a small denominator value.

[0034] Step S4: Determine whether the following three conditions are met simultaneously.

[0035] Condition 1: The absolute value of the slope to be determined is less than or equal to the slope threshold_slope; Condition 2: The absolute value of the difference between the undetermined slope value and the cached slope value at the previous moment is less than or equal to the slope difference threshold delta_slope; Condition 3: Mileage gradient d_drag ≥ velocity threshold_v; The slope threshold (threshold_slope) is used to filter out slopes with abnormally large values. If the absolute value of the slope value (slope_temp) is greater than the slope threshold (threshold_slope), it means that the slope value (slope_temp) is too large and needs to be discarded.

[0036] `delta_slope` is the threshold for the nearest neighbor slope difference. Since the slope of a typical road doesn't change rapidly, although the slopes at adjacent moments are relatively independent, the difference between them isn't particularly large. Therefore, the slope at the previous moment can be used to constrain the numerical range of the current moment's slope. If the absolute value of the difference between the undetermined slope value `slope_temp` and the cached slope value from the previous moment (i.e., the previously cached slope value) is greater than the slope difference threshold `delta_slope`, it indicates that the undetermined slope value `slope_temp` is abnormal and needs to be discarded.

[0037] The speed threshold `threshold_v` is used to identify the slope when the speed is 0. If the mileage gradient `d_drag` is less than the speed threshold `threshold_v`, it indicates that the speed is too low, which in turn indicates that the slope value `slope_temp` is abnormal and should be discarded.

[0038] If all three conditions are met, it means that the slope value slope_temp is normal. Then, proceed to step S5: use the slope value slope_temp as the current slope value slope and cache the current slope value.

[0039] If none of the three conditions are met at the same time, it indicates that the slope value slope_temp is abnormal. Then, proceed to step S6: take the cached slope value from the previous moment (i.e., the previously cached slope value) as the current slope value slope, and cache the current slope value.

[0040] The cached slope value is used to determine condition two in the next iteration.

[0041] Step S7: Filter the current slope value using a filter and then output the result.

[0042] The current slope value is filtered using a filter to remove noise and output a highly accurate slope value.

[0043] The slope calculation algorithm in this embodiment collects elevation and mileage data in real time during cycling; it uses a sliding window to cache the elevation and mileage data respectively; it calculates the elevation gradient h_drag based on the cached elevation data; it calculates the mileage gradient d_drag based on the cached mileage data; based on the elevation gradient h_drag and the mileage gradient d_drag, it obtains the undetermined slope value; if the following three conditions are met simultaneously: the absolute value of the undetermined slope value ≤ slope threshold, the absolute value of the difference between the undetermined slope value and the cached slope value at the previous moment ≤ slope difference threshold, and the mileage gradient d_drag ≥ speed threshold, then the undetermined slope value is used as the current slope value; otherwise, it indicates that the undetermined slope value is abnormal and needs to be discarded, and the cached slope value at the previous moment is used as the current slope value; the current slope value is cached, and a filter is used to filter the current slope value before outputting it. Therefore, the slope calculation algorithm in this embodiment eliminates abnormal undetermined slope values ​​through three conditions, ensuring the accuracy of the data. Moreover, by using a filter to remove noise from the current slope value, it greatly shortens the calculation delay while ensuring the calculation accuracy, improves real-time performance, and solves the technical problem of poor real-time performance of slope calculation in the prior art.

[0044] In some embodiments of this application, the following steps are included before performing step S4, see below. Figure 2 As shown.

[0045] Step S4-1: Determine whether the undetermined slope value has been calculated for the first time.

[0046] If so, proceed to step S4-2: use the undetermined slope value as the current slope value and cache the current slope value.

[0047] If not, proceed to step S4.

[0048] By designing steps S4-1 to S4-2, if the undetermined slope value is calculated for the first time, there is no need to determine whether the above three conditions are met simultaneously. The undetermined slope value is directly used as the current slope value, and the current slope value is cached to save calculation time and improve real-time performance.

[0049] In some embodiments of this application, before filtering the current slope value using a filter, the following steps are further included, see [link to relevant documentation]. Figure 2 As shown.

[0050] Step S7-1: Determine whether this is the first time the current slope value has been obtained.

[0051] If so, proceed to step S8: directly output the current slope value.

[0052] If not, proceed to step S7: Filter the current slope value using a filter and then output the result.

[0053] By designing the above steps, if the current slope value is obtained for the first time, there is no need for filtering; the current slope value can be directly output to save calculation time and improve real-time performance.

[0054] In some embodiments of this application, the filter is a Butterworth filter, which can effectively filter out noise in the current slope value.

[0055] The elevation and mileage data collected by low-end hardware contain a lot of noise, which greatly reduces the accuracy of slope calculation. Considering that the noise in the directly acquired elevation and mileage data is mainly Gaussian white noise, the frequency of which is usually greater than the rate of slope change; after being activated by the slope calculation function (i.e., the formula for calculating the undetermined slope value), the generated noise still has high-frequency characteristics.

[0056] Based on this situation, and considering that the slope change rate of most road surfaces is much lower than the aforementioned noise frequency, this application adopts the Butterworth filtering framework and designs a filter suitable for the road surface slope change rate. This filter can filter out high-frequency noise in the calculation results from the sensor (codebook) while retaining the road surface slope information.

[0057] In some embodiments of this application, in order to improve the filtering effect, if the input sequence in the filter is not filled, then 0 is used to fill the input sequence; if the output sequence in the filter is not filled, then the current slope value is used to fill the output sequence.

[0058] Below, in conjunction with Figure 3 This section explains the specific steps of the slope calculation algorithm.

[0059] The input data for this application is elevation, mileage, or speed data. The speedometer serves as both a data input device and a processing device. See [link to relevant documentation]. Figure 4 As shown.

[0060] Assume the sliding window has a length of 3 seconds and a sliding step size of 1 second.

[0061] Step (1) Feature extraction and elevation gradient calculation, mileage gradient calculation.

[0062] During the ride, elevation and mileage data are acquired in real time and entered into sliding buffer windows, denoted as h_batch and d_batch respectively. The elevation change gradient is calculated using the least squares method based on the cached elevation data. The mileage change rate is represented by the average mileage difference or average speed.

[0063] The elevation gradient is calculated using elevation data, and the formula is as follows: ; Where h_drag represents the elevation gradient, and the user's vertical speed is measured in m / s; t(i) represents the time epoch at time i, in seconds; i is the counting point of the sliding window, i = 1~3.

[0064] h_batch(i) represents the elevation data at time i.

[0065] The mileage gradient is calculated using mileage data, and the formula is as follows: ; Where d_drag represents the mileage gradient; d_batch(i) represents the mileage data at time i; d_batch(i-1) represents the mileage data at time i-1.

[0066] Step (2) Slope calculation.

[0067] After calculating the elevation gradient h_drag and the mileage gradient d_drag, the slope value to be determined is calculated using these two parameters: slope_temp = h_drag / (d_drag + a).

[0068] slope_temp is the slope value to be determined, not the final slope output value, and further processing is required.

[0069] Determine whether the following three conditions are met simultaneously: Condition 1: |slope_temp|≤threshold_slope; Condition 2: |slope_temp - slope0| ≤ delta_slope; Condition 3: d_drag ≥ threshold_v; If all three conditions above are met, then the current slope value is slope_temp. If none of the above three conditions are met simultaneously, then the current slope value is slope = slope0.

[0070] Where slope_temp is the slope value to be determined, and threshold_slope is the slope threshold; slope0 is the cached slope value from the previous moment (i.e., the slope value cached last time); delta_slope is the slope difference threshold; d_drag is the mileage gradient; and threshold_v is the speed threshold.

[0071] Step (3) Filtering and noise reduction.

[0072] If it is the first iteration, that is, the first time the current slope value is calculated, then there is no need for filtering, and the current slope value is directly output.

[0073] If it is not the first iteration, the current slope value is filtered and then output.

[0074] After obtaining the current slope value, it is input into the filter. If the output sequence of the filter is not full, the current slope value is added to the output sequence before filtering. If the input sequence of the filter is not full, it is filled with 0s before the operation. The operation results are as follows: ; Where n represents the sliding window length of the filter, the input buffer window length of the filter is n, and the output buffer window length of the filter is n-1; b is the sequence of input parameter coefficients, where b1, b2, ..., b n This is a preset constant; 'a' represents the output coefficient sequence, where a1, a2, ..., a... n-1 This is a preset constant; slope1、……、slope n-1 slope n These represent the 1st, ..., (n-1st), and nth slope values ​​of the filter's input buffer window, respectively; where slope1, ..., slope2 are the slope values ​​of the filter's input buffer window. n-1 The slope is the historical slope value. n The latest slope value is the input, which is the current slope value obtained in step (2).

[0075] output1, ..., output n-1 represents the 1st, ..., n-1st filtered output values ​​of the filter's output buffer window; represents the filter's historical output values.

[0076] output n The current output value of the filter is calculated based on n input values ​​and n-1 historical output values.

[0077] A comparison of the slope calculation algorithm in this application with the output results of existing technologies can be found in [link to relevant documentation]. Figures 5-7 As shown.

[0078] For a comparison of the time delay between the slope calculation algorithm in this application and existing technologies, please refer to [link / reference needed]. Figure 8 As shown.

[0079] This application presents a low-hardware-requirement algorithm for calculating the gradient of a cycling computer, which falls under the fields of intelligent cycling and sports health.

[0080] This application designs a short-time buffered code table slope calculation algorithm that can calculate the slope using up to 3 seconds of elevation and mileage data. A filter suitable for code table data is also designed to remove noise introduced by the elevation and mileage data. While maintaining calculation accuracy, the algorithm significantly reduces calculation latency and does not require additional high-precision hardware support.

[0081] The biggest advantage of this application is that it can greatly reduce the latency of low-spec hardware in calculating the slope. Example 2

[0082] Based on the slope calculation algorithm in Embodiment 1 above, Embodiment 2 proposes a slope calculation system, including a data acquisition module, a feature extraction module, a slope calculation module, a condition judgment module, a filtering module, etc. (See [link to documentation]). Figure 9 As shown.

[0083] The data acquisition module is used to collect elevation and mileage data in real time during cycling.

[0084] The feature extraction module is used to: perform sliding caching of elevation data and mileage data using a sliding window; calculate the elevation gradient based on the cached elevation data; and calculate the mileage gradient based on the cached mileage data.

[0085] The slope calculation module is used to obtain the slope value to be determined based on the calculated elevation gradient and mileage gradient.

[0086] The conditional judgment module is used to determine whether the following conditions are met simultaneously: Condition 1: The absolute value of the slope to be determined is less than or equal to the slope threshold. Condition 2: The absolute value of the difference between the undetermined slope value and the buffered slope value at the previous moment is less than or equal to the slope difference threshold. Condition 3: Mileage gradient ≥ speed threshold; If so, the undetermined slope value is used as the current slope value, and the current slope value is cached; If not, the cached slope value from the previous moment is used as the current slope value, and the current slope value is cached.

[0087] The filtering module is used to filter the current slope value and then output it.

[0088] The specific working process of the slope calculation system has been detailed in the slope calculation algorithm above, and will not be repeated here.

[0089] The slope calculation system in this embodiment collects elevation and mileage data in real time during cycling; it uses a sliding window to cache the elevation and mileage data respectively; it calculates the elevation gradient h_drag based on the cached elevation data; it calculates the mileage gradient d_drag based on the cached mileage data; based on the elevation gradient h_drag and the mileage gradient d_drag, it obtains the undetermined slope value; if the following three conditions are met simultaneously: the absolute value of the undetermined slope value ≤ slope threshold, the absolute value of the difference between the undetermined slope value and the cached slope value at the previous moment ≤ slope difference threshold, and the mileage gradient d_drag ≥ speed threshold, then the undetermined slope value is used as the current slope value; otherwise, it indicates that the undetermined slope value is abnormal and needs to be discarded, and the cached slope value at the previous moment is used as the current slope value; the current slope value is cached, and a filter is used to filter the current slope value before outputting it. Therefore, the slope calculation system in this embodiment eliminates abnormal undetermined slope values ​​through three conditions, ensuring the accuracy of the data. Moreover, by using a filter to remove noise from the current slope value, it greatly shortens the calculation delay while ensuring the calculation accuracy, improves real-time performance, and solves the technical problem of poor real-time performance of slope calculation in the prior art. Example 3

[0090] Based on the slope calculation algorithm in Embodiment 1 above, Embodiment 3 proposes an electronic device, including a memory and a processor.

[0091] Memory is used to store instructions executed by the computer; The processor is used to execute computer execution instructions stored in memory to implement the slope calculation algorithm described in Embodiment 1. Example 4

[0092] Based on the slope calculation algorithm in Embodiment 1 above, this Embodiment 4 proposes a storage medium.

[0093] The storage medium stores computer execution instructions, which, when executed by the processor, are used to implement the slope calculation algorithm described in Embodiment 1.

[0094] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions claimed by the present invention.

Claims

1. A slope calculation algorithm, characterized in that: include: S1. During the cycling process, real-time elevation and mileage data are collected; S2. Use a sliding window to perform sliding cache for elevation data and mileage data respectively; Calculate the elevation gradient based on the cached elevation data; Calculate the mileage gradient based on the cached mileage data; S3. Based on the calculated elevation gradient and mileage gradient, the slope value to be determined is obtained; S4. Determine whether the following conditions are met simultaneously: Condition 1: The absolute value of the slope to be determined is less than or equal to the slope threshold. Condition 2: The absolute value of the difference between the undetermined slope value and the buffered slope value at the previous moment is less than or equal to the slope difference threshold. Condition 3: Mileage gradient ≥ speed threshold; If so, the undetermined slope value is used as the current slope value, and the current slope value is cached; If not, then use the cached slope value from the previous moment as the current slope value, and cache the current slope value. The current slope value is filtered using a filter before being output.

2. The slope calculation algorithm according to claim 1, characterized in that: Before performing step S4, the following steps are also included: Determine whether the undetermined slope value has been calculated for the first time; If so, the undetermined slope value is used as the current slope value, and the current slope value is cached; If not, proceed to step S4.

3. The slope calculation algorithm according to claim 1, characterized in that: Before filtering the current slope value using a filter, the following steps are also included: Determine if this is the first time the current slope value has been obtained; If so, output the current slope value directly; If not, the current slope value is filtered using a filter before being output.

4. The slope calculation algorithm according to claim 1, characterized in that: The filter is a Butterworth filter.

5. The slope calculation algorithm according to claim 1, characterized in that: Based on the calculated elevation gradient and mileage gradient, the undetermined slope value is obtained, and the calculation formula is as follows: slope_temp=h_drag / (d_drag+a); Where slope_temp is the slope value to be determined; h_drag is the elevation gradient; d_drag is the mileage gradient; and a is a positive number lower than the preset low value.

6. The slope calculation algorithm according to claim 1, characterized in that: The elevation gradient is calculated using the least squares method based on the cached elevation data.

7. The slope calculation algorithm according to any one of claims 1 to 6, characterized in that: The elevation and mileage data are collected by a codebook.

8. A slope calculation system, characterized in that: include: The data acquisition module is used to collect elevation and mileage data in real time during cycling. The feature extraction module is used to: perform sliding caching of elevation data and mileage data using a sliding window; calculate the elevation gradient based on the cached elevation data; and calculate the mileage gradient based on the cached mileage data. The slope calculation module is used to obtain the slope value to be determined based on the calculated elevation gradient and mileage gradient. The conditional judgment module is used to determine whether the following conditions are met simultaneously: Condition 1: The absolute value of the slope to be determined is less than or equal to the slope threshold. Condition 2: The absolute value of the difference between the undetermined slope value and the buffered slope value at the previous moment is less than or equal to the slope difference threshold. Condition 3: Mileage gradient ≥ speed threshold; If so, the undetermined slope value is used as the current slope value, and the current slope value is cached; If not, then use the cached slope value from the previous moment as the current slope value, and cache the current slope value. The filtering module is used to filter the current slope value and then output it.

9. An electronic device, characterized in that: include: Memory is used to store instructions executed by the computer; A processor is configured to execute computer execution instructions stored in the memory to implement the slope calculation algorithm as described in any one of claims 1 to 7.

10. A storage medium, characterized in that: It stores computer execution instructions, which, when executed by a processor, are used to implement the slope calculation algorithm as described in any one of claims 1 to 7.