Smart kalman filtering method for ultrasonic water meter
By using the intelligent Kalman filtering method, an observation window is established for statistical modeling and feature extraction. This identifies water usage scenarios and interference types, and dynamically adjusts filter parameters. This solves the problems of decreased flow measurement accuracy and flow leakage when ultrasonic water meters are used in the field, achieving high-precision and fast-response flow measurement.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XIAMEN HILL HAICHUANG TECHNOLOGY CO LTD
- Filing Date
- 2026-04-28
- Publication Date
- 2026-07-21
AI Technical Summary
When ultrasonic water meters are used in the field, the accuracy of instantaneous flow measurement decreases due to pipeline interference, especially when zero flow is measured, resulting in flow leakage. Existing Kalman filtering algorithms cannot effectively cope with the rapid changes in instantaneous flow of water meters.
The intelligent Kalman filter method is adopted. By establishing an observation window for statistical modeling and feature extraction, water use scenarios and interference types are identified. The Kalman filter parameters and intermediate state variables are dynamically adjusted to remove background flow and directly intervene in the filter state, thereby achieving high-precision noise reduction and fast response.
It effectively eliminates zero-flow-loss phenomena, ensuring high accuracy and fast response in flow measurement, while taking into account filtering performance under both steady-state and transient conditions, and reducing the impact of interference on measurement.
Smart Images

