An adaptive filtering method and system for flow measurement in ultrasonic water meters
By dynamically adjusting the filter coefficient using an adaptive filtering method, the problem of distinguishing between real and spurious signals in ultrasonic water meter flow measurement by traditional filters is solved. This achieves a balance between fast response and smooth output, adapts to different noise characteristics, and reduces flow measurement errors.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-29
- Publication Date
- 2026-07-03
AI Technical Summary
In existing ultrasonic water meter flow measurement, traditional filters cannot effectively distinguish between real flow mutations and false spikes, resulting in flow output errors and cumulative deviations. Furthermore, they cannot achieve both high smoothness and fast response during stable and variable periods, exhibiting poor adaptability.
An adaptive filtering method based on anomaly detection and state machine-driven approach is adopted. By detecting the absolute difference of the original measurement values, the filtering coefficient is dynamically adjusted to distinguish between normal fluctuations and anomalous changes. A first-order IIR filter is used for filtering output, including switching between steady-state mode and shock-resistant mode.
It achieves fast and smooth response without jitter when real traffic changes, effectively suppresses the impact of glitches during abnormal changes, reduces output errors, adapts to different noise characteristics, has low computational overhead, and is suitable for resource-constrained embedded systems.
Smart Images

Figure CN122329429A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of ultrasonic water meter flow measurement technology, and in particular to an adaptive filtering method and system for ultrasonic water meter flow measurement. Background Technology
[0002] Ultrasonic water meters calculate instantaneous flow rate by measuring the time difference (ΔT, or TS value) of ultrasonic waves propagating in both the forward and reverse directions. In actual measurements, the raw time difference (TS) value can fluctuate or become abnormal due to various factors, including turbulence and eddies within the fluid, acoustic field distortion caused by suspended particles or bubbles in the water, thermal noise and quantization errors in electronic circuits, and external electromagnetic interference. These disturbances result in high-frequency random noise and occasional spikes in the raw TS sequence. To obtain a stable and accurate flow rate output, the raw TS sequence must be low-pass filtered.
[0003] First-order IIR filters (Exponentially Weighted Moving Average filters, EWMA) are widely used in embedded real-time systems due to their simple structure, low computational cost, and low memory footprint. Their recursive formula is y(n) = α·x(n) + (1-α)·y(n-1), where α is the filter coefficient (0 < α < 1), x(n) is the original value, and y(n) is the filtered output value. In this filter, a smaller α results in a stronger smoothing effect but a slower response; a larger α results in a faster response but a weaker smoothing effect.
[0004] In existing technologies, such as the patent with publication number CN114826214A, a first-order IIR low-pass filter is disclosed. The configuration unit obtains a filter coefficient array when the cutoff frequency is configured to the upper limit to obtain the maximum value of the filter parameters; and obtains a filter coefficient array when the cutoff frequency is configured to the lower limit to obtain the minimum value of the filter parameters. An acquisition unit acquires the data to be filtered; an index determination unit calculates an adaptive adjustment index; an adaptive adjustment unit adjusts the filter parameters according to the maximum and minimum values of the filter parameters and the adaptive adjustment index to obtain an adjusted filter coefficient array; and a filtering unit filters out high-frequency noise from the data to be filtered based on the adjusted filter coefficient array. While the above patent can achieve the dual goals of accelerating the filtering speed when data changes drastically and improving the smoothing effect when data is stable, it still has the following shortcomings:
[0005] 1. Existing technologies employ a strategy of accelerating follow-up when detecting drastic data changes, based on the premise that all drastic changes are considered valid signals requiring a rapid response. However, in ultrasonic water meter measurements, abrupt changes in the original time difference sequence may originate from two different sources: one is a genuine flow change, such as rapid valve opening and closing or dynamic scenarios like fire-fighting water supply; the other is spurious interference spikes, such as isolated peaks caused by turbulence, bubbles, or electromagnetic interference. Existing solutions cannot distinguish between "genuine flow changes" and "spurious spikes," introducing spikes into the output with equal weight, leading to instantaneous flow errors and cumulative flow deviations.
[0006] 2. This scheme uses a continuous and smooth coefficient adjustment method. After experiencing a strong interference (such as a strong electromagnetic pulse), the filter output may deviate far from the true value. Traditional filters need a long time to "forget" the error history and restore normal tracking ability.
[0007] 3. Traditional IIR filters cannot simultaneously achieve high smoothness during the steady-state period and rapid response during the changing period. If a small α (e.g., 0.05~0.1) is selected, the output is stable but the step response lag is severe, which cannot meet the real-time requirements of dynamic scenarios such as rapid valve opening and closing and fire water supply; if a large α (e.g., 0.3~0.5) is selected, the response is fast but the steady-state output jitter is large, affecting the accuracy of small flow rate measurement.
[0008] 4. The noise characteristics of the TS signal of a water meter will dynamically change under different flow rates, water qualities, and environmental noise levels. Existing technology cannot adapt to these changes, leading to performance degradation.
[0009] Therefore, in view of the above-mentioned technical problems, the present invention proposes an adaptive filtering method and system for ultrasonic water meter flow measurement. Summary of the Invention
[0010] The purpose of this invention is to address the shortcomings of existing technologies by providing an adaptive filtering method and system based on anomaly detection and state machine-driven approach. This method can dynamically adjust the filtering coefficients according to the fluctuation characteristics of the original data, achieving an optimal balance between noise suppression and fast response.
[0011] To achieve the above objectives, the present invention adopts the following technical solution:
[0012] An adaptive filtering method for flow measurement in ultrasonic water meters, comprising:
[0013] S1. Obtain the raw measurement value of the time difference between upstream and downstream flight of the ultrasonic water meter;
[0014] S2. Calculate the absolute difference between the current original measurement value and the previous original measurement value, and compare the absolute difference with the preset anomaly detection threshold. If the absolute difference is less than the preset anomaly detection threshold, proceed to step S3; if the absolute difference is greater than or equal to the anomaly detection threshold, proceed to step S4.
[0015] S3. Determine that the current original measurement value is fluctuating normally, maintain the current filter coefficient or gradually increase the filter coefficient, and filter the output according to the first-order IIR filter algorithm;
[0016] S4. Determine that the current original measurement value is an abnormal change, and use a preset minimum filter coefficient to perform a first-order IIR filter on the current original measurement value for output.
[0017] Furthermore, the step of gradually increasing the filter coefficient in step S3 specifically involves:
[0018] Set a continuous stability counter. Each time a normal fluctuation is determined, the continuous stability counter increments automatically. When the value of the continuous stability counter exceeds the preset stability counting threshold and the current filter coefficient is less than the preset upper limit of the filter coefficient, the filter coefficient is increased.
[0019] Furthermore, after performing a first-order IIR filter on the current raw measurement value in step S4, the process also includes:
[0020] The continuous stable counter is reset to zero, and the filter coefficient for the next time step is set to the preset recovery value.
[0021] Furthermore, after setting the filter coefficient for the next moment to the preset recovery value, the method further includes: during subsequent normal fluctuations, when the value of the continuous stable counter exceeds the preset stable counting threshold, gradually increasing the filter coefficient from the preset recovery value to the preset upper limit value of the filter coefficient.
[0022] Furthermore, the preset anomaly detection threshold in step S2 also includes a low threshold and a high threshold.
[0023] Furthermore, if the absolute difference is less than the low threshold, then step S3 is executed; if the absolute difference is greater than or equal to the low threshold and less than the high threshold, then the first smoothing coefficient is used for filtering; if the absolute difference is greater than or equal to the high threshold, then step S4 is executed.
[0024] Furthermore, after step S4, the method further includes:
[0025] S5. After each filtering is completed, update the previous original measurement value to the current original measurement value, and store the current filtered output value for the next iteration;
[0026] S6. Convert the filtered output value into an instantaneous flow rate value, and process the instantaneous flow rate value to obtain the cumulative flow rate value.
[0027] Accordingly, an adaptive filtering system for ultrasonic water meter flow measurement is also provided, for executing the aforementioned adaptive filtering method for ultrasonic water meter flow measurement. The filtering system includes a processor, which is configured with:
[0028] The acquisition module is used to acquire the raw measurement value of the time difference between upstream and downstream flight of the ultrasonic water meter;
[0029] The comparison module is used to calculate the absolute difference between the current original measurement value and the previous original measurement value, and compare the absolute difference with the preset anomaly detection threshold.
[0030] The steady-state processing module is used to determine that the current original measurement value is a normal fluctuation when the absolute difference is less than the preset anomaly detection threshold. It maintains the current filter coefficient or gradually increases the filter coefficient and performs filtering output according to the first-order IIR filtering algorithm.
[0031] The anti-impact processing module is used to determine that the current original measurement value is an abnormal change when the absolute difference is greater than or equal to the anomaly detection threshold. It then uses a preset minimum filtering coefficient to perform a first-order IIR filter on the current original measurement value and outputs it.
[0032] Furthermore, the processor is connected to a memory for storing data or instructions.
[0033] Furthermore, the processor is connected to a transmission device for data transmission with external devices.
[0034] Compared with the prior art, the present invention has the following beneficial effects:
[0035] 1. Dynamic Balance Smoothing and Response Speed: A state machine automatically identifies the fluctuation characteristics of the measured value. During continuous stable fluctuations, the filter coefficient is gradually increased (up to 0.25), enabling the filter to quickly track actual flow changes; during steady-state operation, the output is smooth and jitter-free. Experimental results show that in a step response test simulating a valve suddenly opening, the rise time of this method is more than 60% shorter than that of a traditional IIR filter with a fixed α=0.1, while the steady-state output fluctuation variance is comparable to that of a filter with a fixed α=0.05.
[0036] 2. Superior ability to suppress abnormal spikes: When a sudden change in the original measurement value is detected (exceeding the threshold Δth), the system instantly switches the filter coefficient to a minimum value (e.g., 0.05), forming a strong inertial filter that attenuates the impact of abnormal spikes on the output by more than 95%. Compared with traditional fixed-coefficient filters, this method reduces the peak output error by 80% when subjected to pulse interference of the same amplitude, effectively avoiding the accumulation of false flow.
[0037] 3. Intelligent Recovery and Adaptation: After an abnormal abrupt change occurs, the system automatically resets the filter coefficients to a conservative value (e.g., 0.10) and gradually increases them during subsequent continuous normal measurements. This prevents the impact of secondary interference and avoids excessive smoothing over a long period, quickly restoring normal performance. The entire process requires no manual intervention and is fully adaptive to the signal statistical characteristics.
[0038] 4. Extremely low computational overhead: The algorithm involves only subtraction, absolute value comparison, multiplication and addition operations, and updating the integer counter, requiring no floating-point coprocessor or complex matrix operations. On an ARM Cortex-M0 core (such as FM33LG048), a single filtering process takes only a few microseconds, making it suitable for high sampling rate applications with hundreds of samples per second.
[0039] 5. Intuitive parameter tuning: All thresholds (Δ_th) and coefficients (α_slow, α_fast_max, etc.) have clear physical meanings and can be intuitively set based on the noise amplitude and expected response time of the actual water meter, without the need for complex automatic control theories or machine learning models.
[0040] 6. High versatility: This method does not rely on specific wave skipping repair algorithms or other preprocessing steps and can be directly applied to the original time-of-flight difference (TOF) sequence, compatible with any existing front-end signal processing link. Furthermore, this adaptive filtering framework can be extended to other sensor signal processing scenarios with similar noise characteristics (random fluctuations and occasional spikes), such as pressure sensing and inertial measurement units. Attached Figure Description
[0041] Figure 1 This is a flowchart of an adaptive filtering method for ultrasonic water meter flow measurement provided in Embodiment 1;
[0042] like Figure 2 This is a comparison chart of the original output value TS of the fluid in the water meter pipeline under static or near-static conditions provided in Example 1 and the output value TS after filtering by this scheme.
[0043] like Figure 3 This is a comparison chart of the original output value TS of the fluid in the water meter pipe under low flow conditions provided in Example 1 and the output value TS after filtering by this scheme.
[0044] like Figure 4 This is a comparison chart of the original output value TS of the fluid in the water meter pipeline under high flow conditions provided in Example 1 and the output value TS after filtering by this scheme. Detailed Implementation
[0045] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and features described therein can be combined with each other.
[0046] The purpose of this invention is to address the shortcomings of existing technologies by providing an adaptive filtering method and system for ultrasonic water meter flow measurement.
[0047] Example 1
[0048] This embodiment provides an adaptive filtering method for ultrasonic water meter flow measurement, such as... Figure 1 As shown, it includes:
[0049] S1. Obtain the raw measurement value of the time difference between upstream and downstream flight of the ultrasonic water meter;
[0050] S2. Calculate the absolute difference between the current original measurement value and the previous original measurement value, and compare the absolute difference with the preset anomaly detection threshold. If the absolute difference is less than the preset anomaly detection threshold, proceed to step S3; if the absolute difference is greater than or equal to the anomaly detection threshold, proceed to step S4.
[0051] S3. Determine that the current original measurement value is fluctuating normally, maintain the current filter coefficient or gradually increase the filter coefficient, and filter the output according to the first-order IIR filter algorithm;
[0052] S4. Determine that the current original measurement value is an abnormal change, and use a preset minimum filter coefficient to perform a first-order IIR filter on the current original measurement value for output.
[0053] An adaptive first-order IIR filtering method for ultrasonic water meter flow measurement in this embodiment is executed by an embedded microcontroller in the ultrasonic water meter. The microcontroller model is, for example, FM33LG048, which is based on the ARM Cortex-M0 core.
[0054] This embodiment also includes initialization operations performed when the system powers on or when measurement starts. The initialization data includes: setting the initial filtered output value `filtered_TS(0)` to the initial raw measurement value `raw_TS(0)`; setting the previous raw measurement value variable `last_raw_TS` to `raw_TS(0)`; initializing the continuous stable counter `stable_count` to 0; and setting the current filtering coefficient α(n) to the default value α_default. In this embodiment, α_default is set to 0.15. It should be noted that the specific value of α_default can be adjusted according to the actual application scenario, and its value should be chosen to achieve a balance between smoothing effect and response speed. After initialization, the system enters the main loop of adaptive filtering.
[0055] In step S1, the raw measurement value of the time difference between the upstream and downstream flight of the ultrasonic water meter is obtained.
[0056] An ultrasonic water meter emits ultrasonic pulses into the fluid via an ultrasonic transducer, measures the propagation time of the ultrasonic waves in both the downstream and upstream directions, and calculates the difference between the two propagation times. This yields the raw time-of-flight difference (TOF) measurement at the nth sampling moment, denoted as raw_TS(n), where n represents the sampling sequence number and is a positive integer. The raw TOF measurement may be subject to various interferences, resulting in random fluctuations or spikes. These interferences include, but are not limited to, turbulence and eddies within the fluid, acoustic field distortion caused by suspended particles or bubbles in the water, thermal noise and quantization errors in electronic circuits, and external electromagnetic interference.
[0057] In step S2, the absolute difference between the current original measurement value and the previous original measurement value is calculated, and the absolute difference is compared with a preset anomaly detection threshold. If the absolute difference is less than the preset anomaly detection threshold, step S3 is executed; if the absolute difference is greater than or equal to the anomaly detection threshold, step S4 is executed.
[0058] The system calculates the absolute difference Δraw between the current raw measurement value and the previous raw measurement value, which is expressed as:
[0059] Δraw = |raw_TS(n) - last_raw_TS|
[0060] Among them, last_raw_TS stores the raw measurement value at the last sampling time.
[0061] Next, the calculated Δraw is compared with the preset anomaly detection threshold Δ_th. The anomaly detection threshold Δ_th is used to determine whether the original value has changed abruptly. Δ_th is set to 200,000 nanoseconds. The threshold is set based on the maximum change amplitude of the original measurement value of the ultrasonic water meter under normal flow fluctuation. The specific value can be calibrated according to the signal noise amplitude of the actual water meter.
[0062] When Δraw < Δ_th, the current original measurement value is determined to be a random fluctuation within the normal fluctuation range, and the system enters "steady-state mode" and executes step S3.
[0063] When Δraw≥Δ_th, the current raw measurement value is determined to be a sudden spike or spike, which may be caused by strong turbulence, electromagnetic interference or other abnormal factors. The system then enters the "impact resistance mode" and executes step S4.
[0064] In step S3, the current original measurement value is determined to be a normal fluctuation. The current filter coefficient is maintained or the filter coefficient is gradually increased, and the filter output is performed according to the first-order IIR filter algorithm.
[0065] When the fluctuation is determined to be normal, the system enters steady-state mode. In steady-state mode, the current filter coefficient remains unchanged, or the filter coefficient is gradually increased based on the cumulative count of continuous stable fluctuations. Specifically:
[0066] First, increment the continuous stable counter stable_count by 1. For example, if the value of stable_count was 3 before, then stable_count will become 4 after incrementing.
[0067] The system then determines whether the conditions for increasing the filter coefficient are met. These conditions include: the value of stable_count exceeds the preset stable counting threshold stable_required; and the current filter coefficient α(n) is less than the preset upper limit of the filter coefficient α_fast_max. In this embodiment, stable_required represents the number of consecutive normal operations required to enter fast mode, stable_required = 5, and α_fast_max = 0.25.
[0068] If stable_count ≤ stable_required, the filter coefficient will not be increased, and the current α(n) will remain unchanged. For example, if stable_count is 4 and stable_required is 5, since 4 < 5, the filter coefficient will not be increased, and the current α(n) will remain unchanged. Assuming the current α(n) is 0.15, then this filtering will still use α = 0.15.
[0069] If stable_count > stable_required and α(n) < α_fast_max, then the filter coefficients are gradually increased. This gradual increase can be achieved by adding a fixed step size, such as 0.01, or by directly setting α(n) to α_fast_max. This embodiment uses a gradual increase of 0.01 step size until α_fast_max is reached, thereby improving the filter's response speed to changes in actual traffic flow.
[0070] Next, the first-order IIR filter calculation is performed, which is expressed as:
[0071] filtered_TS(n)=α(n)×raw_TS(n)+(1-α(n))×filtered_TS(n-1)
[0072] Where filtered_TS(n) represents the current output filtered value; filtered_TS(n-1) represents the previous filtered output value; raw_TS(n) represents the current time difference measurement value; and α(n) represents the current filtering coefficient.
[0073] Using the above formula, the current original measurement value is introduced into the filter output with a weight of α(n), and the historical value is retained with a weight of 1-α(n), thereby achieving a low-pass filtering effect.
[0074] In step S4, if the current raw measurement value is determined to be an abnormal abrupt change, a first-order IIR filter is applied to the current raw measurement value using a preset minimum filter coefficient.
[0075] When an abnormal mutation is detected, i.e. Δraw ≥ Δ_th, the system enters the anti-impact mode. In the anti-impact mode, the current filter coefficient is forcibly set to the preset minimum filter coefficient α_slow (i.e., the strong smoothing coefficient, used to suppress abnormal mutations). In this embodiment, α_slow = 0.05 is set.
[0076] Then, α_slow is used to perform the first-order IIR filter calculation, which is expressed as:
[0077] filtered_TS(n)=α_slow×raw_TS(n)+(1-α_slow)×filtered_TS(n-1)
[0078] Since the value of α_slow is 0.05, the weight of the current abnormal raw measurement value is only 5%, while the weight of the historical filtered output value is as high as 95%. Therefore, the impact of the abnormal spike on the filtered output is greatly attenuated, with an attenuation ratio of 95%. This results in an extremely low weight for the current abnormal raw value, and the filtered output almost entirely depends on the historical value. This effectively suppresses the impact of spikes and prevents abnormal values from being quickly introduced into the filtered output, thus preventing errors in instantaneous flow calculation and cumulative flow deviation.
[0079] After completing the filtering output at the moment of the abnormal change, the stable counter `stable_count` is reset to 0. This is because the occurrence of the abnormal change interrupts the recording of continuous normal fluctuations, and counting needs to be restarted. Simultaneously, the filter coefficient α(n+1) for the next sampling moment is reset to the preset recovery value α_recovery. In this embodiment, the preset recovery value represents the coefficient reset after the abnormal change, and is set to α_recovery = 0.10. The purpose of setting the recovery value is that the filter should not immediately recover to a high response speed immediately after the abnormal event ends, because residual interference or subsequent secondary interference may still exist; however, it is also not advisable to continue maintaining an extremely small filter coefficient (such as 0.05), otherwise, if a real flow change does occur subsequently, the filter will experience significant lag due to a slow response. Therefore, setting the filter coefficient to a moderate recovery value of 0.10 can both maintain a certain suppression effect on possible residual interference and avoid excessively sacrificing response speed, so that the response speed can be gradually improved again in subsequent normal measurements.
[0080] Next, the system enters the monitoring and coefficient recovery phase for normal fluctuations. At the next sampling moment after an abnormal change occurs, the system sets the filter coefficient to the recovery value α_recovery = 0.10 and resets the continuous stability counter stable_count to 0. Thereafter, stable_count increments by 1 for each detected normal fluctuation. When stable_count exceeds the preset stability counting threshold stable_required, the system begins to gradually increase the filter coefficient by 0.01 each time until it reaches the preset upper limit of the filter coefficient α_fast_max, which is set to α_fast_max = 0.25 in this embodiment.
[0081] If an abnormal mutation is detected again during the recovery process, filtering is performed again with α_slow=0.05, stable_count is reset to 0, the filter coefficients are reset to 0.10, and the recovery process restarts.
[0082] It should be noted that the normal fluctuation processing and abnormal mutation processing described in steps S3 and S4 above correspond to two different filtering modes. During actual system operation, these two modes are dynamically switched based on the comparison result of Δraw and Δ_th. When normal fluctuations are detected multiple times consecutively, the filter coefficient gradually increases, and the filter's response speed gradually improves. When an abnormal mutation is detected, the filter coefficient instantly switches to a minimum value, and the filter exhibits strong inertia, effectively suppressing abnormal spikes. After an abnormal mutation occurs, the filter coefficient is reset to its recovery value and gradually increases during subsequent continuous normal fluctuations until it reaches its upper limit.
[0083] The process after step S4 also includes:
[0084] In step S5, after each filtering is completed, the previous original measurement value is updated to the current original measurement value, and the current filtered output value is stored for the next iteration.
[0085] Assign the current raw measurement value raw_TS(n) to last_raw_TS, so that at the next sampling time, last_raw_TS stores the current raw measurement value, that is: last_raw_TS = raw_TS(n).
[0086] Store the current filtered output value filtered_TS(n) in memory for use as the historical filtered output value filtered_TS(n-1) in the next filtering iteration.
[0087] In step S6, the filtered output value is converted into an instantaneous flow rate value, and the instantaneous flow rate value is processed to obtain the cumulative flow rate value.
[0088] The filtered output value filtered_TS(n) is converted into an instantaneous flow velocity value. The conversion method is based on the ultrasonic time-of-flight method and is expressed as follows:
[0089] v=(L / (2×sinθ))×(ΔT / (T_up×T_down))
[0090] Where v represents the instantaneous flow velocity; L represents the propagation path length of the ultrasonic wave in the fluid; θ represents the angle between the direction of ultrasonic wave propagation and the direction of fluid flow; ΔT represents the time difference between upstream and downstream flight, i.e., the filtered output value filtered_TS(n); T_up represents the downstream propagation time; and T_down represents the upstream propagation time.
[0091] In practical engineering applications, the above parameters can be pre-calibrated and stored in the non-volatile memory of the water meter. The system can quickly map the time difference of flight into the instantaneous flow velocity value by looking up a table or fitting a function.
[0092] Next, the instantaneous flow rate is integrated over time to obtain the cumulative flow rate, which is expressed as follows:
[0093] Q=Σ(v×S×Δt)
[0094] Where Q represents the cumulative flow rate; v represents the instantaneous flow velocity; S represents the cross-sectional area of the pipe; and Δt represents the sampling time interval.
[0095] like Figure 2 The figure shows a comparison between the original output value TS of the fluid in the water meter pipe under static or near-static conditions and the output value TS after filtering by this scheme.
[0096] like Figure 3 The figure shows a comparison between the original output value TS of the fluid in the water meter pipe under low flow conditions and the output value TS after filtering by this scheme.
[0097] like Figure 4 The figure shows a comparison between the original output value TS of the fluid in the water meter pipeline under high flow conditions and the output value TS after filtering by this scheme.
[0098] Using the adaptive filtering method in this embodiment, the ultrasonic water meter can obtain stable and accurate flow output under various operating conditions. When the original measured value is within the normal fluctuation range, the filter maintains a moderate smoothing strength or gradually increases the response speed to ensure smooth steady-state output and sensitive response to changes in actual flow. When abnormal spikes or glitches appear in the original measured value, the filter instantly switches to a minimum filter coefficient, minimizing the weight of outliers and effectively avoiding the accumulation of false flow. After an abnormal event occurs, the filter gradually recovers to a normal state through a mechanism of resetting the coefficient and continuous stable counting, preventing the influence of secondary interference and avoiding excessive smoothing over a long period of time. The entire filtering process is fully adaptive, requires no manual intervention, and has extremely low computational overhead, making it suitable for real-time operation on resource-constrained embedded microcontrollers.
[0099] Example 2
[0100] The adaptive filtering method for ultrasonic water meter flow measurement provided in this embodiment differs from that in Embodiment 1 in that:
[0101] This embodiment employs a multi-level threshold enhancement method to further improve the fine-grained control capability against interference of different intensities.
[0102] The preset anomaly detection thresholds include a low threshold Δ_th_low and a high threshold Δ_th_high, where Δ_th_low < Δ_th_high.
[0103] Next, the absolute difference Δraw calculated in step S2 is compared with the low threshold and the high threshold respectively, and different filtering strategies are adopted according to the comparison results.
[0104] When Δraw < Δ_th_low, the system determines it as a normal fluctuation and executes the normal fluctuation processing procedure in step S3.
[0105] When Δ_th_low ≤ Δraw < Δ_th_high, the system determines it as medium-intensity interference and uses the first smoothing coefficient for filtering; the value of the first smoothing coefficient is between α_slow and α_fast_max, for example, 0.10. It does not need to completely suppress interference when the interference intensity is moderate, but only needs to smooth it moderately, thus achieving a trade-off between anti-interference and response speed.
[0106] When Δraw ≥ Δ_th_high, the system determines it as high-intensity interference, executes the abnormal mutation handling process in step S4, and forces the use of α_slow for suppression.
[0107] The multi-level threshold scheme in this embodiment uses a hierarchical approach to enable the filter to adaptively adjust the smoothness according to the interference intensity, thereby further optimizing the filtering performance.
[0108] Example 3
[0109] This embodiment provides an adaptive filtering system for ultrasonic water meter flow measurement, used to execute an adaptive filtering method for ultrasonic water meter flow measurement according to Embodiment 1. The filtering system includes a processor, which is configured with:
[0110] The acquisition module is used to acquire the raw measurement value of the time difference between upstream and downstream flight of the ultrasonic water meter;
[0111] The comparison module is used to calculate the absolute difference between the current original measurement value and the previous original measurement value, and compare the absolute difference with the preset anomaly detection threshold.
[0112] The steady-state processing module is used to determine that the current original measurement value is a normal fluctuation when the absolute difference is less than the preset anomaly detection threshold. It maintains the current filter coefficient or gradually increases the filter coefficient and performs filtering output according to the first-order IIR filtering algorithm.
[0113] The anti-impact processing module is used to determine that the current original measurement value is an abnormal change when the absolute difference is greater than or equal to the anomaly detection threshold. It then uses a preset minimum filtering coefficient to perform a first-order IIR filter on the current original measurement value and outputs it.
[0114] The processor described in this embodiment may include a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.
[0115] The processor described in this embodiment has a memory connected to it for storing data or instructions. The memory may include a mass storage device for data or instructions. For example, and not limitingly, the memory may include a hard disk drive (HDD), a floppy disk drive, a solid-state drive (SSD), flash memory, an optical disk drive, a magneto-optical disk drive, magnetic tape, or a Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, the memory may include removable or non-removable (or fixed) media. Where appropriate, the memory may be internal or external to the data processing device. In a particular embodiment, the memory is non-volatile memory. In a particular embodiment, the memory includes read-only memory (ROM) and random access memory (RAM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), an electrically alterable read-only memory (EAROM), or flash memory, or a combination of two or more of these. Where appropriate, the RAM can be Static Random-Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). DRAM can be Fast Page Mode Dynamic Random Access Memory (FPMDRAM), Extended Data Out Dynamic Random Access Memory (EDODRAM), Synchronous Dynamic Random-Access Memory (SDRAM), etc.
[0116] Memory can be used to store or cache various data files that need to be processed and / or communicated, as well as possible computer program instructions that the processor may execute. The processor reads and executes the computer program instructions stored in memory.
[0117] The processor described in this embodiment is connected to a transmission device for data transmission with external devices. The transmission device can be used to receive or send data via a network. Specific examples of the network described above may include wired or wireless networks provided by the communication provider of the electronic device. In one example, the transmission device includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0118] The processor described in this embodiment is connected to an input / output device for inputting or outputting information. The input / output device is used to input or output information; the input can be the raw time difference, and the output is the filtered time difference value.
[0119] Note that the above description is merely a preferred embodiment of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of the present invention, the scope of which is determined by the scope of the appended claims.
Claims
1. An adaptive filtering method for ultrasonic water meter flow measurement, characterized in that, include: S1. Obtain the raw measurement value of the time difference between upstream and downstream flight of the ultrasonic water meter; S2. Calculate the absolute difference between the current original measurement value and the previous original measurement value, and compare the absolute difference with the preset anomaly detection threshold. If the absolute difference is less than the preset anomaly detection threshold, proceed to step S3; if the absolute difference is greater than or equal to the anomaly detection threshold, proceed to step S4. S3. Determine that the current original measurement value is fluctuating normally, maintain the current filter coefficient or gradually increase the filter coefficient, and filter the output according to the first-order IIR filter algorithm; S4. Determine that the current original measurement value is an abnormal change, and use a preset minimum filter coefficient to perform a first-order IIR filter on the current original measurement value for output.
2. The adaptive filtering method for ultrasonic water meter flow measurement according to claim 1, wherein, The step of gradually increasing the filter coefficient in step S3 is specifically as follows: Set a continuous stability counter. Each time a normal fluctuation is determined, the continuous stability counter increments automatically. When the value of the continuous stability counter exceeds the preset stability counting threshold and the current filter coefficient is less than the preset upper limit of the filter coefficient, the filter coefficient is increased.
3. An adaptive filtering method for ultrasonic water meter flow measurement according to claim 2, characterized in that, After performing a first-order IIR filter on the current raw measurement value in step S4, the following further includes: The continuous stable counter is reset to zero, and the filter coefficient for the next time step is set to the preset recovery value.
4. The adaptive filtering method for ultrasonic water meter flow measurement according to claim 3, wherein, The step of setting the filter coefficient for the next moment to the preset recovery value further includes: during subsequent normal fluctuations, when the value of the continuous stable counter exceeds the preset stable counting threshold, gradually increasing the filter coefficient from the preset recovery value to the preset upper limit value of the filter coefficient.
5. The adaptive filtering method for ultrasonic water meter flow measurement according to claim 1, wherein, The preset anomaly detection threshold in step S2 also includes a low threshold and a high threshold.
6. The adaptive filtering method for ultrasonic water meter flow measurement according to claim 5, characterized in that, If the absolute difference is less than the low threshold, then step S3 is executed; if the absolute difference is greater than or equal to the low threshold and less than the high threshold, then the first smoothing coefficient is used for filtering; if the absolute difference is greater than or equal to the high threshold, then step S4 is executed.
7. The adaptive filtering method for ultrasonic water meter flow measurement according to claim 1, characterized in that, Following step S4, the following is also included: S5. After each filtering is completed, update the previous original measurement value to the current original measurement value, and store the current filtered output value for the next iteration; S6. Convert the filtered output value into an instantaneous flow rate value, and process the instantaneous flow rate value to obtain the cumulative flow rate value.
8. An adaptive filtering system for ultrasonic water meter flow measurement, used to execute the adaptive filtering method for ultrasonic water meter flow measurement according to any one of claims 1-7, the filtering system comprising a processor, characterized in that, The processor is equipped with: The acquisition module is used to acquire the raw measurement value of the time difference between upstream and downstream flight of the ultrasonic water meter; The comparison module is used to calculate the absolute difference between the current original measurement value and the previous original measurement value, and compare the absolute difference with the preset anomaly detection threshold. The steady-state processing module is used to determine that the current original measurement value is a normal fluctuation when the absolute difference is less than the preset anomaly detection threshold. It maintains the current filter coefficient or gradually increases the filter coefficient and performs filtering output according to the first-order IIR filtering algorithm. The anti-impact processing module is used to determine that the current original measurement value is an abnormal change when the absolute difference is greater than or equal to the anomaly detection threshold. It then uses a preset minimum filtering coefficient to perform a first-order IIR filter on the current original measurement value and outputs it.
9. An adaptive filtering system for ultrasonic water meter flow measurement according to claim 8, characterized in that, The processor is connected to a memory for storing data or instructions.
10. An adaptive filtering system for ultrasonic water meter flow measurement according to claim 8, characterized in that, The processor is connected to a transmission device for data transmission with external devices.
Citation Information
Patent Citations
First-order IIR low-pass filter
CN114826214A