Turbidity detection method, device, and storage medium
By sampling during the high-level period and performing moving filtering and smoothing, the problem of weak voltage signals and susceptibility to interference in turbidity meters is solved, thereby improving the stability and accuracy of turbidity detection results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 广州安捷制造有限公司
- Filing Date
- 2026-02-24
- Publication Date
- 2026-06-05
AI Technical Summary
Existing turbidimeters use weak voltage signals in infrared reflective measurements, which are easily affected by environmental interference, leading to AD value drift and fluctuations, thus affecting the stability of turbidimeter measurement results.
By sampling the raw AD value during the high-level period, moving filtering and smoothing are performed, including moving average, buffer queue filtering and preset time window smoothing, to ensure the stability of the AD value.
This improves the stability and accuracy of turbidity detection results and reduces the impact of environmental noise and signal interference on the measurement.
Smart Images

Figure CN122150192A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of water quality testing technology, and in particular to a turbidity detection method, equipment and storage medium. Background Technology
[0002] Currently, the turbidity detection process for liquids using turbidimeters is as follows: the turbidimeter directly or indirectly transmits infrared light to the liquid, converting the collected light signal into a voltage signal; this voltage signal is amplified by an operational amplifier and then input into a microcontroller to convert the analog voltage signal into a digital AD (Analog-to-Digital) value; finally, the turbidity value of the liquid is calculated based on the AD value using a curve fitting algorithm. However, when using an infrared reflection measurement scheme, the voltage signal obtained from the light signal conversion is inherently weak. Even after amplification, it still suffers from small amplitude and large fluctuations, and is easily affected by the environment. This causes the AD value acquired by the microcontroller to drift and fluctuate, resulting in poor stability of the turbidity measurement results. Summary of the Invention
[0003] The main objective of this application is to provide a turbidity detection method, device, and storage medium, which aims to improve the stability of turbidity detection results.
[0004] To achieve the above objectives, this application proposes a turbidity detection method, the method comprising:
[0005] Sampling is performed during the high-level period corresponding to the target voltage signal to obtain at least one original AD value during the high-level period, wherein the target voltage signal is obtained by converting the light signal reflected by the emitted light through the liquid under test; At least one original AD value during the high-level period is subjected to shift filtering according to a preset filtering period to obtain the filtered AD value for each filtering period. The filtered AD values for each filtering cycle are smoothed to obtain the target AD value; The turbidity value of the liquid to be tested is determined based on the target AD value.
[0006] In one embodiment, the step of performing a shift filter on at least one original AD value during the high-level period according to a preset filtering period to obtain a filtered AD value for each filtering period includes: Based on at least one original AD value during each high-level period, determine the average AD value during each high-level period; At the end of each filtering cycle, the average AD values are averaged to obtain a moving average. Based on the moving average and the preset filtering threshold, each of the average AD values is filtered to determine the filtered AD value for each filtering cycle based on the filtered average AD value.
[0007] In one embodiment, the step of averaging the average AD values at the arrival of each filtering cycle to obtain a moving average includes: The average AD value during each of the high-level periods is sequentially stored in a preset buffer queue; At the arrival of each filtering cycle, the average AD value currently stored in the buffer queue is averaged to obtain the moving average value.
[0008] In one embodiment, the step of filtering each of the average AD values based on the moving average and a preset filtering threshold, so as to determine the filtered AD value for each filtering period based on the filtered average AD value, includes: Determine the difference between each of the average AD values and the moving average; The offset rate is determined based on the difference and the moving average. If the offset rate is greater than the filtering threshold, the average AD value is removed from the buffer queue; If the offset rate is less than or equal to the filtering threshold, then the average AD value is retained; The average AD value in the filtered buffer queue is averaged to obtain the filtered AD value for each filtering cycle.
[0009] In one embodiment, smoothing the filtered AD values of each of the filtering periods to obtain the target AD value includes: The filtered AD values for each filtering cycle are sequentially stored in a preset sample pool; Each time a new filtered AD value is stored, a filtered AD value is selected from the sample pool according to the storage time sequence of the filtered AD value in the sample pool, and used as sample data for a preset time window. Based on the sample data in the preset time window, the currently stored filtered AD value in the sample pool is smoothed to obtain a smoothed AD value; The target AD value is determined based on each smoothed AD value.
[0010] In one embodiment, the determination of the amount of data currently stored in the sample pool and the window length of the preset time window; If the amount of data is less than or equal to the window length, then the mean of the currently stored filtered AD values in the sample pool is used as the smoothed AD value. If the amount of data is greater than the window length, then the deviation value or deviation ratio corresponding to each sample data is calculated based on the currently stored filtered AD value in the sample pool and the sample data in the preset time window; the smoothed AD value is determined based on the deviation value or deviation ratio of each sample data.
[0011] In one embodiment, determining the smoothed AD value based on the deviation value or deviation ratio of each sample data includes: If the deviation value of all sample data is less than the deviation threshold, or the deviation ratio of all sample data is less than the deviation ratio threshold, then the filtered AD value in the sample pool is replaced with the sample data of the preset time window, and the mean of each sample data is used as the smoothed AD value. If any sample data has a deviation value greater than or equal to the deviation threshold, or if any sample data has a deviation ratio greater than or equal to the deviation ratio threshold, then the mean of the currently stored filtered AD values in the sample pool is used as the smoothed AD value.
[0012] In one embodiment, sampling is performed during the high-level period corresponding to the target voltage signal to obtain at least one raw AD value during the high-level period, wherein the target voltage signal is obtained by converting the light signal reflected by the emitted light through the liquid under test, including: A drive signal with a preset duty cycle is generated according to a preset timing period to control the signal transmitting tube to emit light. The light signal reflected by the liquid under test is received by the signal receiver and converted into an initial voltage signal. The initial voltage signal is amplified by a signal amplifier to obtain the target voltage signal; Based on the preset timing period and the preset duty cycle, the high-level period of the drive signal is determined, and the target voltage signal is subjected to phase-locked sampling based on the high-level period to obtain at least one original AD value during the high-level period.
[0013] Furthermore, to achieve the above objectives, this application also proposes a turbidity detection device, which includes: A sampling module is used to sample during the high-level period corresponding to the target voltage signal to obtain at least one raw AD value during the high-level period, wherein the target voltage signal is obtained by converting the light signal reflected by the emitted light through the liquid under test; A filtering module is used to perform shift filtering on at least one original AD value during the high-level period according to a preset filtering cycle, so as to obtain the filtered AD value for each filtering cycle. A smoothing module is used to smooth the filtered AD values of each filtering cycle to obtain the target AD value; The determination module is used to determine the turbidity value of the liquid to be tested based on the target AD value.
[0014] In addition, to achieve the above objectives, this application also proposes a turbidity detection device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the turbidity detection method as described above.
[0015] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the turbidity detection method described above.
[0016] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the turbidity detection method described above.
[0017] This application provides a turbidity detection method, device, and storage medium. The turbidity detection method includes: sampling during a high-level period corresponding to a target voltage signal to obtain at least one raw AD value during the high-level period, wherein the target voltage signal is obtained by converting the light signal reflected by the liquid to be tested from emitted light; performing a moving filter on the at least one raw AD value during the high-level period according to a preset filtering period to obtain a filtered AD value for each filtering period; smoothing the filtered AD values for each filtering period to obtain a target AD value; and determining the turbidity value of the liquid to be tested based on the target AD value. By acquiring the raw AD value during the high-level period and performing a moving filter on the raw AD value according to a preset filtering period to reduce the data fluctuation of the AD value; and then smoothing each filtered AD value to ensure the stability of the AD value, thereby obtaining a stable and reliable target AD value; and finally fitting and calculating the target AD value to obtain the turbidity value of the liquid to be tested, the stability of the turbidity detection results is effectively improved. Attached Figure Description
[0018] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a flowchart illustrating the turbidity detection method of this application in Embodiment 1. Figure 2 This is a flowchart illustrating Embodiment 2 of the turbidity detection method of this application; Figure 3 This is a flowchart illustrating Embodiment 3 of the turbidity detection method of this application; Figure 4 This is a flowchart illustrating Embodiment 4 of the turbidity detection method of this application; Figure 5 This is a schematic diagram of signal sampling provided in an embodiment of this application; Figure 6 A complete flowchart of the turbidity detection method of this application is provided; Figure 7 This is a schematic diagram of the module structure of the turbidity detection device according to an embodiment of this application; Figure 8 This is a schematic diagram of the hardware operating environment involved in the turbidity detection method in this application embodiment.
[0021] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0022] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0023] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0024] It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device, big data service platform, or turbidity detection system capable of performing the above functions. The following description uses a turbidity detection system as an example to illustrate this embodiment and the subsequent embodiments.
[0025] Based on this, embodiments of this application provide a turbidity detection method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the turbidity detection method of this application in Embodiment 1.
[0026] Step S11: Sample during the high-level period corresponding to the target voltage signal to obtain at least one original AD value during the high-level period; It should be noted that the target voltage signal is obtained by converting the light signal reflected by the emitted light after passing through the liquid under test. More specifically, the generation process of the target voltage signal is as follows: a drive signal with a preset duty cycle is generated according to a preset timing period to control the signal emitting tube to emit light; the emitted light generates a reflected light signal after passing through the liquid under test. The reflected light signal is converted into a voltage signal by a signal receiver. The voltage signal is amplified by a signal amplifier to obtain the target voltage signal; the target voltage signal is used for subsequent AD value sampling.
[0027] In this embodiment, the high-level period refers to the time period during which the drive signal is high (usually logic 1 or a positive voltage). Since the duty cycle of the drive signal is fixed, the ratio of the high-level to low-level time of the signal is constant. This embodiment can use phase-locked loop (PLL) technology to synchronize the microcontroller's sampling with the high-level period of the drive signal. This allows the target voltage signal to be sampled at a preset sampling frequency during the high-level period to obtain the original AD value for that high-level period, while sampling stops during the low-level period.
[0028] Step S12: Perform a moving filter on at least one original AD value during the high-level period according to a preset filtering cycle to obtain the filtered AD value for each filtering cycle. It should be noted that moving average filtering refers to a method of filtering each average AD value based on the moving average of the current filtering cycle. The moving average is obtained by averaging the average AD values under this filtering cycle, and the average AD value is obtained by averaging at least one original AD value during the high-level period.
[0029] In this embodiment, for each high-level period, an average AD value corresponding to the high-level period is calculated based on at least one original AD value during the high-level period. For each filtering cycle, the average value among the average AD values corresponding to the current filtering cycle is used as a moving average. Then, based on the moving average of the current filtering cycle, the average AD values of the current filtering cycle are filtered. For example, for each average AD value, an offset rate is calculated based on the average AD value and the moving average, and the offset rate is used to determine whether to filter out the average AD value. In other feasible embodiments, a deviation value is calculated based on the average AD value and the moving average, and the deviation value is used to determine whether to filter out the average AD value. Further, an averaging operation is performed on the filtered average AD values, and the calculation result is used as the filtered AD value for the current filtering cycle.
[0030] Step S13: Smooth the filtered AD values of each filtering cycle to obtain the target AD value; It should be noted that while the filtered AD values show a relatively stable trend to some extent, the correlation between the data remains poor over time, making them prone to significant fluctuations. Therefore, smoothing is also applied to each filtered AD value to ensure data stability.
[0031] In one embodiment, a first-in, first-out (FIFO) sample pool is pre-set. The filtered AD values after filtering are sequentially stored in the sample pool. Each time a new filtered AD value is stored in the sample pool, the current filtered AD values in the sample pool are averaged to obtain a smoothed AD value. Further, the changing trends of each output smoothed AD value are analyzed. If the change in the smoothed AD value tends to be stable or the rate of change is lower than a preset rate of change threshold, then the current smoothed AD value is considered stable and reliable, thus obtaining the target AD value.
[0032] In another embodiment, a preset time window can also be set. The size of the preset time window can be flexibly configured according to the actual application scenario. In an exemplary embodiment, when the turbidimeter enters a new testing environment, assuming that one AD value is acquired per second, and the turbidimeter needs t seconds to reach a stable working state, the window size of the preset time window is configured as t. The preset time window is used to store the latest filtered AD value selected from the sample pool. That is, whenever a new filtered AD value is stored in the sample pool, the data in the preset time window needs to be updated. The window size of the preset time window is smaller than the capacity of the sample pool. More specifically, whenever a new filtered AD value is stored in the sample pool, the data in the preset time window needs to be updated. Further, based on the current filtered AD value in the sample pool, the sample mean is calculated, and then based on the difference between the data in the preset time window and the sample mean, it is determined whether the data in the preset time window is in a stable state. Further, if the data in the time window is determined to be stable, the mean corresponding to the data in the preset time window is used as the smoothed AD value; if the data in the time window is unstable, the sample mean is used as the smoothed AD value. Furthermore, the changing trends of each smoothed AD value are analyzed. If the change of the smoothed AD value tends to be stable or the rate of change is lower than the preset rate of change threshold, then the current smoothed AD value is considered stable and reliable, thus obtaining the target AD value.
[0033] Step S14: Determine the turbidity value of the liquid to be tested based on the target AD value.
[0034] It should be noted that the AD value corresponding to the standard turbidity solution is obtained through pre-sampling. Based on the known turbidity value of the standard turbidity solution and its corresponding AD value, a mapping relationship between the AD value and the turbidity value is established. Then, based on the target AD value and the mapping relationship, the turbidity value of the liquid to be tested can be calculated.
[0035] This embodiment, through the above-described scheme, includes: sampling during the high-level period corresponding to the target voltage signal to obtain at least one original AD value during the high-level period, wherein the target voltage signal is obtained by converting the light signal reflected by the emitted light through the liquid to be tested; performing a moving filter on the at least one original AD value during the high-level period according to a preset filtering cycle to obtain a filtered AD value for each filtering cycle; smoothing the filtered AD values for each filtering cycle to obtain a target AD value; and determining the turbidity value of the liquid to be tested based on the target AD value. By acquiring the original AD value during the high-level period and performing a moving filter on the original AD value according to a preset filtering cycle to reduce the data fluctuation of the AD value; further, smoothing each filtered AD value to ensure the stability of the AD value, thereby obtaining a stable and reliable target AD value; and finally, fitting and calculating the target AD value to obtain the turbidity value of the liquid to be tested, effectively improving the stability of the turbidity detection results.
[0036] In one feasible implementation, refer to Figure 2 , Figure 2 This is a flowchart illustrating a second embodiment of the turbidity detection method of this application; at least one original AD value during the high-level period is subjected to shift filtering according to a preset filtering cycle to obtain a filtered AD value for each filtering cycle, including: Step S21: Determine the average AD value for each high-level period based on at least one original AD value for each high-level period; In this embodiment, the following operation is performed for each high-level period: the original AD values collected during the high-level period are averaged to obtain the average AD value for the high-level period.
[0037] Step S22: When each filtering cycle arrives, the average AD values are averaged to obtain a moving average. In one feasible embodiment, the following operation is performed for each filtering cycle: the moving averages of each moving average under the current filtering cycle are averaged to obtain the moving average.
[0038] In other feasible embodiments, a buffer queue can be pre-set, and after the average AD value is calculated, it can be directly stored in the buffer queue. At the arrival of each filtering cycle, the average AD value currently stored in the buffer queue is averaged to obtain the moving average value.
[0039] Step S23: Based on the moving average and the preset filtering threshold, filter each of the average AD values to determine the filtered AD value for each filtering cycle based on the filtered average AD value. In this embodiment, based on the moving average, a preset filtering threshold, and each average AD value in the current filtering period, the data fluctuation of each average AD value is analyzed. Data filtering is then performed on each average AD value based on the data fluctuation. For example, based on the moving average and each average AD value, the offset rate or deviation value corresponding to each average AD value is calculated. Based on the offset rate or deviation value of the average AD value, combined with the filtering threshold, it is determined whether an average AD value needs to be removed. It should be noted that the filtered average AD values do not need to participate in the calculation of the next filtering period. Further, the average AD values after filtering are averaged to obtain the filtered AD value corresponding to that filtering period.
[0040] This embodiment calculates a moving average by averaging the average AD values currently stored in the buffer queue. Then, based on the moving average, the average AD values are filtered to reduce data fluctuations caused by environmental noise or signal interference, thereby effectively improving the overall stability of turbidity detection.
[0041] In one feasible implementation, the average AD values are filtered based on the moving average and a preset filtering threshold, so as to determine the filtered AD value for each filtering cycle based on the filtered average AD value, including... Step S31: Determine the difference between each of the average AD values and the moving average; Step S32: Determine the offset rate based on the difference and the moving average. Step S33: If the offset rate is greater than the filtering threshold, the average AD value is removed from the buffer queue. Step S34: If the offset rate is less than or equal to the filtering threshold, then the average AD value is retained; Step S35: Average the average AD values in the filtered buffer queue to obtain the filtered AD value for each filtering cycle.
[0042] It should be noted that the filtering threshold can be set based on actual test experience and design specifications. In this embodiment, for each average AD value: the difference between the average AD value and the moving average is calculated, and then the offset rate is calculated based on the difference and the moving average. The offset rate calculation formula is: Δp(i) = abs(iM) / M, where Δp(i) represents the offset rate corresponding to the average AD value, i represents the average AD value, and M represents the moving average. Further, the offset rate is compared with a preset filtering threshold. If the offset rate is greater than the preset filtering threshold, the average AD value is removed from the buffer queue, and the filtered average AD value does not need to participate in the calculation of the next filtering cycle; if the offset rate is less than or equal to the preset filtering threshold, the average AD value is retained.
[0043] Furthermore, the average AD value in the filtered buffer queue is averaged to obtain the filtered AD value for each filtering cycle.
[0044] This embodiment calculates the offset rate based on the average AD value and the moving average value, and then filters out the average AD value with an offset rate greater than the filtering threshold, which effectively improves the overall stability of turbidity detection. In addition, the moving average filtering algorithm is simple and efficient and does not significantly increase the computational burden of the system.
[0045] In one feasible implementation, refer to Figure 3 , Figure 3 This is a flowchart illustrating the turbidity detection method of this application in Embodiment 3; the filtered AD values of each filtering cycle are smoothed to obtain the target AD value, including: Step S41: The filtered AD values of each filtering cycle are sequentially stored in a preset sample pool; In this embodiment, a sample pool is pre-set, which is a first-in-first-out queue. The capacity of the sample pool can be set according to the actual situation. After filtering, the filtered AD values of each filtering cycle are stored in the sample pool.
[0046] Step S42: Each time a new filtered AD value is stored, a filtered AD value is selected from the sample pool according to the storage time sequence of the filtered AD value in the sample pool, and used as sample data for a preset time window. It should be noted that each time the turbidimeter completes a filtering process, it generates a new filtered AD value and appends it sequentially to the sample pool. When a new filtered AD value is added to the sample pool, the filtered AD value is selected from the last value in the pool backwards as the sample data for the preset time window, ensuring that the sample data for the preset time window always contains the latest filtered AD value in the sample pool. It should also be noted that the number of filtered AD values selected does not exceed the window size of the preset time window. In the initial stage, when the number of filtered AD values stored in the sample pool is small and cannot reach the window size, all filtered AD values in the sample pool are selected as the sample data for the preset time window.
[0047] Step S43: Based on the sample data in the preset time window, smooth the currently stored filtered AD value in the sample pool to obtain a smoothed AD value; It should be noted that in the initial stage, the sample pool is empty and needs to be gradually filled with data. To ensure that the system can respond quickly and provide initial estimates, in this embodiment, if the current data volume in the sample pool is less than or equal to the window length, the mean of the currently stored filtered AD values in the sample pool is used as the smoothed AD value. If the data volume is greater than the window length, the currently stored filtered AD values in the sample pool are averaged to obtain the sample mean; then, based on the sample mean and the sample data in the preset time window, the currently stored filtered AD values in the sample pool are smoothed to obtain the smoothed AD value.
[0048] Step S44: Determine the target AD value based on each smoothed AD value.
[0049] It should be noted that, based on the smoothed AD values output by the smoothing process, it is determined whether the convergence state has been reached. The convergence state means that the change of the smoothed AD value tends to be stable or the rate of change is lower than the preset rate of change threshold. Then, the converged smoothed AD value is used as the stable target AD value.
[0050] This embodiment smooths the filtered AD values currently stored in the sample pool based on sample data within a preset time window, obtaining smoothed AD values. This effectively suppresses short-term fluctuations in AD values, making the measurement data smoother over time and reducing noise interference. The converged smoothed AD value is then used as a stable target AD value. Subsequently, the turbidity value of the liquid being tested is accurately calculated based on this stable target AD value, effectively improving the stability of turbidity detection results.
[0051] In one feasible implementation, determining the target AD value based on the currently stored filtered AD values in the sample pool and the sample data in the preset time window includes: Step S51: If the amount of data is less than or equal to the window length, then the mean of the currently stored filtered AD values in the sample pool is used as the smoothed AD value. In this embodiment, if the amount of data is less than or equal to the window length, the mean of the currently stored filtered AD values in the sample pool is directly calculated to obtain the smoothed AD value.
[0052] Step S52: If the amount of data is greater than the window length, then calculate the deviation value or deviation ratio corresponding to each sample data according to the currently stored filtered AD value in the sample pool and the sample data in the preset time window; determine the smoothed AD value according to the deviation value or deviation ratio of each sample data.
[0053] In this embodiment, if the amount of data is greater than the window length, the average value of the currently stored filtered AD values in the sample pool is calculated, and the calculated mean is used as the sample mean. Based on the sample mean and the sample data in the preset time window, the deviation value or deviation ratio of the sample data is calculated. Based on the deviation value or deviation ratio, it is determined whether the sample data in the preset time window is in a stable state. Further, if the deviation value of all sample data is less than a deviation threshold, or the deviation ratio of all sample data is less than a deviation ratio threshold, it is proven that the sample data in the time window is in a stable state. Then, the filtered AD values in the sample pool are replaced with the sample data of the preset time window, and the mean value corresponding to the data in the preset time window is used as the smoothed AD value. If the deviation value of any sample data is greater than or equal to the deviation threshold, or the deviation ratio of any sample data is greater than or equal to the deviation ratio threshold, it is proven that the data in the time window is unstable. The sample pool data is kept unchanged, and the sample mean is used as the smoothed AD value.
[0054] It should be noted that in low-turbidity scenarios, the water contains fewer suspended particles, resulting in smaller fluctuations in the AD value, and the system is more sensitive to deviations. Conversely, in high-turbidity scenarios, the water contains more suspended particles, leading to larger variations in the AD value, and the system is more sensitive to deviation ratios. Therefore, in this embodiment, the turbidity of the liquid being tested can also be determined based on the currently stored filtered AD values in the sample pool. For example, if the average of the currently stored filtered AD values in the sample pool is greater than a preset AD threshold, the liquid being tested is determined to be in a high-turbidity state.
[0055] Furthermore, for low-turbidity scenarios: if the deviation value of all sample data is less than the deviation threshold, it indicates that the sample data within the preset time window is relatively stable. Therefore, the filtered AD value in the sample pool is replaced with the sample data from the preset time window, and the updated sample pool data is averaged to obtain a smoothed AD value. This embodiment, by clearing the sample pool and replacing it with data from the time window, can quickly converge to the new measurement interval. Additionally, if the deviation value of any sample data is greater than or equal to the deviation threshold, it indicates that the sample data within the preset time window has significant fluctuations. The sample pool data is kept unchanged, and the sample mean is used as the smoothed AD value. The deviation threshold can be set according to actual conditions, for example, set to 10.
[0056] For high-turbidity scenarios: If the deviation ratio of all sample data is less than the deviation ratio threshold, it indicates that the sample data within the preset time window is relatively stable. The filtered AD values in the sample pool are replaced with the sample data from the preset time window, and the updated sample pool data is averaged to obtain a smoothed AD value. Conversely, if the deviation ratio of any sample data is greater than or equal to the deviation ratio threshold, it indicates that the sample data within the preset time window exhibits significant fluctuations. The sample pool data is kept unchanged, and the sample mean is used as the smoothed AD value. The deviation ratio threshold can be set according to actual conditions, for example, to 0.1.
[0057] This embodiment ensures data stability by smoothing the currently stored filtered AD values in the sample pool. In addition, the smoothing algorithm is simple and efficient. When the turbidity of the test solution changes, the system can quickly converge the calculation and adjust the output stable AD value in a timely manner to ensure the real-time performance and accuracy of turbidity measurement.
[0058] In one feasible implementation, refer to Figure 4 , Figure 4 This is a flowchart illustrating Embodiment 4 of the turbidity detection method of this application; sampling is performed during the high-level period corresponding to the target voltage signal to obtain at least one raw AD value during the high-level period, wherein the target voltage signal is obtained by converting the light signal reflected by the emitted light after passing through the liquid to be tested, including: Step S61: Generate a drive signal with a preset duty cycle according to a preset timing period to control the signal transmitting tube to emit light; Step S62: Receive the light signal reflected by the liquid under test from the emitted light through a signal receiver, and convert the light signal into an initial voltage signal; It should be noted that the emitted light is an infrared wave, and the wavelength of the infrared wave can be set according to actual conditions, for example, the wavelength can be set to 875nm. The preset timing period and preset duty cycle are both set according to actual conditions and are not specifically limited here. The preset duty cycle refers to the proportion of the time the signal emitting tube is in the energized and emitting state relative to the preset timing period. In this embodiment, a PWM drive signal with a preset duty cycle is generated according to the preset timing period. The PWM drive signal is used to drive the signal emitting tube to emit emitted light. The emitted light is reflected by the liquid to be tested, and the reflected light signal is received into the signal receiver of the turbidimeter through a filter. The signal receiver converts the received light signal into an initial voltage signal.
[0059] Step S63: The initial voltage signal is amplified by a signal amplifier to obtain the target voltage signal; In this embodiment, the initial voltage signal is linearly amplified by a signal amplifier in the turbidimeter by a preset factor to obtain the target voltage signal.
[0060] Step S64: Determine the high-level period of the drive signal according to the preset timing period and the preset duty cycle, so as to perform phase-locked sampling on the target voltage signal according to the high-level period and obtain at least one original AD value during the high-level period.
[0061] In this embodiment, the high-level period of the drive signal is determined according to the preset timing period and the preset duty cycle. Phase-locked loop (PLL) technology is used to synchronize the sampling of the turbidimeter's analog-to-digital converter (ADC) with the high-level period of the drive signal, thereby accurately determining the start and end times of the high-level period. Based on the start time of the high-level period, the ADC sampling is initiated to convert the analog target voltage signal into a digital raw AD value. Sampling stops at the end time of the high-level period. (Refer to...) Figure 5 , Figure 5 This is a signal sampling diagram provided in an embodiment of the present application. During the sampling process, the analog-to-digital converter will sample according to a preset sampling frequency to obtain each original AD value sampled during each high-level period.
[0062] This embodiment uses phase-locked acquisition technology for sampling, filtering out channel background voltage and interference caused by phase shift, improving signal stability and anti-interference ability, thereby accurately acquiring digital signals that are strongly correlated with the turbidity of the liquid under test, and effectively improving the overall stability of turbidity detection.
[0063] In one feasible implementation, refer to Figure 6 , Figure 6This is a complete flowchart of the turbidity detection method provided in this application. PWM control refers to generating a PWM drive signal with a preset duty cycle according to a preset timing period to control the signal transmitter to emit light. Signal reception refers to receiving the light signal reflected by the liquid under test through a signal receiver, converting the light signal into an initial voltage signal, and amplifying the initial voltage signal through a signal amplifier to obtain the target voltage signal. AD phase-locked acquisition refers to determining the high-level period of the drive signal according to the preset timing period and preset duty cycle, using phase-locked loop technology to synchronize the sampling of the turbidity meter's analog-to-digital converter with the high-level period of the drive signal, and then starting the analog-to-digital converter sampling according to the start time of the high-level period to convert the analog target voltage signal into a digital raw AD value. Sampling stops at the end time of the high-level period, thus obtaining each raw AD value sampled for each high-level period. Moving average processing refers to performing moving average filtering on at least one raw AD value of the high-level period according to a preset filtering period to obtain a filtered AD value for each filtering period. Historical dynamic parameter calibration refers to smoothing the filtered AD values for each filtering period. Obtaining a stable AD value refers to determining a stable target AD value based on the various AD values output through smoothing. The output turbidity value refers to the turbidity value of the liquid being tested, calculated by fitting the target AD value, effectively improving the stability of turbidity detection results.
[0064] It should be noted that the examples in the figure are only for understanding this application and do not constitute a limitation on the turbidity detection method of this application. Any simple modifications based on this technical concept are within the protection scope of this application.
[0065] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0066] This application also provides a turbidity detection device, please refer to... Figure 7 , Figure 7 This is a schematic diagram of the module structure of the turbidity detection device according to an embodiment of this application; the turbidity detection device includes: The sampling module 71 is used to sample during the high-level period corresponding to the target voltage signal to obtain at least one original AD value during the high-level period, wherein the target voltage signal is obtained by converting the light signal reflected by the emitted light through the liquid under test; The filtering module 72 is used to perform a shift filtering process on at least one original AD value during the high-level period according to a preset filtering period to obtain the filtered AD value for each filtering period. The smoothing module 73 is used to smooth the filtered AD value of each filtering cycle to obtain the target AD value; The determination module 74 is used to determine the turbidity value of the liquid to be tested based on the target AD value.
[0067] The turbidity detection device provided in this application, employing the turbidity detection method in the above embodiments, can solve the technical problems mentioned in the background art. Compared with the prior art, the beneficial effects of the turbidity detection device provided in this application are the same as those of the turbidity detection method provided in the above embodiments, and other technical features in the turbidity detection device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0068] Filter module 72 is also used for: Based on at least one original AD value during each high-level period, determine the average AD value during each high-level period; At the end of each filtering cycle, the average AD values are averaged to obtain a moving average. Based on the moving average and the preset filtering threshold, each of the average AD values is filtered to determine the filtered AD value for each filtering cycle based on the filtered average AD value.
[0069] Filter module 72 is also used for: The average AD value during each of the high-level periods is sequentially stored in a preset buffer queue; At the arrival of each filtering cycle, the average AD value currently stored in the buffer queue is averaged to obtain the moving average value.
[0070] Filter module 72 is also used for: Determine the difference between each of the average AD values and the moving average; The offset rate is determined based on the difference and the moving average. If the offset rate is greater than the filtering threshold, the average AD value is removed from the buffer queue; If the offset rate is less than or equal to the filtering threshold, then the average AD value is retained; The average AD value in the filtered buffer queue is averaged to obtain the filtered AD value for each filtering cycle.
[0071] The smoothing module 73 is also used for: The filtered AD values for each filtering cycle are sequentially stored in a preset sample pool; Each time a new filtered AD value is stored, a filtered AD value is selected from the sample pool according to the storage time sequence of the filtered AD value in the sample pool, and used as sample data for a preset time window. Based on the sample data in the preset time window, the currently stored filtered AD value in the sample pool is smoothed to obtain a smoothed AD value; The target AD value is determined based on each smoothed AD value.
[0072] The smoothing module 73 is also used for: Determine the amount of data currently stored in the sample pool, and the window length of the preset time window; If the amount of data is less than or equal to the window length, then the mean of the currently stored filtered AD values in the sample pool is used as the smoothed AD value. If the amount of data is greater than the window length, then the deviation value or deviation ratio corresponding to each sample data is calculated based on the currently stored filtered AD value in the sample pool and the sample data in the preset time window; the smoothed AD value is determined based on the deviation value or deviation ratio of each sample data.
[0073] The smoothing module 73 is also used for: If the deviation value of all sample data is less than the deviation threshold, or the deviation ratio of all sample data is less than the deviation ratio threshold, then the filtered AD value in the sample pool is replaced with the sample data of the preset time window, and the mean of each sample data is used as the smoothed AD value. If any sample data has a deviation value greater than or equal to the deviation threshold, or if any sample data has a deviation ratio greater than or equal to the deviation ratio threshold, then the mean of the currently stored filtered AD values in the sample pool is used as the smoothed AD value.
[0074] The sampling module 71 is also used for: A drive signal with a preset duty cycle is generated according to a preset timing period to control the signal transmitting tube to emit light. The light signal reflected by the liquid under test is received by the signal receiver and converted into an initial voltage signal. The initial voltage signal is amplified by a signal amplifier to obtain the target voltage signal; Based on the preset timing period and the preset duty cycle, the high-level period of the drive signal is determined, and the target voltage signal is subjected to phase-locked sampling based on the high-level period to obtain at least one original AD value during the high-level period.
[0075] This application provides a turbidity detection device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the turbidity detection method in Embodiment 1 above.
[0076] The following is for reference. Figure 8 , Figure 8 This is a schematic diagram of the hardware operating environment involved in the turbidity detection method in this application embodiment. The turbidity detection device in this application embodiment may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), vehicle terminals (such as vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 8 The turbidity detection device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments of this application.
[0077] like Figure 8 As shown, the turbidity detection device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory 1002 or a program loaded from a storage device 1003 into a random access memory 1004. The random access memory 1004 also stores various programs and data required for the operation of the turbidity detection device. The processing unit 1001, the read-only memory 1002, and the random access memory 1004 are interconnected via a bus 1005. An input / output interface 1006 is also connected to the bus. Typically, the following systems can be connected to the input / output interface 1006: input devices 1007 including, for example, a touch screen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 1003 including, for example, magnetic tape, hard disk, etc.; and communication devices 1009. The communication device 1009 allows the turbidity detection device to communicate wirelessly or wiredly with other devices to exchange data. Although the figure shows turbidity detection devices with various systems, it should be understood that it is not required to implement or possess all of the systems shown. More or fewer systems may be implemented alternatively.
[0078] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from read-only memory 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0079] The turbidity detection device provided in this application, employing the turbidity detection method in the above embodiments, can solve the technical problems mentioned in the background art. Compared with the prior art, the beneficial effects of the turbidity detection device provided in this application are the same as those of the turbidity detection method provided in the above embodiments, and other technical features of the turbidity detection device are the same as those disclosed in the method of the previous embodiment, and will not be repeated here.
[0080] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0081] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0082] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the turbidity detection method in the above embodiments.
[0083] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0084] The aforementioned computer-readable storage medium may be included in the turbidity detection device; or it may exist independently and not assembled into the turbidity detection device.
[0085] The aforementioned computer-readable storage medium carries one or more programs. When these programs are executed by the turbidity detection device, the turbidity detection device: samples during the high-level period corresponding to the target voltage signal to obtain at least one raw AD value during the high-level period, wherein the target voltage signal is obtained by converting the light signal reflected by the emitted light through the liquid to be tested; performs shift filtering on the at least one raw AD value during the high-level period according to a preset filtering period to obtain a filtered AD value for each filtering period; smooths the filtered AD values for each filtering period to obtain a target AD value; and determines the turbidity value of the liquid to be tested based on the target AD value. A stable and reliable target AD value is obtained through filtering and smoothing; finally, a fitting calculation is performed based on the target AD value to obtain the turbidity value of the liquid to be tested, effectively improving the overall stability of turbidity detection.
[0086] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0087] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0088] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0089] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described turbidity detection method, and is able to solve the technical problems described in the background art. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the turbidity detection method provided in the above embodiments, and will not be repeated here.
[0090] This application provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the turbidity detection method described above.
[0091] The computer program product provided in this application can solve the technical problems described in the background section. Compared with the prior art, the beneficial effects of the computer program product provided in the embodiments of this application are the same as the beneficial effects of the turbidity detection method provided in the above embodiments, and will not be repeated here.
[0092] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.
Claims
1. A turbidity detection method, characterized in that, include: Sampling is performed during the high-level period corresponding to the target voltage signal to obtain at least one original AD value during the high-level period, wherein the target voltage signal is obtained by converting the light signal reflected by the emitted light through the liquid under test; At least one original AD value during the high-level period is subjected to shift filtering according to a preset filtering period to obtain the filtered AD value for each filtering period. The filtered AD values for each filtering cycle are smoothed to obtain the target AD value; The turbidity value of the liquid to be tested is determined based on the target AD value.
2. The turbidity detection method as described in claim 1, characterized in that, The step of performing a shift filter on at least one original AD value during the high-level period according to a preset filtering period to obtain a filtered AD value for each filtering period includes: Based on at least one original AD value during each high-level period, determine the average AD value during each high-level period; At the end of each filtering cycle, the average AD values are averaged to obtain a moving average. Based on the moving average and the preset filtering threshold, each of the average AD values is filtered to determine the filtered AD value for each filtering cycle based on the filtered average AD value.
3. The turbidity detection method as described in claim 2, characterized in that, The step of averaging the average AD values at the end of each filtering cycle to obtain a moving average includes: The average AD value during each of the high-level periods is sequentially stored in a preset buffer queue; At the arrival of each filtering cycle, the average AD value currently stored in the buffer queue is averaged to obtain the moving average value.
4. The turbidity detection method as described in claim 3, characterized in that, The step of filtering each average AD value based on the moving average and a preset filtering threshold, to determine the filtered AD value for each filtering period based on the filtered average AD value, includes: Determine the difference between each of the average AD values and the moving average; The offset rate is determined based on the difference and the moving average. If the offset rate is greater than the filtering threshold, the average AD value is removed from the buffer queue; If the offset rate is less than or equal to the filtering threshold, then the average AD value is retained; The average AD value in the filtered buffer queue is averaged to obtain the filtered AD value for each filtering cycle.
5. The turbidity detection method as described in claim 1, characterized in that, The step of smoothing the filtered AD values of each filtering cycle to obtain the target AD value includes: The filtered AD values for each filtering cycle are sequentially stored in a preset sample pool; Each time a new filtered AD value is stored, a filtered AD value is selected from the sample pool according to the storage time sequence of the filtered AD value in the sample pool, and used as sample data for a preset time window. Based on the sample data in the preset time window, the currently stored filtered AD value in the sample pool is smoothed to obtain a smoothed AD value; The target AD value is determined based on each smoothed AD value.
6. The turbidity detection method as described in claim 5, characterized in that, The step of smoothing the currently stored filtered AD values in the sample pool based on the sample data in the preset time window to obtain smoothed AD values includes: Determine the amount of data currently stored in the sample pool, and the window length of the preset time window; If the amount of data is less than or equal to the window length, then the mean of the currently stored filtered AD values in the sample pool is used as the smoothed AD value. If the amount of data is greater than the window length, then the deviation value or deviation ratio corresponding to each sample data is calculated based on the currently stored filtered AD value in the sample pool and the sample data in the preset time window; the smoothed AD value is determined based on the deviation value or deviation ratio of each sample data.
7. The turbidity detection method as described in claim 6, characterized in that, Determining the smoothed AD value based on the deviation value or deviation ratio of each sample data includes: If the deviation value of all sample data is less than the deviation threshold, or the deviation ratio of all sample data is less than the deviation ratio threshold, then the filtered AD value in the sample pool is replaced with the sample data of the preset time window, and the mean of each sample data is used as the smoothed AD value. If any sample data has a deviation value greater than or equal to the deviation threshold, or if any sample data has a deviation ratio greater than or equal to the deviation ratio threshold, then the mean of the currently stored filtered AD values in the sample pool is used as the smoothed AD value.
8. The turbidity detection method as described in claim 1, characterized in that, The sampling is performed during the high-level period corresponding to the target voltage signal to obtain at least one raw AD value during the high-level period, wherein the target voltage signal is obtained by converting the light signal reflected by the emitted light through the liquid under test, including: A drive signal with a preset duty cycle is generated according to a preset timing period to control the signal transmitting tube to emit light. The light signal reflected by the liquid under test is received by the signal receiver and converted into an initial voltage signal. The initial voltage signal is amplified by a signal amplifier to obtain the target voltage signal; Based on the preset timing period and the preset duty cycle, the high-level period of the drive signal is determined, and the target voltage signal is subjected to phase-locked sampling based on the high-level period to obtain at least one original AD value during the high-level period.
9. A turbidity detection device, characterized in that, The turbidity detection device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the turbidity detection method as described in any one of claims 1 to 8.
10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the turbidity detection method as described in any one of claims 1 to 8.