Figure CN122432492A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of ultrasonic water meter technology, and in particular to an intelligent Kalman filtering method for ultrasonic water meters. Background Technology
[0002] Ultrasonic water meters measure instantaneous flow rate by measuring the time difference of sound waves traveling upstream and downstream in water. The accuracy of this time-of-flight measurement can reach the ps level, theoretically enabling ultrasonic water meters to measure instantaneous flow rates from 0.5L to 1.0L / h. Their extremely high sensitivity allows for R1000-level water meter measurements, far exceeding the accuracy of mechanical water meters. However, this high sensitivity also presents challenges for field applications. Factors such as valve opening and closing, pump start-up and shutdown, gas in the pipeline, and pipeline vibration can significantly interfere with the measurement. While an ultrasonic water meter can achieve an accuracy of 0.5L / h with the valve closed (in a clean, interference-free laboratory environment), field interference can cause errors in instantaneous flow rate, reaching tens of L / h. These errors lead to inaccurate measurement, especially at zero flow, where "flow leakage" occurs, limiting the application of ultrasonic water meters.
[0003] To address these interferences, numerous filtering algorithms exist, such as median filtering, extremum removal filtering, and Kalman filtering. These algorithms are widely used in ultrasonic water meters and have achieved certain results. However, the instantaneous flow rate of a water meter is not continuously changing. Depending on the water usage scenario, the instantaneous flow rate passing through the water meter has the following characteristics: the flow rate is close to zero when the valve is closed; when the valve is open, the flow rate rises sharply, exhibiting a step value; the same applies when the valve is closed, with the flow rate rapidly changing to zero. This characteristic leads to conventional filtering algorithms not achieving good filtering results. Taking Kalman filtering as an example, by controlling the Q and R parameters of the Kalman filter, smooth filtering can be achieved to remove noise. The smoothing degree can be reduced to quickly adapt to the large flow rate changes caused by valve changes. There are many improved Kalman filtering algorithms for water meters. However, these algorithms do not change the essence of Kalman filtering; Kalman filtering is an inertial smoothing filter and cannot adapt to the rapidly changing instantaneous flow rate of water meters. Summary of the Invention
[0004] The objective of this application is to provide a smart Kalman filtering method for ultrasonic water meters, comprising: acquiring the instantaneous flow sequence of the ultrasonic water meter; establishing an observation window containing the current instantaneous flow and historical flow, and performing statistical modeling and feature extraction on the flow data within the observation window; based on the feature extraction results, removing the actual flow as background flow to extract and identify first feature data and second feature data, wherein the first feature data represents the water usage scenario and the second feature data represents the interference type; in response to identifying the flow step change state in the first feature data, synchronously performing dynamic adjustment of the process noise covariance matrix and measurement noise covariance matrix of the Kalman filter, and directly intervening to adjust the intermediate state variables of the Kalman filter to output the filtered instantaneous flow.
[0005] By adopting the above technical solution, the actual flow rate is separated as background flow rate, enabling the algorithm to extract pure noise features independently of the absolute flow rate value. This solves the contradiction between high-precision denoising under steady-state water use conditions and rapid response under step conditions. The dual mechanism of simultaneous dynamic adjustment of the Q / R matrix and direct intervention of intermediate state variables forces the Kalman filter's inertial smoothing process to be skipped when a step occurs. This allows the filter to maintain efficient denoising under steady-state conditions and achieve instantaneous flow tracking without delay at the moment of valve opening and closing, effectively eliminating the phenomenon of zero flow leakage.
[0006] Optionally, establishing an observation window that includes the current instantaneous flow and historical flow includes: configuring the sliding window length to 15 sampling points; collecting the instantaneous flow at the current moment in real time, and storing the instantaneous flow and its 14 consecutive historical flows into the sliding window to generate an instantaneous flow sequence containing 15 observation points.
[0007] By adopting the above technical solution, and through engineering verification, the sliding window length of 15 sampling points can fully cover the typical pulse interference cycle of ultrasonic water meters (such as water hammer and pipeline vibration), ensuring sufficient statistical sample size for feature extraction, while keeping the computational complexity within the computing power range of a low-power microcontroller, thus achieving a balance between algorithm performance and embedded hardware resources.
[0008] Optionally, the method for identifying the type of interference includes: if it is determined that there is a single non-zero value in the instantaneous flow sequence and it is surrounded by zero values before and after it, then it is identified as a single pulse interference under zero flow; if it is determined that there are two consecutive non-zero values with opposite signs in the instantaneous flow sequence and they are surrounded by zero values before and after it, then it is identified as positive and negative double pulse interference under zero flow; and if it is determined that there are two consecutive non-zero values with the same sign in the instantaneous flow sequence and they are surrounded by zero values before and after it, then it is identified as unidirectional double pulse interference under zero flow.
[0009] By adopting the above technical solution, three morphological judgment criteria for zero flow interference are defined (single pulse, positive and negative double pulse, and unidirectional double pulse), enabling the algorithm to accurately identify and filter out pseudo pulse signals caused by bubbles, pipeline vibration, etc., under zero flow conditions, thus completely solving the continuous reading phenomenon caused by interference mismeasurement in the flow problem.
[0010] Optionally, identifying the flow step change state in the first feature data includes: identifying a positive step state triggered by valve opening and the flow rate jumps from zero to a target threshold; and identifying a negative step state triggered by valve closing and the flow rate drops from the target threshold to zero.
[0011] By adopting the above technical solution, the filter can distinguish between two completely different step scenarios: "water supply on" and "water supply off", thus avoiding erroneous intervention caused by misjudging a negative step as a positive step.
[0012] Optionally, the direct intervention to adjust the intermediate state variables of the Kalman filter includes: in response to identifying the step change state of the flow rate, resetting the prior state estimate and posterior state estimate of the Kalman filter to be equal to the current observed flow rate value; and initializing the prior estimate error covariance matrix to block the inertial smoothing effect of the flow rate integral at the previous time on the current time filtering calculation.
[0013] By adopting the above technical solution, the prior / posterior state estimates are forcibly reset (making them equal to the current observations) and the prior error covariance matrix is initialized. This logically formats the historical memory of the Kalman filter, completely blocking the inertial smoothing effect of the flow integral at the previous moment on the current moment. This allows the filter to instantly jump to the current true physical value at the moment the valve is switched on and off, eliminating the inherent system overshoot and recovery period of the Kalman filter when the flow changes abruptly.
[0014] Optionally, removing the actual flow rate as background flow rate includes: calculating the steady-state mean of continuous flow rate data within the observation window and configuring it as the background flow rate; subtracting the steady-state mean from the flow rate data within the observation window point by point to generate a pure noise flow rate sequence stripped of actual water usage trends.
[0015] By adopting the above technical solution, the actual water use trend is gradually deducted from the observation window using the steady-state mean stripping method to generate a pure noise flow sequence. This allows the interference type identification logic mentioned above to still be reused in non-zero flow conditions. That is, regardless of whether the current flow is 1L / h or 1000L / h, the pure noise sequence features after background stripping are homogeneous with the noise features under zero flow conditions, which significantly improves the signal-to-noise ratio and identification accuracy in dynamic water use environments.
[0016] Optionally, the method further includes: in response to the failure to identify the flow step change state and the identification of the interference type, maintaining the regular iterative calculation of the intermediate state variables of the Kalman filter; and increasing the weight parameters of the measurement noise covariance matrix based on the interference type to perform smoothing filtering.
[0017] By adopting the above technical solution, under non-step operating conditions, a mild strategy of keeping intermediate state variables unchanged and only increasing the weight of measurement noise covariance R is adopted to ensure the continuity of the filtering process and avoid filter oscillation caused by frequent intervention in intermediate state variables. At the same time, by utilizing the autoregressive characteristics of Kalman filtering, the small high-frequency fluctuations are smoothed to the greatest extent, taking into account the measurement stability under non-step scenarios.
[0018] Optionally, the method further includes: obtaining the first derivative of the instantaneous flow rate within the observation window; determining that the system is in a rapid step state in response to the first derivative exceeding a preset extreme value threshold; and increasing the sampling frequency of the ultrasonic water meter based on the rapid step state to obtain a high-density feature observation sequence.
[0019] By adopting the above technical solution, the sampling frequency is dynamically increased at the instant of detecting a sudden change in flow rate, using the first derivative exceeding a preset extreme value threshold as the criterion for a rapid step. This solves the problem of insufficient accuracy of fixed low-frequency sampling for step edge capture under low-power design. By increasing the observation density only at the instant of the step, a dynamic balance between power consumption and performance is achieved.
[0020] Optionally, the method further includes: calculating the second derivative of the instantaneous flow rate to obtain the step slope change rate; and configuring the initial value of the process noise covariance matrix for the next sampling period according to the step slope change rate in a proportional mapping relationship.
[0021] By adopting the above technical solution, the second derivative (rate of change of step slope) is introduced for predictive control. The initial value of the process noise covariance matrix Q for the next iteration is dynamically preset according to a positive proportional mapping relationship, which makes the filter have stronger anti-oscillation capability after the step occurs, further shortening the convergence time of the system. By predicting the step inflection point in advance, the filter can complete parameter adaptation before the step occurs.
[0022] Optionally, establishing an observation window that includes the current instantaneous flow rate and historical flow rates further includes: collecting real-time temperature data of the environment where the ultrasonic water meter is located; obtaining a water sound velocity compensation coefficient based on the real-time temperature data by looking up a table; and using the compensation coefficient to calibrate the ranging error of the flow data within the observation window, wherein the ranging error calibration is performed before the feature extraction.
[0023] By adopting the above technical solution, real-time temperature compensation calibration is introduced at the data source. The water body sound velocity compensation coefficient is obtained by looking up the table to correct the distance measurement error of the flow data. This eliminates the ultrasonic sound velocity drift caused by seasonal changes, diurnal temperature differences or sudden changes in ambient temperature, and ensures that the flow reference value within the observation window has physical consistency. This effectively prevents step misjudgment or interference misidentification caused by environmental drift. Attached Figure Description
[0024] Figure 1 This is a schematic diagram of the intelligent Kalman filtering method for ultrasonic water meters used in this application. Detailed Implementation
[0025] The technical solution of the intelligent Kalman filtering method for ultrasonic water meters of this application will be described in detail below with reference to the accompanying drawings and specific embodiments. This method is mainly applied to the signal processing unit of the ultrasonic water meter. The signal processing unit can be integrated into the low-power microcontroller of the ultrasonic water meter. The microcontroller is connected to the ultrasonic transducer drive measurement circuit through its analog-to-digital conversion interface or digital communication interface to acquire the original time-of-flight difference measurement data reflecting the fluid flow velocity in real time. These original data are converted into an instantaneous flow sequence. In the actual pipeline environment where the ultrasonic water meter is located, the opening and closing of valves in the pipeline, the periodic start and stop of water pumps in the secondary water supply system, bubbles formed by residual gas in the pipeline, and external mechanical vibrations can all introduce high-frequency or pulse interference to the measurement of time-of-flight difference by changing the sound wave propagation path or causing micro-deformation of the pipe wall. These interferences are not fully exposed in the pure laboratory environment, but they manifest as drastic jumps in the instantaneous flow signal under field conditions. If the classic Kalman filtering algorithm is directly applied to this flow sequence... Smoothing processes present a dilemma due to the inherent inertial smoothing characteristics of the Kalman filter: when the filter parameters are configured in strong smoothing mode, the process of the flow rate jumping from zero to the target threshold at the moment the valve opens will be over-smoothed, resulting in significant time-domain lag; when the filter parameters are configured in fast follow mode, high-frequency noise in the steady-state water use phase cannot be effectively suppressed. To address this, this application introduces an intelligent decision-making mechanism based on statistical modeling and feature extraction. This intelligent decision-making mechanism constructs an observation window containing the current instantaneous flow rate and its historical data to perform multi-dimensional mathematical analysis on the flow signal within the window. From this, the background flow rate component representing the actual water use trend and the residual noise component representing various types of interference are extracted. Based on this, the mechanism monitors in real time whether a step change occurs in the water use scenario. When a flow step change is detected, the mechanism simultaneously performs adaptive adjustment of the dual parameters of the Kalman filter and direct intervention and reset of the internal intermediate state variables. Thus, within the same filtering framework, it simultaneously achieves high-precision denoising under steady-state conditions and delay-free tracking under transient conditions.
[0026] like Figure 1As shown, this application discloses a smart Kalman filtering method for ultrasonic water meters, comprising: acquiring the instantaneous flow sequence of the ultrasonic water meter; establishing an observation window containing the current instantaneous flow and historical flow, and performing statistical modeling and feature extraction on the flow data within the observation window; based on the feature extraction results, removing the actual flow as background flow to extract and identify first feature data and second feature data, wherein the first feature data represents the water usage scenario and the second feature data represents the interference type; in response to identifying the flow step change state in the first feature data, synchronously performing dynamic adjustment of the process noise covariance matrix and measurement noise covariance matrix of the Kalman filter, and directly intervening to adjust the intermediate state variables of the Kalman filter to output the filtered instantaneous flow.
[0027] Understandably, the step of obtaining the instantaneous flow sequence of the ultrasonic water meter is executed by the measurement and control module of the ultrasonic water meter. This measurement and control module alternately applies transmission and reception control signals to a pair of ultrasonic transducers installed on the measuring pipe section at a fixed base sampling frequency. When the upstream transducer acts as the transmitter, the downstream transducer acts as the receiver, recording the flight time of the sound wave propagating in the downstream direction. Then, the roles are switched so that the downstream transducer transmits and the upstream transducer receives, recording the flight time of the sound wave propagating in the upstream direction. The difference between the flight times in the two directions has a linear proportional relationship with the axial average velocity of the fluid in the pipe section, determined by the flow field distribution coefficient. Multiplying the flight time difference by the velocity conversion coefficient and then by the cross-sectional area of the pipe section yields the instantaneous volumetric flow rate value at the corresponding moment. This instantaneous volumetric flow rate value is stored in the data register of the microcontroller in the form of a digital signal and forms a continuous time sequence over time. Establishing an observation window that includes current instantaneous flow and historical flow refers to using the microcontroller's internal circular buffer or ring data queue to organize the time series. Based on the current sampling time, several consecutive historical sampling points are traced back, and the instantaneous flow values at these sampling points, along with the current value, are encapsulated into a fixed-length data vector. This data vector is the instantaneous flow sequence carried by the observation window. The microcontroller's data processing core then performs statistical modeling and feature extraction operations on the flow data within the observation window. The statistical modeling process includes calculating the central tendency and dispersion parameters of the flow data within the window, such as the arithmetic mean, median, standard deviation, and range. The feature extraction process identifies the inherent patterns presented by the data within the window based on these statistics and predefined morphological criteria.Removing actual flow as background flow based on feature extraction results refers to: calculating the steady-state mean of flow data within the observation window and identifying this steady-state mean as the actual flow component (i.e., background flow) at the current moment; then subtracting this steady-state mean from each flow data point within the window to extract a residual sequence containing only disturbance components. This residual sequence can be further analyzed to distinguish whether it contains specific forms of interference patterns. The first feature data characterizing the water use scenario refers to determining the current water use state of the system by analyzing the magnitude of the background flow and its changing trend on the window time scale. Possible water use scenarios include zero-flow static state, steady-state low-flow water use state, steady-state high-flow water use state, and flow step transient state. The second feature data characterizing the interference type refers to identifying which predefined interference pattern superimposed on the actual flow at the current moment belongs to by performing waveform morphology classification on the extracted residual sequence. Predefined interference patterns can include single-pulse interference under zero flow, positive and negative double-pulse interference under zero flow, unidirectional double-pulse interference under zero flow, and superimposed interference on a non-zero flow background. In the additive interference scenario, when the first characteristic data is identified as a step change in flow rate, the method switches to a nonlinear intervention mode. In this mode, the process noise covariance matrix and measurement noise covariance matrix of the Kalman filter are dynamically adjusted simultaneously. The process noise covariance matrix controls the filter's confidence in the system state evolution, while the measurement noise covariance matrix controls the filter's confidence in the measured values. At the instant of the step change, the process noise covariance is increased to allow the filter to quickly accept the state change, while the measurement noise covariance is decreased to increase the filter's acceptance weight for the current observation. Based on this, a direct intervention adjustment operation can be performed on the intermediate state variables of the Kalman filter. This direct intervention adjustment operation can directly modify the prior state estimate, posterior state estimate, and prior estimate error covariance matrix within the filter, thereby fundamentally breaking the inertial smooth continuity of the Kalman filter. This allows the filtered output to complete the transition from the old steady state to the new steady state within a single sampling period. The final filtered instantaneous flow rate retains both the speed of the step response and the noise suppression capability under steady state.
[0028] Establish an observation window that includes the current instantaneous flow and historical flow, including: configuring the sliding window length to 15 sampling points; collecting the instantaneous flow at the current moment in real time, and storing the instantaneous flow and its 14 consecutive historical flows into the sliding window to generate an instantaneous flow sequence containing 15 observation points.
[0029] In this embodiment, the length of the sliding window is configured to 15 sampling points. This specific value is determined based on engineering analysis of the time-domain duration of typical interference signals in ultrasonic water meter application scenarios. The main interference sources encountered by ultrasonic water meters in actual field use include pulse vibrations caused by water hammer effect, pressure waves generated by the start-up and shutdown of secondary water supply pump stations, and instantaneous impacts caused by the bursting of air bubbles in the pipeline. The duration of a single disturbance of these interference signals is usually between several and more than ten sampling cycles. If the window length is too short, the complete interference waveform cannot be captured. If the window length is too long, too much historical information will be introduced, resulting in a sluggish response to changes in flow status and increasing the computational load of the microcontroller. The window length of 15 sampling points has been verified in engineering to cover the complete life cycle of typical interference signals under most common pipeline network conditions, while controlling the number of multiplication and addition operations required for each sliding window update. Within the acceptable real-time computing budget of a low-power microcontroller, in specific implementations, the microcontroller can drive the data acquisition process through interrupt service routines or timer callback functions. At the arrival of each sampling period, the analog-to-digital converter or digital interface completes a reading of instantaneous flow data. The instantaneous flow value at the current moment is pushed into the tail of the circular data queue, while the oldest historical data at the head of the queue is popped and discarded. This ensures that the queue always stores the flow observation values of the most recent 15 consecutive sampling moments, forming a sliding update state sequence. The first position in this state sequence, i.e., index 0, stores the latest flow value at the current moment, and the second to fifteenth positions, i.e., indices 1 to 14, store the 14 historical flow values that are traced back sequentially. The entire sequence is maintained in the microcontroller's random access memory in a first-in-first-out manner, and the update delay of the sequence is only one sampling period, ensuring the real-time requirements.
[0030] In this embodiment of the application, the method for identifying the type of interference includes: if it is determined that there is a single non-zero value in the instantaneous flow sequence and it is surrounded by zero values before and after it, then it is identified as a single pulse interference under zero flow; if it is determined that there are two consecutive non-zero values with opposite signs in the instantaneous flow sequence and they are surrounded by zero values before and after it, then it is identified as positive and negative double pulse interference under zero flow; and if it is determined that there are two consecutive non-zero values with the same sign in the instantaneous flow sequence and they are surrounded by zero values before and after it, then it is identified as unidirectional double pulse interference under zero flow.
[0031] Understandably, the identification of interference types is based on a morphological scan of the pure noise residual sequence obtained after removing the background flow. When the first feature data indicates that the current water usage scenario is in a zero-flow state, the background flow value within the observation window should theoretically be zero or close to a minimum value of zero. At this time, the residual sequence obtained after removing the background flow from the measured value itself represents all the interference components superimposed on the zero-flow reference. The feature recognition logic in the microcontroller performs a point-by-point traversal scan of the residual sequence to detect the number of non-zero values, their sign polarity, and their relative positional relationship with zero values. A single non-zero value surrounded by zero values before and after it means that the scan finds only one data point in the residual sequence with an absolute value exceeding the predefined dead zone threshold, while the preceding and following adjacent points of this data point are both zero points with absolute values below the dead zone threshold. This morphology corresponds to isolated pulse interference caused by a single bubble rupture or a single mechanical impact in the pipeline. Two consecutive non-zero values with opposite signs surrounded by zero values before and after them means that the scan finds two non-zero values in the residual sequence with opposite signs. Two adjacent data points, both exceeding the dead zone threshold in absolute value, with opposite signs (one positive and the other negative), and both preceding and following adjacent points being zero, correspond to alternating negative attenuation oscillation interference in the pipeline caused by pressure wave oscillations or transient responses of the transducer drive circuit. Two consecutive non-zero values with the same sign, surrounded by zero values before and after them, indicate that the residual sequence contains two adjacent data points, both exceeding the dead zone threshold in absolute value, with the same sign (either both positive or both negative), and both preceding and following adjacent points being zero. This corresponds to superimposed pulse interference in the pipeline caused by two consecutive mechanical impacts or continuous gas releases. These three morphological criteria can distinguish different types of zero-flow interference at the source, providing a refined classification basis for subsequent filter parameter adjustments. This avoids misjudging interference signals as actual water usage events during zero-flow static conditions, leading to so-called flow metering errors.
[0032] In this embodiment of the application, identifying the flow step change state in the first feature data includes: identifying a positive step state triggered by valve opening and the flow rate jumps from zero to a target threshold; and identifying a negative step state triggered by valve closing and the flow rate drops from the target threshold to zero.
[0033] Specifically, the identification of flow step change states is also based on the statistical modeling and feature extraction results of flow data within the observation window. When the water usage scenario represented by the first feature data undergoes a sudden change from a zero flow state to a non-zero flow state within several consecutive sampling periods, this embodiment of the application determines the sudden change as a positive step state triggered by valve opening. The typical characteristics of this positive step are: the average flow rate within the observation window rapidly rises from an extremely low value to a value significantly higher than zero during the window update process, and this value tends to stabilize after reaching the target threshold. At the same time, the standard deviation of the flow data within the window will significantly increase at the moment the step occurs because the step itself contains data changes spanning multiple orders of magnitude. The triggering source of the positive step is the valve opening operation of the user-end water equipment. This operation switches the pipeline from a closed state to an open state, and the water flow changes from static to flowing. The flow velocity at the ultrasonic water meter rapidly rises from near zero to above zero. The steady-state flow velocity, determined by the pressure difference and the diameter of the water-using equipment, can be identified as a negative step state triggered by valve closure when the water-using scenario characterized by the first feature data undergoes a sudden change from a non-zero flow state to a zero flow state within several consecutive sampling periods. The typical characteristics of this negative step are that the average flow rate within the observation window drops rapidly from a high value to a level close to zero during the window update process, and the standard deviation of the flow data within the window also increases significantly at the moment the step occurs because the flow rate value drops from a high level to a low level. The triggering source of the negative step is the valve closure operation of the user-end water-using equipment. This valve closure operation switches the pipeline from a flowing state to a cut-off state, and the water flow changes from flowing to still. The flow velocity at the ultrasonic water meter drops rapidly from the steady-state water flow rate to zero. The positive and negative step states constitute the two most basic forms of transient flow change in the water-using scenario, which correspond to the beginning and end of the water-using event, respectively.
[0034] In this embodiment of the application, directly intervening in the adjustment of the intermediate state variables of the Kalman filter includes: in response to identifying a step change in the flow rate, resetting the prior state estimate and posterior state estimate of the Kalman filter to be equal to the current observed flow rate value; and initializing the prior estimate error covariance matrix to block the inertial smoothing effect of the flow rate integral at the previous time on the current time filtering calculation.
[0035] Specifically, upon identifying a positive or negative step state, the microcontroller's filtering calculation module can interrupt the regular Kalman filter iteration process and switch to a forced initialization sub-process specifically designed for step scenarios. In this forced initialization sub-process, the observed flow rate value at the current sampling moment is first read. This observed flow rate value is the original sampled data of the instantaneous flow rate sequence at the current moment. Then, this observed flow rate value is simultaneously assigned to two key state variables within the Kalman filter: the prior state estimate and the posterior state estimate. The prior state estimate is... The state transition matrix is used to update the posterior state estimate from the previous time step. This process naturally carries over the flow information from the previous time step (i.e., the historical flow integral) to the current time step, resulting in inertial lag when a step occurs. However, by directly resetting the prior state estimate to the current observed flow value, the prediction step of the state transition equation is completely skipped, so that the current internal state of the filter no longer carries any historical flow information before the step occurs. Similarly, resetting the posterior state estimate to the current observed flow value allows the filter output to jump within the same sampling period. This method transforms the flow rate to the actual physical flow value without requiring the convergence process of several cycles required by conventional filtering. Based on this, the prior estimation error covariance matrix can be further initialized. In conventional Kalman filtering, this matrix controls the filter's uncertainty assessment of the state prediction. When a step change occurs, the original error covariance matrix has accumulated a large amount of statistical characteristics from the previous steady-state flow range. If it is not reset, even if the state estimate has been forcibly modified, the historical information in the error covariance matrix will still indirectly affect the subsequent flow rate through the calculation of the Kalman gain. The continued filtering behavior initializes the prior estimation error covariance matrix to a preset initial value, which is equivalent to informing the filter that the current state estimate has a preset level of uncertainty. This allows the Kalman gain to be recalculated based on the confidence level of the current observation. By resetting the prior state estimate, the posterior state estimate, and initializing the prior estimation error covariance matrix in three steps, the Kalman filter's inertial smoothing characteristic is essentially blocked from continuing in the step transient, enabling the filter output to complete a delay-free transition from the old flow reference to the new flow reference within one sampling period.
[0036] In this embodiment of the application, the actual flow rate is removed as background flow rate, including: calculating the steady-state mean of continuous flow data within the observation window and configuring it as background flow rate; subtracting the steady-state mean from the flow data within the observation window point by point to generate a pure noise flow sequence stripped of actual water usage trends.
[0037] Specifically, removing the actual flow rate as background flow rate involves decomposing the composite flow signal within the observation window into a gradually varying component representing the actual water usage trend and a rapidly varying component representing interference factors. This allows for independent analysis and processing of these two components. The steady-state mean can be calculated using the arithmetic mean method: summing the instantaneous flow values of all 15 sampling points within the observation window and then dividing by 15 yields the central tendency measure for that window at the current moment. This steady-state mean physically represents the average flow rate over the most recent 15 sampling periods. When there are no abrupt changes within the window, the deviation between the steady-state mean and the actual flow rate is solely due to noise and interference. When there are abrupt changes within the window, the steady-state mean lies between the two steady-state flow rates before and after the abrupt change, but it still reflects the overall flow level within the window's timescale. Setting this steady-state mean as background flow rate means recognizing it as representing the actual physical flow rate near the current moment—the true flow rate of user water usage—rather than measurement noise or external interference. The introduced spurious component involves subtracting the steady-state mean from the flow data within the observation window point by point. This means performing an arithmetic operation on the instantaneous flow value at each sampling point within the window, subtracting the background flow. This operation generates a new numerical sequence, where each value represents the deviation of the original flow measurement at the corresponding sampling time from the background flow benchmark. When the system is in a zero-flow state, the steady-state mean is close to zero, so the subtraction operation has minimal impact on the original data. The stripped sequence is essentially equivalent to the original noise sequence. When the system is in a non-zero-flow state, the steady-state mean reflects the sequence obtained after subtracting the actual water flow, which is a pure noise component superimposed on the water flow. The amplitude and waveform of this noise component have similar statistical characteristics to the noise interference under zero flow, thus allowing the aforementioned interference type identification method to be reused for classification. The mean subtraction method effectively extracts interference signals from the dynamic flow background, providing a signal basis for uniformly performing interference type identification across the entire flow range.
[0038] In this embodiment of the application, the method further includes: in response to the absence of a flow step change state and the identification of an interference type, maintaining the regular iterative calculation of the intermediate state variables of the Kalman filter; and increasing the weight parameters of the measurement noise covariance matrix based on the interference type to perform smoothing filtering.
[0039] Specifically, when the analysis results of the first feature data indicate that the current water use scenario does not include a step change in flow, i.e., the system is in a zero-flow static state or a steady-state water use state, it is determined that no interventionist reset operation is needed for the intermediate state variables of the Kalman filter. Under this condition, the state prediction equation and state update equation of the Kalman filter continue to run according to the standard time update and measurement update iteration process without any form of forced variable modification. The prior state estimate of the filter is obtained by multiplying the state transition matrix by the posterior state estimate of the previous time step. The posterior state estimate is obtained by adding the prior state estimate to the product of the Kalman gain multiplied by the innovation term. The entire iterative process maintains the complete mathematical structure of the classic Kalman filter algorithm. On this basis, the weight parameters of the measurement noise covariance matrix are adjusted according to the specific interference type. The weight parameters of the measurement noise covariance matrix are a scalar multiplier or a diagonal matrix multiplier, used to add additional noise tolerance on the basis of the standard measurement noise covariance matrix. When a single-pulse interference under zero flow is identified, it can be... The weighting parameter of the measurement noise covariance matrix is increased to a first preset multiple, which reduces the filter's confidence in the current observation value. This allows the single-pulse interference to be significantly smoothed as measurement noise during filtering. When positive and negative double-pulse interference under zero flow is identified, the weighting parameter of the measurement noise covariance matrix can be increased to a second preset multiple, which is higher than the first preset multiple because the combined energy of positive and negative double pulses is higher than that of single pulses, requiring stronger smoothing to suppress their oscillating components. When co-current double-pulse interference under zero flow is identified, the weighting parameter of the measurement noise covariance matrix can be increased to a third preset multiple, which is between the first and second preset multiples to match the energy level of co-current double pulses. By differentially increasing the weighting of the measurement noise covariance matrix according to the type of interference, adaptive smoothing filtering of various interference signals can be achieved while maintaining the regular iteration of the intermediate state variables in the Kalman filter. This ensures that the output flow curve under steady-state conditions has excellent smoothness and low volatility.
[0040] In this embodiment of the application, the method further includes: obtaining the first derivative of the instantaneous flow rate within the observation window; determining that the system is in a rapid step state in response to the first derivative exceeding a preset extreme value threshold; and increasing the sampling frequency of the ultrasonic water meter based on the rapid step state to obtain a high-density feature observation sequence.
[0041] Specifically, while performing statistical modeling and feature extraction within the observation window, instantaneous flow rate is calculated in parallel. This first derivative reflects the instantaneous rate of flow rate change over time. In the specific implementation of digital signal processing, the first derivative can be approximated using the finite difference method, i.e., calculating the difference in instantaneous flow rate between two adjacent sampling points divided by the sampling time interval. In practical engineering calculations, the difference value can be directly used instead of the derivative value because the sampling time interval is a constant and does not affect the threshold comparison result. The sequence of first derivatives of instantaneous flow rate within the observation window can be obtained by sequentially performing difference operations on continuous sampling points within the window. Forward difference can be used at the initial boundary of the window, and central difference can be used at the inner points of the window to improve the numerical accuracy of the derivative value. When the valve opens or closes, causing a flow rate step, the absolute value of this first derivative will reach a value much higher than the steady-state fluctuation level at the instant the step occurs. The preset extreme threshold is a value calibrated on-site or preset at the factory, and its value is higher than the maximum derivative value that can be generated by slow flow rate changes or noise fluctuations during normal water use. When the absolute value of the first derivative exceeds the preset extreme threshold... When the threshold is reached, the system is determined to be in a rapid step state, which means that the flow rate is changing drastically at a rate exceeding the normal rate of change. In response to this determination, a command is sent to the sampling control module of the ultrasonic water meter to increase the sampling frequency of the system. The increase in sampling frequency can be a pre-set fixed multiple, such as increasing the base sampling frequency to two, three, or four times the original value, or it can be dynamically determined proportionally based on the specific overshoot of the first derivative. The larger the derivative value, the higher the increase in sampling frequency. After the sampling frequency is increased, the microcontroller can acquire more instantaneous flow observation data per unit time. These high-density observation data are stored sequentially in the observation window to form a high-density feature observation sequence, which allows transient features such as the rise time, peak overshoot, and settling time of the step edge to be captured more precisely, thereby further improving the response accuracy and control effect of this application under the rapid step condition. At the same time, since the increase in sampling frequency is only started when the rapid step state is triggered, and returns to the base sampling frequency under steady-state conditions, this dynamic sampling strategy achieves an optimized balance between performance and power consumption.
[0042] In this embodiment of the application, it may further include: calculating the second derivative of the instantaneous flow rate to obtain the step slope change rate; and configuring the initial value of the process noise covariance matrix of the next sampling period according to the step slope change rate in a proportional mapping relationship.
[0043] Specifically, based on increasing the sampling frequency and acquiring a high-density feature observation sequence, this embodiment further calculates the second derivative of the instantaneous flow rate. This second derivative reflects the rate of change of the first derivative, i.e., the acceleration component of the flow rate change. In the digital domain, the second derivative is obtained by performing a difference operation on the first-order difference sequence again. Specifically, it involves calculating the difference between two consecutive first-order difference values divided by the square of the sampling time interval. The absolute value of the second derivative characterizes the drastic change in the step slope itself. When the absolute value of the second derivative is relatively large... When the second derivative is large, it indicates that the slope of the step edge is changing rapidly, meaning the flow rate is accelerating from zero to the target threshold and is in the acceleration or deceleration phase. When the absolute value of the second derivative approaches zero, it indicates that the slope of the step edge is becoming constant, meaning the flow rate is increasing or decreasing at a near-constant rate. In this embodiment, the calculated second derivative is defined as the step slope change rate, and based on the magnitude of this change rate, the initial value of the process noise covariance matrix of the Kalman filter in the next sampling period is configured through a proportional mapping relationship. The proportional mapping relationship can be... The initial value of the process noise covariance matrix is a linear function, meaning it equals the scaling factor multiplied by the absolute value of the step slope change rate plus a base offset. The scaling factor depends on the state dimension of the Kalman filter and the dimensions of each state variable, and is calibrated through field testing or simulation experiments. In conventional Kalman filtering algorithms, the process noise covariance matrix is typically set as a fixed diagonal matrix. However, in this application, the initial value of the process noise covariance matrix is dynamically adjusted according to the step slope change rate. When the step slope change rate is large, the initial value of the process noise covariance matrix is set to a correspondingly large value. This means that the filter anticipates greater uncertainty in the system state at that moment, thus relaxing the constraints on the state transition equation and allowing the filter output to more closely follow the changes in the observed values. When the step slope change rate is small, the initial value of the process noise covariance matrix is set to a correspondingly small value. This means that the system state tends to be stable, and the filter can rely more heavily on the predictions of the state transition equation, thereby achieving more effective smoothing of the observed noise.
[0044] In this embodiment of the application, the establishment of an observation window that includes the current instantaneous flow rate and historical flow rate further includes: collecting real-time temperature data of the environment where the ultrasonic water meter is located; obtaining the water sound velocity compensation coefficient by looking up a table based on the real-time temperature data; and using the compensation coefficient to calibrate the distance measurement error of the flow data within the observation window, wherein the calibration is performed before feature extraction.
[0045] Specifically, before organizing and storing the flow data in time and space, the operation of establishing the observation window first introduces an environmental temperature compensation preprocessing step. This preprocessing step is based on the physical fact in ultrasonic flow measurement that the speed of sound in water changes with temperature. The actual speed of sound in water increases with rising temperature and decreases with falling temperature. If this temperature dependence of sound speed is not compensated for, the measured time difference of flight corresponding to the same physical flow velocity will drift due to changes in sound speed under different seasons or different diurnal temperature variations. This drift is significant in metrological scenarios where measurement accuracy is strictly required. The following aspect cannot be ignored. Therefore, in this embodiment, a temperature sensor can be integrated into the outer wall of the pipe section or the transducer mounting base of the ultrasonic water meter. This temperature sensor collects real-time temperature data of the water in the flow channel at fixed time intervals and converts it into a digital signal, which is then transmitted to the analog-to-digital converter interface of the microcontroller. After receiving the real-time temperature data, the microcontroller uses the temperature value as an index to perform a lookup operation in a sound velocity-temperature lookup table pre-programmed into the microcontroller's read-only memory. This lookup table covers the entire operating temperature range that the ultrasonic water meter may encounter, for example, from 0 degrees Celsius to 50 degrees Celsius, and stores each temperature value at a certain interval. The water velocity value or equivalent velocity compensation coefficient corresponding to the temperature node can be calculated using linear interpolation when the temperature value falls between two storage nodes during table lookup. After obtaining this coefficient, the instantaneous flow data to be stored in the observation window is calibrated for ranging errors. The calibration method is as follows: the original instantaneous flow value is multiplied by a correction factor derived from the compensation coefficient. If the compensation coefficient is given in the form of a velocity ratio, the correction factor is the ratio of the standard velocity at the reference temperature to the actual velocity at the current temperature. Through this multiplication, the velocity-temperature ratio in the original flow data is adjusted. The systematic bias introduced by temperature changes is eliminated, thus giving the flow data stored in the observation window physical consistency independent of temperature. This temperature calibration operation can be performed before feature extraction, that is, before the flow data enters the sliding window and is used for statistical modeling and background flow removal. Temperature compensation is completed first, ensuring that all subsequent feature recognition and filtering decisions based on the window data have eliminated the influence of environmental temperature drift at the source. This prevents changes in sound velocity caused by seasonal changes or diurnal temperature differences from being misjudged as flow changes or interference features, which could lead to errors in water use scenario identification or misjudgment of interference types.
[0046] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device, and unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0047] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, or indirect coupling or communication connection between apparatuses or units, and may be electrical, mechanical, or other forms.
[0048] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0049] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0050] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory, random access memory, magnetic disks, or optical disks.
[0051] The above are all preferred embodiments of this application and are not intended to limit the scope of protection of this application. Any feature disclosed in this specification (including the abstract and drawings) may be replaced by other equivalent or similar features unless specifically stated otherwise. That is, unless specifically stated otherwise, each feature is only one example of a series of equivalent or similar features.
Claims
1. An intelligent Kalman filtering method for an ultrasonic water meter, characterized in that, include: Obtain the instantaneous flow sequence of the ultrasonic water meter; Establish an observation window that includes the current instantaneous flow and historical flow, and perform statistical modeling and feature extraction on the flow data within the observation window; Based on the feature extraction results, the actual flow rate is removed as background flow rate in order to extract and identify the first feature data and the second feature data, wherein the first feature data represents the water use scenario and the second feature data represents the type of interference. In response to identifying the step change state of the flow rate in the first feature data, the process noise covariance matrix and measurement noise covariance matrix of the Kalman filter are dynamically adjusted simultaneously, and the intermediate state variables of the Kalman filter are directly intervened and adjusted to output the filtered instantaneous flow rate.
2. The method according to claim 1, characterized in that, The establishment of an observation window that includes current instantaneous flow and historical flow includes: Configure the sliding window length to 15 sampling points; The instantaneous flow rate at the current moment is collected in real time, and the instantaneous flow rate and the previous 14 consecutive historical flow rates are stored in the sliding window to generate an instantaneous flow rate sequence containing 15 observation points.
3. The method according to claim 1, characterized in that, The method for identifying the type of interference includes: If it is determined that there is a single non-zero value in the instantaneous flow sequence and that it is surrounded by zero values before and after it, it is identified as a single-pulse interference under zero flow. If it is determined that there are two consecutive non-zero values with opposite signs in the instantaneous flow sequence, and both values are surrounded by zero values, then it is identified as positive and negative double-pulse interference under zero flow; and If it is determined that there are two consecutive non-zero values with the same sign in the instantaneous flow sequence and both of them are surrounded by zero values, then it is identified as a double-pulse interference in the same direction under zero flow.
4. The method according to claim 1, characterized in that, The process of identifying the step change state of the flow rate in the first feature data includes: Identify a positive step state triggered by valve opening, where the flow rate jumps from zero to a target threshold; and Identify negative step states triggered by valve closure where the flow rate drops from the target threshold to zero.
5. The method according to claim 4, characterized in that, The direct intervention to adjust the intermediate state variables of the Kalman filter includes: In response to identifying the step change in flow rate, the prior and posterior state estimates of the Kalman filter are reset to be equal to the currently observed flow rate value; and Initialize the prior estimation error covariance matrix to block the inertial smoothing effect of the previous flow integral on the current filtering calculation.
6. The method according to claim 1, characterized in that, The removal of actual traffic as background traffic includes: Calculate the steady-state mean of the continuous flow data within the observation window and configure it as the background flow; The steady-state mean is subtracted from the flow data within the observation window point by point to generate a pure noise flow sequence stripped of actual water usage trends.
7. The method according to claim 1, characterized in that, The method further includes: In response to the failure to identify the state of the flow step change and the identification of the type of interference, the normal iterative calculation of the intermediate state variables of the Kalman filter is maintained; The weighting parameters of the measurement noise covariance matrix are increased based on the interference type to perform smoothing filtering.
8. The method according to claim 1, characterized in that, The method further includes: Obtain the first derivative of the instantaneous flow rate within the observation window; When the first derivative exceeds a preset extreme value threshold, the system is determined to be in a rapid step state. The sampling frequency of the ultrasonic water meter is increased based on the extremely rapid step state to obtain a high-density feature observation sequence.
9. The method according to claim 8, characterized in that, The method further includes: Calculate the second derivative of the instantaneous flow rate to obtain the rate of change of the step slope; Based on the rate of change of the step slope, the initial value of the process noise covariance matrix for the next sampling period is configured according to a proportional mapping relationship.
10. The method according to claim 1, characterized in that, The establishment of an observation window that includes the current instantaneous flow and historical flow further includes: Collect real-time temperature data of the environment in which the ultrasonic water meter is located; The water sound velocity compensation coefficient is obtained by looking up the table based on the real-time temperature data. The distance measurement error is calibrated using the compensation coefficient for the flow data within the observation window, wherein the distance measurement error calibration is performed before the feature extraction.