Water meter filtering method, system, computer and medium based on Kalman filtering
By optimizing the Q value and R value in the Kalman filter model and adjusting the R value calculation formula in segments according to the flow magnitude, the problem of low accuracy of water meter measurement is solved, and high-precision measurement under different flow conditions is achieved.
Patent Information
- Application Number
- CN202111607352.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2041-12-27
AI Technical Summary
The existing water meter filtering technology based on Kalman filtering cannot meet the requirements of different flow data, resulting in low accuracy in water meter measurement.
The initial Kalman filtering model is constructed, and the Q value and R value are optimized according to the preset formula respectively. The R value calculation formula is adjusted in segments according to the flow magnitude to prevent the R value from approaching 0.
It improves the accuracy of water meter measurement, adapts to the requirements of different flow data, and reduces data jitter.
Smart Images

Figure CN114526782B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of water meters, and in particular to a water meter filtering method, system, computer, and medium based on Kalman filtering. Background Art
[0002] In data processing, the Kalman filtering algorithm is often used. The parameters Q and R of the traditional Kalman filter are calculated by fixed formulas and then continuously iterated to process data. The filtering effect of Kalman filtering is quite significant before data amplification. However, if the data is amplified, due to the fixed values of Q and R, there are small jitters in the curve after Kalman filtering. Therefore, the existing water meter filtering technology based on Kalman filtering cannot meet the requirements of different flow data, thus affecting the accuracy of water meter measurement. Summary of the Invention
[0003] The technical problem to be solved by the present invention is to provide a water meter filtering method, system, computer, and medium based on Kalman filtering, which can solve the problems existing in the existing water meter filtering technology based on Kalman filtering, thereby improving the accuracy of water meter measurement.
[0004] To solve the above technical problem, the present invention provides a water meter filtering method based on Kalman filtering, including: constructing an initial Kalman filtering model; optimizing the Q value in the initial Kalman filtering model according to a preset Q value calculation formula to obtain a first optimized Kalman filtering model; optimizing the R value in the first optimized Kalman filtering model according to a preset R value calculation formula to obtain a second optimized Kalman filtering model; and filtering the collected water meter data according to the second optimized Kalman filtering model.
[0005] Preferably, the preset Q value calculation formula is: Q = |O1 - O2|, where O1 is the output value of the Kalman filter in the most recent time, and O2 is the output value of the current Kalman filter.
[0006] Preferably, the preset R value calculation formula is: R = O1 * K, where O1 is the output value of the Kalman filter in the most recent time, and K is a proportional parameter preset according to the flow rate.
[0007] Preferably, the preset R value calculation formula is: R = O1 * K + M, where O1 is the output value of the Kalman filter in the most recent time, K is a proportional parameter preset according to the flow rate, and M is a preset compensation value.
[0008] Preferably, the step of optimizing the R value in the first optimized Kalman filter model according to a preset R value calculation formula to obtain a second optimized Kalman filter model includes: obtaining the flow rate of the water meter; determining whether the water meter flow rate is greater than a preset flow rate; if the determination is yes, then optimizing the R value in the first optimized Kalman filter model according to a first preset R value calculation formula to obtain a second optimized Kalman filter model; if the determination is no, then optimizing the R value in the first optimized Kalman filter model according to a second preset R value calculation formula to obtain a second optimized Kalman filter model; wherein, the first preset R value calculation formula is R = O1 * K1, the second preset R value calculation formula is R = O1 * K2, O1 is the output value of the Kalman filter for the most recent time, and both K1 and K2 are proportional parameters preset according to the flow rate, and K1 > K2.
[0009] Preferably, the step of optimizing the R value in the first optimized Kalman filter model according to a preset R value calculation formula to obtain a second optimized Kalman filter model includes: obtaining the flow rate of the water meter; determining whether the water meter flow rate is greater than a preset flow rate; if the determination is yes, then optimizing the R value in the first optimized Kalman filter model according to a third preset R value calculation formula to obtain a second optimized Kalman filter model; if the determination is no, then optimizing the R value in the first optimized Kalman filter model according to a fourth preset R value calculation formula to obtain a second optimized Kalman filter model; wherein, the third preset R value calculation formula is R = O1 * K1 + M, the fourth preset R value calculation formula is R = O1 * K2 + M, O1 is the output value of the Kalman filter for the most recent time, and both K1 and K2 are proportional parameters preset according to the flow rate, M is a preset compensation value, and K1 > K2.
[0010] The present invention also provides a water meter filtering system based on Kalman filtering for implementing any of the above-mentioned water meter filtering methods based on Kalman filtering, including: a model construction module for constructing an initial Kalman filter model; a first optimization module for optimizing the Q value in the initial Kalman filter model according to a preset Q value calculation formula to obtain a first optimized Kalman filter model; a second optimization module for optimizing the R value in the first optimized Kalman filter model according to a preset R value calculation formula to obtain a second optimized Kalman filter model; and a filtering module for filtering the collected water meter data according to the second optimized Kalman filter model.
[0011] Preferably, the second optimization module further includes: a flow acquisition unit configured to acquire the flow rate of the water meter; a judgment unit configured to judge whether the flow rate of the water meter is greater than a preset flow rate; a first optimization unit configured to, when the judgment unit judges yes, optimize the R value in the first optimized Kalman filter model according to a first preset R value calculation formula to obtain a second optimized Kalman filter model; and a second optimization unit configured to, when the judgment unit judges no, optimize the R value in the first optimized Kalman filter model according to a second preset R value calculation formula to obtain a second optimized Kalman filter model.
[0012] The present invention also provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein when the processor executes the computer program, the steps of any of the above methods are implemented.
[0013] The present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of any of the above methods are implemented.
[0014] The beneficial effects of implementing the present invention are as follows:
[0015] The present invention provides a water meter filtering method, system, computer device, and readable storage medium based on Kalman filtering. By constructing an initial Kalman filter model; optimizing the Q value in the initial Kalman filter model according to a preset Q value calculation formula to obtain a first optimized Kalman filter model; further optimizing the R value in the first optimized Kalman filter model according to a preset R value calculation formula to obtain a second optimized Kalman filter model; and finally filtering the collected water meter data according to the second optimized Kalman filter model. By adopting the present invention, the problems existing in the existing water meter filtering technology based on Kalman filtering can be solved, and thus the accuracy of water meter measurement can be improved. Description of the Drawings
[0016] Figure 1 is a flowchart of the water meter filtering method based on Kalman filtering provided by the present invention;
[0017] Figure 2 is a flowchart of the first embodiment of the optimization method provided by the present invention;
[0018] Figure 3 is a flowchart of the second embodiment of the optimization method provided by the present invention;
[0019] Figure 4 is a schematic diagram of the water meter filtering system based on Kalman filtering provided by the present invention;
[0020] Figure 5 is a schematic diagram of the second optimization module provided by the present invention. Detailed Implementation Manner
[0021] To make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. It should be noted that the orientation terms such as up, down, left, right, front, back, inside, and outside that appear or will appear in the text of the present invention are only based on the accompanying drawings of the present invention, and they do not specifically limit the present invention.
[0022] As Figure 1 shown, the present invention provides a water meter filtering method based on Kalman filtering, including:
[0023] S101, constructing an initial Kalman filtering model;
[0024] S102, optimizing the Q value in the initial Kalman filtering model according to a preset Q value calculation formula to obtain a first optimized Kalman filtering model;
[0025] S103, optimizing the R value in the first optimized Kalman filtering model according to a preset R value calculation formula to obtain a second optimized Kalman filtering model;
[0026] S104, filtering the collected water meter data according to the second optimized Kalman filtering model.
[0027] It should be noted that in data processing, the Kalman filtering algorithm is often used. The parameters Q and R of the traditional Kalman filter are calculated by fixed formulas and then the data is continuously processed by iteration. The filtering effect of Kalman filtering is quite significant before data amplification. However, if the data is amplified, due to the fixed Q value and R value, there are still small jitters in the curve after Kalman filtering. Therefore, the existing water meter filtering technology based on Kalman filtering cannot meet the requirements of different flow rate data, thus affecting the accuracy of water meter measurement.
[0028] In the present invention, an initial Kalman filtering model is constructed; the Q value in the initial Kalman filtering model is optimized according to a preset Q value calculation formula to obtain a first optimized Kalman filtering model; then the R value in the first optimized Kalman filtering model is optimized according to a preset R value calculation formula to obtain a second optimized Kalman filtering model; finally, the collected water meter data is filtered according to the second optimized Kalman filtering model. By adopting the present invention, the problems existing in the existing water meter filtering technology based on Kalman filtering can be solved, and thus the accuracy of water meter measurement can be improved.
[0029] Preferably, the formula for calculating the preset Q value is: Q = |O1 - O2|, where O1 is the output value of the Kalman filter for the most recent time, and O2 is the output value of the current Kalman filter. Further, the formula for calculating the preset R value is: R = O1 * K, where O1 is the output value of the Kalman filter for the most recent time, and K is a proportionality parameter preset according to the flow rate.
[0030] It should be noted that in this embodiment, since the accuracy requirement for the secondary meter in the water meter industry is 5% for accuracies below Q2 and 2% for accuracies above Q2, the R value is processed in segments and assigned values according to different flow rate ranges, so as to achieve the purpose of requiring fast response but low filtering requirements when processing large flow rate data, while requiring high filtering requirements but not fast response when processing small flow rate data.
[0031] More preferably, the formula for calculating the preset R value is: R = O1 * K + M, where O1 is the output value of the Kalman filter for the most recent time, K is a proportionality parameter preset according to the flow rate, and M is a preset compensation value.
[0032] It should be noted that in this embodiment, in order to prevent the R value from approaching 0 due to too low a flow rate, a compensation value M is added in this embodiment.
[0033] As Figure 2 shown, the steps of optimizing the R value in the first optimized Kalman filter model according to the preset R value calculation formula to obtain the second optimized Kalman filter model include:
[0034] S201, obtaining the flow rate of the water meter;
[0035] S202, determining whether the water meter flow rate is greater than the preset flow rate;
[0036] S203, if it is determined to be yes, then optimizing the R value in the first optimized Kalman filter model according to the first preset R value calculation formula to obtain the second optimized Kalman filter model;
[0037] S204, if it is determined to be no, then optimizing the R value in the first optimized Kalman filter model according to the second preset R value calculation formula to obtain the second optimized Kalman filter model;
[0038] Wherein, the first preset R value calculation formula is R = O1 * K1, the second preset R value calculation formula is R = O1 * K2, O1 is the output value of the Kalman filter for the most recent time, and both K1 and K2 are proportionality parameters preset according to the flow rate, and K1 > K2.
[0039] It should be noted that in this embodiment, by obtaining the flow rate of the water meter and determining whether the water meter flow rate is greater than the preset flow rate, if the determination result is yes, the R value in the first optimized Kalman filter model is optimized according to the first preset R value calculation formula to obtain the second optimized Kalman filter model; if the determination result is no, the R value in the first optimized Kalman filter model is optimized according to the second preset R value calculation formula to obtain the second optimized Kalman filter model. By adopting this embodiment, it is possible to assign values according to different flow rate intervals, so as to achieve the purpose that when dealing with large flow rate data, fast response is required but the filtering requirement is low, while when dealing with small flow rate data, the filtering requirement is high but fast response is not required.
[0040] As Figure 3 shown, the steps of optimizing the R value in the first optimized Kalman filter model according to the preset R value calculation formula to obtain the second optimized Kalman filter model include:
[0041] S301, obtaining the flow rate of the water meter;
[0042] S302, determining whether the water meter flow rate is greater than the preset flow rate;
[0043] S303, if the determination result is yes, optimizing the R value in the first optimized Kalman filter model according to the third preset R value calculation formula to obtain the second optimized Kalman filter model;
[0044] S304, if the determination result is no, optimizing the R value in the first optimized Kalman filter model according to the fourth preset R value calculation formula to obtain the second optimized Kalman filter model;
[0045] Among them, the third preset R value calculation formula is R = O1 * K1 + M, and the fourth preset R value calculation formula is R = O1 * K2 + M, where O1 is the output value of the most recent Kalman filter, K1 and K2 are both proportional parameters preset according to the flow rate, M is the preset compensation value, and K1 > K2.
[0046] It should be noted that in this embodiment, by obtaining the flow rate of the water meter and determining whether the water meter flow rate is greater than a preset flow rate, if the determination is yes, the R value in the first optimized Kalman filter model is optimized according to the third preset R value calculation formula to obtain a second optimized Kalman filter model; if the determination is no, the R value in the first optimized Kalman filter model is optimized according to the fourth preset R value calculation formula to obtain a second optimized Kalman filter model. By adopting this embodiment, it is possible to assign values according to different flow rate intervals, so as to achieve the purpose of requiring fast response but low filtering requirements when processing large flow rate data, while having high filtering requirements but not requiring fast response when processing small flow rate data; at the same time, it prevents the situation where the R value approaches 0 due to too low flow rate.
[0047] As Figure 4 shown, the present invention also provides a water meter filtering system 100 based on Kalman filtering, which is used to implement any of the above-mentioned water meter filtering methods based on Kalman filtering, and includes: a model construction module 1, which is used to construct an initial Kalman filter model; a first optimization module 2, which is used to optimize the Q value in the initial Kalman filter model according to a preset Q value calculation formula to obtain a first optimized Kalman filter model; a second optimization module 3, which is used to optimize the R value in the first optimized Kalman filter model according to a preset R value calculation formula to obtain a second optimized Kalman filter model; and a filtering module 4, which is used to filter the collected water meter data according to the second optimized Kalman filter model.
[0048] It should be noted that in data processing, the Kalman filter algorithm is often used. The parameters Q and R of the traditional Kalman filter are calculated by fixed formulas and then continuously iterated to process data. The filtering effect of the Kalman filter is still very significant before data amplification, but if the data is amplified, due to the fixed Q value and R value, there is still a small jitter in the curve after Kalman filtering. Therefore, the existing water meter filtering technology based on Kalman filtering cannot meet the requirements of different flow rate data, thus affecting the accuracy of water meter measurement.
[0049] In the present invention, the initial Kalman filter model is constructed by the model construction module 1, the Q value in the initial Kalman filter model is optimized by the first optimization module 2 according to a preset Q value calculation formula to obtain a first optimized Kalman filter model, the R value in the first optimized Kalman filter model is optimized by the second optimization module 3 according to a preset R value calculation formula to obtain a second optimized Kalman filter model, and the filtering module 4 filters the collected water meter data according to the second optimized Kalman filter model. By adopting the present invention, the problems existing in the existing water meter filtering technology based on Kalman filtering can be solved, and thus the accuracy of water meter measurement can be improved.
[0050] As Figure 5 shown, the second optimization module 3 further includes: a flow rate acquisition unit 31 for acquiring the flow rate of the water meter; a judgment unit 32 for judging whether the flow rate of the water meter is greater than a preset flow rate; a first optimization unit 33 for, when the judgment unit 32 judges yes, optimizing the R value in the first optimized Kalman filter model according to a first preset R value calculation formula to obtain a second optimized Kalman filter model; and a second optimization unit 34 for, when the judgment unit 32 judges no, optimizing the R value in the first optimized Kalman filter model according to a second preset R value calculation formula to obtain a second optimized Kalman filter model.
[0051] It should be noted that in this embodiment, the flow rate acquisition unit 31 acquires the flow rate of the water meter; the judgment unit 32 judges whether the flow rate of the water meter is greater than a preset flow rate; the first optimization unit 33, when the judgment unit 32 judges yes, optimizes the R value in the first optimized Kalman filter model according to a first preset R value calculation formula to obtain a second optimized Kalman filter model; and the second optimization unit 34, when the judgment unit 32 judges no, optimizes the R value in the first optimized Kalman filter model according to a second preset R value calculation formula to obtain a second optimized Kalman filter model.
[0052] Specifically, the formula optimization is carried out in two cases:
[0053] First, by acquiring the flow rate of the water meter and judging whether the flow rate of the water meter is greater than a preset flow rate, if it is judged yes, the R value in the first optimized Kalman filter model is optimized according to a first preset R value calculation formula to obtain a second optimized Kalman filter model, and if it is judged no, the R value in the first optimized Kalman filter model is optimized according to a second preset R value calculation formula to obtain a second optimized Kalman filter model. By adopting this embodiment, it is possible to assign values according to different flow rate intervals, so as to achieve the purpose that when processing large-flow data, fast response is required but the filtering requirement is low, and when processing small-flow data, the filtering requirement is high but fast response is not required. Among them, the first preset R value calculation formula is R = O1 * K1, and the second preset R value calculation formula is R = O1 * K2, where O1 is the output value of the Kalman filter for the most recent time, and K1 and K2 are both proportional parameters preset according to the flow rate, and K1 > K2.
[0054] Second, by obtaining the flow rate of the water meter and determining whether the flow rate of the water meter is greater than a preset flow rate, if the determination is yes, then the R value in the first optimized Kalman filter model is optimized according to the third preset R value calculation formula to obtain a second optimized Kalman filter model; if the determination is no, then the R value in the first optimized Kalman filter model is optimized according to the fourth preset R value calculation formula to obtain a second optimized Kalman filter model. By adopting this embodiment, it is possible to assign values according to different flow rate intervals, so as to achieve the purpose of requiring fast response but low filtering requirements when processing large flow rate data, while requiring high filtering requirements but not requiring fast response when processing small flow rate data; at the same time, it prevents the R value from approaching 0 due to too low flow rate. Among them, the third preset R value calculation formula is R = O1 * K1 + M, and the fourth preset R value calculation formula is R = O1 * K2 + M, where O1 is the output value of the Kalman filter for the most recent time, K1 and K2 are both proportional parameters preset according to the flow rate, M is a preset compensation value, and K1 > K2.
[0055] The present invention also provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the steps of any of the above methods are implemented.
[0056] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above methods are implemented.
[0057] In summary, in the field of water meters, the Kalman filter algorithm can be used for data processing. The parameters Q and R of the traditional Kalman filter are calculated by fixed formulas and then continuously iterated to process data, but this does not conform to the characteristics of water meter data processing. Therefore, without changing the original Kalman filter, we use the difference between the output value O1 of the previous Kalman filter and the current measurement value O2 as Q. R is divided into two cases. Because in the accuracy of the secondary meter in the water meter industry, the accuracy requirement below Q2 is 5%, and above it is 2%, so the R value is processed in segments. In the low-speed flow rate measurement interval, the R value is the percentage K1 of the previous output value O1, and in the high-flow rate interval, the R value is the percentage K2 of the previous output value. Here, K1 > K2; in order to prevent the R value from approaching 0 due to too low flow rate, a compensation value M needs to be added. In summary: Q = |O1 - O2|; in the high-flow rate interval, R = Q1 * K2 + M, and in the low-flow rate interval, R = Q1 * K1 + M.
[0058] The above is the preferred embodiment of the present invention. It should be noted that for those of ordinary skill in the art in this technical field, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements are also regarded as the protection scope of the present invention.
Claims
1. A water meter filtering method based on Kalman filtering, characterized in that, Including: Construct an initial Kalman filter model; Optimize the Q value in the initial Kalman filter model according to a preset Q value calculation formula to obtain a first optimized Kalman filter model; Optimize the R value in the first optimized Kalman filter model according to a preset R value calculation formula to obtain a second optimized Kalman filter model; the preset R value calculation formula is R = O1 * K or R = O1 * K + M, where O1 is the output value of the most recent Kalman filter, K is a proportional parameter preset according to the flow rate, and M is a preset compensation value; Filter the collected water meter data according to the second optimized Kalman filter model.
2. The water meter filtering method based on Kalman filtering according to claim 1, wherein The preset Q value calculation formula is: Q = |O1 - O2|, where O1 is the output value of the most recent Kalman filter and O2 is the output value of the current Kalman filter.
3. The water meter filtering method based on Kalman filtering according to claim 1, characterized in that, The step of optimizing the R value in the first optimized Kalman filter model according to a preset R value calculation formula to obtain a second optimized Kalman filter model includes: Obtain the flow rate of the water meter; Judge whether the water meter flow rate is greater than a preset flow rate; If the judgment is yes, then optimize the R value in the first optimized Kalman filter model according to a first preset R value calculation formula to obtain a second optimized Kalman filter model; If the judgment is no, then optimize the R value in the first optimized Kalman filter model according to a second preset R value calculation formula to obtain a second optimized Kalman filter model; Among them, the first preset R value calculation formula is R = O1 * K1, the second preset R value calculation formula is R = O1 * K2, O1 is the output value of the most recent Kalman filter, and both K1 and K2 are proportional parameters preset according to the flow rate, and K1 > K2.
4. The water meter filtering method based on Kalman filtering according to claim 1, characterized in that The step of optimizing the R value in the first optimized Kalman filter model according to a preset R value calculation formula to obtain a second optimized Kalman filter model includes: Obtain the flow rate of the water meter; Judge whether the water meter flow rate is greater than a preset flow rate; If the judgment is yes, then optimize the R value in the first optimized Kalman filter model according to a third preset R value calculation formula to obtain a second optimized Kalman filter model; If the judgment is no, then optimize the R value in the first optimized Kalman filter model according to a fourth preset R value calculation formula to obtain a second optimized Kalman filter model; Among them, the third preset R value calculation formula is R = O1 * K1 + M, the fourth preset R value calculation formula is R = O1 * K2 + M, O1 is the output value of the most recent Kalman filter, and both K1 and K2 are proportional parameters preset according to the flow rate, M is a preset compensation value, and K1 > K2.
5. A water meter filtering system based on Kalman filtering, characterized in that, For implementing the water meter filtering method based on Kalman filter according to any one of claims 1 to 4, including: A model construction module for constructing an initial Kalman filter model; A first optimization module for optimizing the Q value in the initial Kalman filter model according to a preset Q value calculation formula to obtain a first optimized Kalman filter model; A second optimization module, configured to optimize the R value in the first optimized Kalman filter model according to a preset R value calculation formula to obtain a second optimized Kalman filter model; A filtering module, configured to filter the collected water meter data according to the second optimized Kalman filter model.
6. The water meter filtering system based on Kalman filtering according to claim 5, characterized in that, The second optimization module further includes: A flow rate acquisition unit, configured to acquire the flow rate of the water meter; A judgment unit, configured to judge whether the water meter flow rate is greater than a preset flow rate; A first optimization unit, configured to optimize the R value in the first optimized Kalman filter model according to a first preset R value calculation formula to obtain a second optimized Kalman filter model when the judgment unit judges that it is; A second optimization unit, configured to optimize the R value in the first optimized Kalman filter model according to a second preset R value calculation formula to obtain a second optimized Kalman filter model when the judgment unit judges that it is not.
7. A computer device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, the steps of any one of claims 1 to 4 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the steps of any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Kalman filtering parameter debugging method for ultrasonic water meter data filtering
CN112697215A
Lightweight multi-parameter fusion link quality estimation method
CN113644994A