A self-calibration method and system for air quality sensors based on time series analysis
By using a self-calibration method based on time series analysis, air quality sensor data is collected and segmented, statistical parameters are calculated and compared, drift is dynamically identified and sensor output is adjusted, solving the problems of high manpower and material resources and complexity in traditional air quality sensor calibration, and realizing real-time self-calibration and stability of air quality monitoring.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI LANNOVO INTELLIGENT TECH CO LTD
- Filing Date
- 2025-10-09
- Publication Date
- 2026-05-26
AI Technical Summary
Traditional air quality sensors develop systematic deviations between measured values and actual concentrations due to aging and environmental corrosion during long-term operation. Existing calibration methods are labor-intensive and cannot achieve real-time calibration. Complex model training and additional hardware increase system complexity and cost, and cannot effectively distinguish between sensor drift and normal fluctuations caused by environmental factors.
By using a self-calibration method based on time series analysis, air quality measurements are collected to form time series data, which is then divided into continuous time periods. Statistical parameters are calculated and compared with historical parameters to dynamically identify significant drift. The sensor output circuit is then adjusted using calibration coefficients to achieve autonomous closed-loop calibration.
It achieves long-term reliability and stability of air quality monitoring data that is efficient, low-cost, and real-time, avoiding reliance on manual intervention and complex models, and accurately identifies and automatically corrects sensor drift.
Smart Images

Figure CN121208259B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of environmental monitoring technology, specifically relating to a self-calibration method and system for air quality sensors based on time series analysis. Background Technology
[0002] Traditional air quality sensors, during long-term continuous operation, experience a gradual decline or drift in the performance of their sensing elements due to aging, environmental corrosion, or changes in physicochemical properties, leading to systematic deviations between measured values and actual concentrations. Currently, the common approach to addressing this issue relies on periodic manual calibration, where professionals use standard reference equipment to perform comparative measurements and adjust sensor parameters on-site. This method is not only resource-intensive but also fails to provide real-time deviation correction, making it difficult to guarantee the reliability of sensor data within the calibration cycle.
[0003] Furthermore, some improvement schemes attempt to assist in correction by introducing other data sources or complex predictive models, such as fusing data from multiple homogeneous or heterogeneous sensors or establishing mathematical models of environmental parameters and sensor drift. However, these methods often rely on the reliability of additional hardware, increasing the complexity and cost of the system. Moreover, model training and updates require a large amount of prior data and computational resources, posing challenges to maintainability and adaptability in practical deployments.
[0004] Existing technologies also include automated methods based on simple thresholds or fixed-period triggering for calibration. However, these methods typically cannot effectively distinguish between the sensor's true performance drift and normal fluctuations caused by environmental factors, easily leading to miscalibration or untimely calibration. They lack in-depth analysis of the inherent temporal patterns of sensor output data and struggle to intelligently capture slowly evolving, gradual drift trends, thus limiting their effectiveness in applications requiring long-term stable monitoring. Summary of the Invention
[0005] According to a first aspect of the present invention, the present invention claims protection for a self-calibration method for an air quality sensor based on time series analysis, comprising the following steps:
[0006] S1: During normal operation of the sensor, air quality measurements are collected at fixed time intervals to form time series data;
[0007] S2: Divide the time series data into consecutive time periods, each time period containing a predetermined number of measurements;
[0008] S3: For each time period, calculate the statistical parameters of the measured values within that time period, including the average value and the range of fluctuation;
[0009] S4: Compare the statistical parameters of the current time period with the statistical parameters of one or more previous time periods to determine the trend of the statistical parameters;
[0010] S5: Based on the aforementioned trend, determine whether the sensor has experienced significant drift;
[0011] S6: When a significant drift is detected, a correction coefficient is calculated based on the trend of change and the correction coefficient is applied to the output circuit of the sensor to adjust the measured value;
[0012] Furthermore, step S2 also includes:
[0013] The segmentation operation is achieved by setting a sliding window of fixed length, with each window containing the same number of measurements, and the windows are continuous and do not overlap.
[0014] The predetermined quantity is set based on sensor stability and the frequency of environmental changes;
[0015] The length of the time period is dynamically adjusted according to the type of sensor and environmental conditions, wherein the environmental conditions include at least one of temperature and humidity.
[0016] During dynamic adjustment, the ambient temperature and humidity are monitored, and the time period is automatically shortened when the temperature or humidity changes exceed the preset range.
[0017] The time period length can be adjusted by querying a predefined mapping table of environmental conditions and length.
[0018] Furthermore, step S3 also includes:
[0019] S31: Obtain all measured values within the current time period and arrange them in chronological order. Extract the measured values from the data buffer according to the timestamp, ensuring that the order is consistent with the acquisition time. Store the arranged values as a temporary array.
[0020] S32, calculate the arithmetic mean of the arranged measurements. The arithmetic mean is obtained by summing all the measurements and then dividing by the number of measurements. When summing, the temporary array is traversed and all values are accumulated. When dividing by the number, integer division or floating-point operation is used.
[0021] S33, find the minimum and maximum values among the measured values, and calculate the difference between the maximum and minimum values as the range to represent the fluctuation range. When finding the minimum and maximum values, traverse the temporary array, compare each value, and record the current minimum and maximum. The range is calculated as the maximum value minus the minimum value.
[0022] S34, Simultaneously calculate the median value of the measured values. The median value is obtained by sorting the measured values by size and taking the center value. The measured values are arranged in ascending order. If the number of measured values is odd, the value of the middle position after sorting is taken. If it is even, the arithmetic mean of the two middle values is taken.
[0023] S35, based on the arithmetic mean, range and median, a comprehensive statistical parameter is formed by combining them. When combining, the arithmetic mean, range and median are weighted and summed according to a predetermined weight.
[0024] S36, record the comprehensive statistical parameters for subsequent comparison. When recording, store the comprehensive statistical parameters together with the timestamp in non-volatile memory and retain records from multiple recent time periods.
[0025] Furthermore, step S4 also includes:
[0026] S41, Select the most recent M time periods as the reference group, where M is an integer greater than 1. The value of M is set according to the stability of the sensor's historical data. Select the data of the M consecutive time periods before the current time period from the historical records.
[0027] S42, calculate the average value of the statistical parameters for each time period in the reference group as the baseline statistical parameters. When calculating, add the statistical parameters for each time period in the reference group and then divide by M to obtain the baseline value.
[0028] S43, calculate the absolute deviation between the statistical parameters of the current time period and the benchmark statistical parameters, wherein the absolute deviation is obtained by calculating the absolute value of the difference between the current statistical parameters and the benchmark value;
[0029] S44, calculate the standard deviation of the statistical parameters in the reference group as the fluctuation benchmark. The standard deviation is calculated by the difference between each reference statistical parameter and the benchmark value, then the average of the squares of these differences is calculated, and finally the square root of the average value is taken as an approximation.
[0030] S45, compare the absolute deviation with the threshold obtained by multiplying the fluctuation benchmark by a predetermined coefficient, set the predetermined coefficient based on experience, and calculate the threshold as the fluctuation benchmark multiplied by the predetermined coefficient;
[0031] S46, if the absolute deviation exceeds the threshold, the change trend is determined to be a significant change, and the direction and magnitude of the change trend are recorded. When comparing, a numerical comparator is used. If the absolute deviation is greater than the threshold, a flag is triggered to indicate a significant change. The direction is recorded by the positive or negative value of the difference between the current statistical parameter and the benchmark value. A positive value indicates an upward trend, and a negative value indicates a downward trend. The magnitude is recorded as the absolute value of the difference.
[0032] Furthermore, step S5 also includes:
[0033] Check whether the trend of change exceeds the predetermined number of times it exceeds the tolerance value, where the tolerance value is set based on the variability of historical statistical parameters;
[0034] The tolerance value is adjusted by calculating the average fluctuation range of historical statistical parameters. If the trend of a series of consecutive predetermined time periods exceeds the tolerance value, it is considered a drift.
[0035] Furthermore, step S6 also includes:
[0036] Based on the magnitude and direction of the trend, the correction coefficient is determined by looking up a table, where the table pre-stores the mapping relationship between the trend magnitude and the correction coefficient.
[0037] When looking up the table, the trend amplitude is divided into multiple intervals, and each interval corresponds to a correction coefficient; when the direction is positive, the correction coefficient is negative, and when the direction is negative, the correction coefficient is positive; the table content is pre-filled based on sensor calibration experiments.
[0038] Furthermore, step S6 also includes:
[0039] The correction coefficients are converted into voltage or current signals, and the bias voltage or gain of the sensor is adjusted by a digital-to-analog converter.
[0040] During conversion, the correction factor is multiplied by the reference voltage value to obtain the target voltage;
[0041] The digital-to-analog converter converts the digital target voltage into an analog signal, which is then output to the bias pin of the sensor to change the operating point.
[0042] Furthermore, after step S6, the following is also included:
[0043] To verify the correction effect, the changes in statistical parameters are monitored for a period of time after correction. If the trend of change does not return to normal, steps S3 to S6 are repeated.
[0044] During verification, after calibration, the statistical parameters for the next time period are monitored. If the deviation from the baseline value still exceeds half of the tolerance value, it is determined that the system has not returned to normal and calibration is performed again.
[0045] Furthermore, step S1 also includes:
[0046] The fixed time interval is set according to the response characteristics of the sensor; for sensors with slow response, a longer interval is set.
[0047] For fast-response sensors, set short intervals; collect measurements including particulate matter concentration or gas concentration, and store them in real time in a circular data buffer to ensure that the data is arranged in chronological order.
[0048] Furthermore, in step S3, the fluctuation range is also obtained by calculating the variance or coefficient of variation of the measured values, where the coefficient of variation is the ratio of the standard deviation to the mean.
[0049] When calculating variance, first calculate the square of the difference between each measurement and the mean, and then calculate the mean.
[0050] The coefficients of variation are obtained by dividing the variance by the mean.
[0051] According to a second aspect of the present invention, the present invention claims protection for a self-calibration system for an air quality sensor based on time series analysis, comprising:
[0052] One or more processors;
[0053] A memory storing one or more programs, which, when executed by one or more processors, enable the one or more processors to implement the aforementioned self-calibration method for air quality sensors based on time series analysis.
[0054] This invention discloses a self-calibration method and system for air quality sensors based on time series analysis. It continuously collects measurements during normal sensor operation to form time series data, divides this data into consecutive time periods, and calculates the statistical parameters for each time period. By dynamically comparing the current parameters with historical parameter sequences, it intelligently identifies significant trends in statistical characteristics to determine whether a fundamental drift has occurred. Once drift is confirmed, a pre-set calibration table is consulted based on the trend amplitude and direction to obtain calibration coefficients. Finally, the gain or bias voltage of the sensor's output circuit is adjusted via a digital-to-analog converter to achieve autonomous closed-loop calibration. This invention utilizes only the sensor's own historical data for analysis, eliminating the need for external reference equipment or complex model training. It achieves efficient, low-cost, and real-time online self-calibration, significantly improving the long-term reliability and stability of air quality monitoring data. Attached Figure Description
[0055] Figure 1 A flowchart illustrating the workflow of a time-series analysis-based self-calibration method for air quality sensors, as claimed in an embodiment of the present invention.
[0056] Figure 2 This is a second flowchart of a self-calibration method for an air quality sensor based on time series analysis, as claimed in an embodiment of the present invention.
[0057] Figure 3 The third flowchart illustrates a self-calibration method for an air quality sensor based on time series analysis, as claimed in an embodiment of the present invention. Detailed Implementation
[0058] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0059] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0060] According to the first embodiment of the present invention, referring to Figure 1 This invention claims protection for a self-calibration method for air quality sensors based on time series analysis, comprising the following steps:
[0061] S1: During normal operation of the sensor, air quality measurements are collected at fixed time intervals to form time series data;
[0062] S2: Divide the time series data into consecutive time periods, each time period containing a predetermined number of measurements;
[0063] S3: For each time period, calculate the statistical parameters of the measured values within that time period, including the average value and the range of fluctuation;
[0064] S4: Compare the statistical parameters of the current time period with the statistical parameters of one or more previous time periods to determine the trend of the statistical parameters;
[0065] S5: Based on the aforementioned trend, determine whether the sensor has experienced significant drift;
[0066] S6: When a significant drift is determined to have occurred, a correction coefficient is calculated based on the trend of change and the correction coefficient is applied to the output circuit of the sensor to adjust the measured value.
[0067] In this embodiment, the air quality sensor is installed indoors to continuously monitor PM2.5 concentration. During normal operation, the sensor may experience measurement distortion due to aging, environmental interference, or component drift. The self-calibration method automatically detects and corrects this drift through time series analysis, without manual intervention. The embodiment simulates the process of the sensor transitioning from a normal state to drift, and then recovering through calibration.
[0068] During normal operation, the sensor collects air quality measurements at fixed time intervals. The fixed time interval is set based on the sensor's response characteristics: for the PM2.5 sensor used in this embodiment, which has a slow response, a longer interval is set, such as collecting measurements once per minute. The collected measurements (e.g., PM2.5 concentration) are stored in real-time in a circular data buffer. The buffer size is set to accommodate a sufficient number of data points to ensure that the data is arranged in chronological order and does not overflow. In experimental testing, the sensor collects data under stable conditions, with initial measurements showing minimal fluctuations, simulating normal operation.
[0069] The time-series data was segmented into consecutive time intervals, each containing a predetermined number of measurements. Segmentation was achieved using fixed-length sliding windows: each window contained the same number of measurements (e.g., 60 measurements representing one hour of data), and the windows were consecutive and non-overlapping. The predetermined number was set based on sensor stability and the frequency of environmental changes; in testing, a window size of 60 was chosen to balance response speed and stability. Experiments showed that a window that was too small resulted in sensitivity to noise, while a window that was too large delayed drift detection.
[0070] For each time period, statistical parameters of the measurements within that period are calculated, including the average and the range of fluctuation. The average is calculated by summing all measurements within the window and dividing by the number of measurements, with the result rounded to two decimal places. The range of fluctuation is obtained by calculating the range (the difference between the maximum and minimum values). During testing, the average and range remain relatively stable under normal conditions; when sensor drift occurs, the average gradually shifts, and the range may widen.
[0071] The statistical parameters of the current time period are compared with those of one or more previous time periods. Specifically, five consecutive time periods preceding the current time period are selected as a reference group, and the average of the statistical parameters of the reference group is calculated as the baseline. Then, the difference between the current statistical parameter and the baseline is calculated, and the sign and magnitude of the difference are analyzed: a positive difference indicates an upward trend, a negative difference indicates a downward trend, and the absolute value of the difference indicates the magnitude of the trend. During the test, when simulating sensor drift, the difference remains positive and the magnitude increases.
[0072] The system determines whether a sensor has experienced significant drift based on its trend. A tolerance threshold is set, adjusted for historical volatility of statistical parameters from a reference group (e.g., the average of historical fluctuations). The criterion is that if the current trend amplitude exceeds the tolerance threshold three consecutive times, it is considered significant drift. In experimental testing, when drift is artificially introduced into the sensor, the trend amplitude continuously exceeds the threshold, triggering the drift flag.
[0073] When a significant drift is detected, a correction coefficient is calculated based on the trend. The correction coefficient is determined using a lookup table: a pre-stored correction table maps the trend amplitude range to specific coefficients. For example, when the trend amplitude is positive and large, the correction coefficient is negative to offset the drift. During testing, the correction table is pre-filled based on sensor calibration experiments to ensure that the coefficients match the degree of drift.
[0074] A correction factor is applied to the sensor's output circuit to adjust the measured value. Specifically, the correction factor is converted into an analog voltage signal by a microcontroller, then output to the sensor's gain adjustment pin via a digital-to-analog converter, directly modifying the amplification factor of the output circuit. Experimental tests show that after correction, the sensor output stabilizes, and the measured value matches the reference value.
[0075] Furthermore, step S2 also includes:
[0076] The segmentation operation is achieved by setting a sliding window of fixed length, with each window containing the same number of measurements, and the windows are continuous and do not overlap.
[0077] The predetermined quantity is set based on sensor stability and the frequency of environmental changes;
[0078] The length of the time period is dynamically adjusted according to the type of sensor and environmental conditions, wherein the environmental conditions include at least one of temperature and humidity.
[0079] During dynamic adjustment, the ambient temperature and humidity are monitored, and the time period is automatically shortened when the temperature or humidity changes exceed the preset range.
[0080] The time period length can be adjusted by querying a predefined mapping table of environmental conditions and length.
[0081] In this embodiment, the time period length in step S2 is dynamically adjusted based on the sensor type and environmental conditions. Environmental conditions include temperature and humidity: the sensor integrates a temperature and humidity module to monitor environmental parameters in real time. When temperature or humidity changes exceed a preset range (e.g., a temperature change exceeding 5 degrees Celsius or a humidity change exceeding 10%), the system automatically shortens the time period length, such as reducing it from 60 measurements to 30, to increase response speed. This adjustment is achieved by querying a predefined mapping table between environmental conditions and time periods. During testing, shortening the window length during sudden environmental changes allows for faster drift detection and avoids missed detections.
[0082] Furthermore, referring to Figure 2 Step S3 also includes:
[0083] S31: Obtain all measured values within the current time period and arrange them in chronological order. Extract the measured values from the data buffer according to the timestamp, ensuring that the order is consistent with the acquisition time. Store the arranged values as a temporary array.
[0084] S32, calculate the arithmetic mean of the arranged measurements. The arithmetic mean is obtained by summing all the measurements and then dividing by the number of measurements. When summing, the temporary array is traversed and all values are accumulated. When dividing by the number, integer division or floating-point operation is used.
[0085] S33, find the minimum and maximum values among the measured values, and calculate the difference between the maximum and minimum values as the range to represent the fluctuation range. When finding the minimum and maximum values, traverse the temporary array, compare each value, and record the current minimum and maximum. The range is calculated as the maximum value minus the minimum value.
[0086] S34, Simultaneously calculate the median value of the measured values. The median value is obtained by sorting the measured values by size and taking the center value. The measured values are arranged in ascending order. If the number of measured values is odd, the value of the middle position after sorting is taken. If it is even, the arithmetic mean of the two middle values is taken.
[0087] S35, based on the arithmetic mean, range and median, a comprehensive statistical parameter is formed by combining them. When combining, the arithmetic mean, range and median are weighted and summed according to a predetermined weight.
[0088] S36, record the comprehensive statistical parameters for subsequent comparison. When recording, store the comprehensive statistical parameters together with the timestamp in non-volatile memory and retain records from multiple recent time periods.
[0089] In this embodiment, all measured values within the current time period are extracted from the data buffer according to their timestamps, ensuring the order matches the acquisition time. The data is then arranged and stored as a temporary array for subsequent calculations. During testing, the correctness of the data arrangement is confirmed by verifying the continuity of the time series.
[0090] The algorithm iterates through a temporary array, summing all measurements and then dividing by the number of measurements. Floating-point arithmetic is used, and the result is rounded to three decimal places. Experiments show that the average value effectively represents the central tendency of the data.
[0091] Iterate through the temporary array to find the minimum and maximum values, and calculate the range as the fluctuation range. In the test, the range is small in a stable environment and increases during drift.
[0092] Sort the measurements by size (using a sorting algorithm such as bubble sort), and take the center value as the median. If the number of measurements is even, take the arithmetic mean of the two middle values. The median value enhances robustness to outliers.
[0093] The arithmetic mean, range, and median are summed using predetermined weights (0.6 for the mean, 0.2 for the range, and 0.2 for the median), and the result is normalized to a single value. In testing, the combined parameter was more stable than any single parameter.
[0094] Comprehensive statistical parameters are stored together with timestamps in non-volatile memory, retaining records for the most recent 100 time periods. This facilitates historical comparison and backtracking analysis.
[0095] Furthermore, referring to Figure 3 Step S4 also includes:
[0096] S41, Select the most recent M time periods as the reference group, where M is an integer greater than 1. The value of M is set according to the stability of the sensor's historical data. Select the data of the M consecutive time periods before the current time period from the historical records.
[0097] S42, calculate the average value of the statistical parameters for each time period in the reference group as the baseline statistical parameters. When calculating, add the statistical parameters for each time period in the reference group and then divide by M to obtain the baseline value.
[0098] S43, calculate the absolute deviation between the statistical parameters of the current time period and the benchmark statistical parameters, wherein the absolute deviation is obtained by calculating the absolute value of the difference between the current statistical parameters and the benchmark value;
[0099] S44, calculate the standard deviation of the statistical parameters in the reference group as the fluctuation benchmark. The standard deviation is calculated by the difference between each reference statistical parameter and the benchmark value, then the average of the squares of these differences is calculated, and finally the square root of the average value is taken as an approximation.
[0100] S45, compare the absolute deviation with the threshold obtained by multiplying the fluctuation benchmark by a predetermined coefficient, set the predetermined coefficient based on experience, and calculate the threshold as the fluctuation benchmark multiplied by the predetermined coefficient;
[0101] S46, if the absolute deviation exceeds the threshold, the change trend is determined to be a significant change, and the direction and magnitude of the change trend are recorded. When comparing, a numerical comparator is used. If the absolute deviation is greater than the threshold, a flag is triggered to indicate a significant change. The direction is recorded by the positive or negative value of the difference between the current statistical parameter and the benchmark value. A positive value indicates an upward trend, and a negative value indicates a downward trend. The magnitude is recorded as the absolute value of the difference.
[0102] In this embodiment, the most recent M time periods are selected as a reference group, and M is set to 5 based on the stability of historical sensor data. Data from 5 consecutive time periods are extracted from the historical records.
[0103] Calculate the average of the statistical parameters for each time period in the reference group as a baseline. For example, add the averages of the five time periods together and divide by 5.
[0104] Calculate the absolute value of the difference between the current statistical parameter and the benchmark value, and round the result to two decimal places.
[0105] The standard deviation of the reference group's statistical parameters is calculated as the fluctuation benchmark. Specifically, the difference between each reference statistical parameter and the benchmark value is first calculated, then the average of the squares of these differences is calculated, and finally the square root of the average is taken as an approximation (avoid formulas, describe it as an approximate calculation).
[0106] The threshold is obtained by multiplying the fluctuation baseline by a predetermined coefficient (set to 2). The absolute deviation is then compared with the threshold using a numerical comparator.
[0107] If the absolute deviation exceeds the threshold, a flag indicating a significant change is triggered.
[0108] The direction is determined by the sign of the difference, and the magnitude is recorded as the absolute value of the difference. In testing, this sub-step accurately captured the drift trend.
[0109] Furthermore, step S5 also includes:
[0110] Check whether the trend of change exceeds the predetermined number of times it exceeds the tolerance value, where the tolerance value is set based on the variability of historical statistical parameters;
[0111] The tolerance value is adjusted by calculating the average fluctuation range of historical statistical parameters. If the trend of a series of consecutive predetermined time periods exceeds the tolerance value, it is considered a drift.
[0112] In this embodiment, the tolerance value in step S5 is set based on the variability of historical statistical parameters: the average of the fluctuation range over the most recent 20 time periods is calculated as the tolerance value. A predetermined number of tests is set to 3, meaning that a drift is only determined if the trend exceeds the tolerance value for three consecutive time periods. In testing, this continuous determination reduces false alarms.
[0113] Furthermore, step S6 also includes:
[0114] Based on the magnitude and direction of the trend, the correction coefficient is determined by looking up a table, where the table pre-stores the mapping relationship between the trend magnitude and the correction coefficient.
[0115] When looking up the table, the trend amplitude is divided into multiple intervals, and each interval corresponds to a correction coefficient; when the direction is positive, the correction coefficient is negative, and when the direction is negative, the correction coefficient is positive; the table content is pre-filled based on sensor calibration experiments.
[0116] In this embodiment, step S6, the lookup table method, is specifically implemented as follows: the calibration table divides the trend amplitude into multiple intervals (e.g., low, medium, high), with each interval corresponding to a calibration coefficient. When the trend direction is positive, the calibration coefficient is negative for reverse compensation. The table content is filled in based on the sensor's factory calibration experiment. During testing, the lookup table method proved to be fast and reliable.
[0117] Furthermore, step S6 also includes:
[0118] The correction coefficients are converted into voltage or current signals, and the bias voltage or gain of the sensor is adjusted by a digital-to-analog converter.
[0119] During conversion, the correction factor is multiplied by the reference voltage value to obtain the target voltage;
[0120] The digital-to-analog converter converts the digital target voltage into an analog signal, which is then output to the bias pin of the sensor to change the operating point.
[0121] In this embodiment, step S6 adjusts the sensor circuit via a digital-to-analog converter: the correction coefficient is multiplied by the reference voltage value to obtain the target voltage; the digital-to-analog converter converts the digital signal into an analog voltage and outputs it to the sensor's bias pin, thus changing the operating point. Tests show that voltage adjustment effectively corrects the output.
[0122] Furthermore, after step S6, the following is also included:
[0123] To verify the correction effect, the changes in statistical parameters are monitored for a period of time after correction. If the trend of change does not return to normal, steps S3 to S6 are repeated.
[0124] During verification, after calibration, the statistical parameters for the next time period are monitored. If the deviation from the baseline value still exceeds half of the tolerance value, it is determined that the system has not returned to normal and calibration is performed again.
[0125] In this embodiment, statistical parameters are monitored for a period of time after correction. If the deviation of the statistical parameters from the benchmark value in the next time period still exceeds half of the tolerance value, the correction is deemed unsuccessful, and steps S3 to S6 are repeated. During testing, the verification step ensures the reliability of the correction and avoids over-correction or under-correction.
[0126] Furthermore, step S1 also includes:
[0127] The fixed time interval is set according to the response characteristics of the sensor; for sensors with slow response, a longer interval is set.
[0128] For fast-response sensors, set short intervals; collect measurements including particulate matter concentration or gas concentration, and store them in real time in a circular data buffer to ensure that the data is arranged in chronological order.
[0129] In this embodiment, the interval is set based on the sensor's response characteristics (such as rise time and fall time): the interval is set to twice the rise time to ensure stable measurements. During testing, this setting avoids the acquisition of unstable data.
[0130] Furthermore, in step S3, the fluctuation range is also obtained by calculating the variance or coefficient of variation of the measured values, where the coefficient of variation is the ratio of the standard deviation to the mean.
[0131] When calculating variance, first calculate the square of the difference between each measurement and the mean, and then calculate the mean.
[0132] The coefficients of variation are obtained by dividing the variance by the mean.
[0133] In this embodiment, the fluctuation range in step S3 can also be obtained through variance or coefficient of variation: variance is calculated as the average of the squares of the differences between each measurement and the mean; coefficient of variation is the quotient of variance and mean. In testing, these parameters provide additional fluctuation information, but range is simpler and more practical.
[0134] Throughout the test, the sensor operated under simulated normal and drift scenarios. Initially, measurements were stable with minimal changes in statistical parameters; upon introduction of drift, trend detection was triggered promptly, and the correction system effectively restored sensor accuracy. All steps were logically sound and required no manual intervention, demonstrating the method's self-calibration capability.
[0135] The following is a specific example:
[0136] This embodiment details the implementation process of a self-calibration method for an indoor PM2.5 air quality sensor. The sensor operates long-term in a relatively stable office environment, but its measuring elements experience slow performance degradation over time, leading to a fundamental drift in the measured values. This method automatically identifies this drift and performs correction by analyzing the sensor's own time-series output data in real time, without requiring external reference equipment or manual intervention. The embodiment simulates continuous sensor operation for several weeks, covering the entire cycle from normal operation, drift occurrence, detection, and automatic correction recovery.
[0137] Sensor hardware configuration: The core of the sensor is an optical particulate matter detection unit, equipped with a microprocessor for data acquisition and processing, and built-in non-volatile memory for storing historical data. The output circuit includes a microprocessor-controlled digital-to-analog converter for adjusting signal gain. The sensor is continuously powered to ensure uninterrupted data acquisition.
[0138] S1: Collect time series data;
[0139] After the sensor is powered on and initialized, the microprocessor starts an internal timer, triggering an analog-to-digital conversion at a fixed time interval to read the current PM2.5 concentration measurement. This fixed time interval is determined based on the sensor's response characteristic parameters. Specifically, during the sensor's factory calibration phase, its complete response time (including rise time and settling time) from exposure to concentration changes to the output signal reaching stability has been measured. To avoid acquiring transient and unstable data, the fixed interval is set slightly longer than this response time, ensuring that each acquired value is a representative stable value. Each acquired measurement is accompanied by a precise timestamp and stored sequentially in a pre-allocated circular data buffer. The size of this buffer is designed to hold data for a sufficiently long period, such as more than 24 hours, to prevent data overwriting during data processing. The microprocessor checks the buffer status before writing new data to ensure that the data is ordered and complete.
[0140] S2: Divide the time period;
[0141] The microprocessor's processing program periodically (e.g., whenever a certain number of new data points accumulate in the buffer) initiates a data analysis task. This task first reads the raw data stream from the circular buffer in chronological order. Then, it segments the data using a fixed-length "sliding window." The number of measurements contained in this window (i.e., the window size) is pre-defined; for example, a window size of 60 represents data collected within one hour. The window slides forward one data point at a time, meaning the new window contains data points 2 through 61 from the previous window, and the latest 62nd data point is added, and so on, forming consecutive and slightly overlapping time periods. This sliding method ensures that any potential points of change are not completely missed by the window boundaries. Data for each segmented time period is temporarily loaded into memory for use in the next computation.
[0142] S3: Calculate statistical parameters;
[0143] For each segmented time period (containing 60 measurements), the microprocessor performs statistical calculations. First, it calculates the average: the 60 measurements are summed one by one, and then the sum is divided by 60. The result is typically rounded to two decimal places to balance precision and computational resources. Next, it calculates the range (represented by the range): iterating through the 60 measurements, the maximum and minimum values are found, and the difference between the maximum and minimum values is calculated. The average reflects the average concentration level within the time period, while the range visually represents the magnitude of data fluctuation within that period. These two parameters together constitute the basic statistical description of the time period.
[0144] S4: Compare statistical parameters to determine the trend of change;
[0145] The microprocessor maintains a queue of historical statistical parameters to store the averages and ranges for a number of recent time periods (e.g., the last 20 time periods). When it is necessary to analyze the trend of the current time period (denoted as T_c), the system selects the M consecutive time periods immediately preceding T_c (e.g., M=5, i.e., T_c-5 to T_c-1) as a reference group. The arithmetic mean of the five averages within the reference group is calculated as the "baseline average". Similarly, the average of the five ranges within the reference group is calculated as the "baseline fluctuation level". Then, the difference between the average of the current time period and the baseline average, and the difference between the range of the current time period and the baseline fluctuation level are calculated. The sign (positive or negative) of these differences indicates the direction of change (e.g., a positive difference in averages indicates an upward trend in concentration readings), while the absolute value of the difference indicates the magnitude of the change.
[0146] S5: Determine the significance of the drift;
[0147] The system presets a "tolerance threshold" to determine whether the difference is significant. This threshold is not a fixed value but is dynamically adjusted based on the volatility of the reference group data itself. For example, the threshold can be set as the baseline volatility level multiplied by an empirical coefficient (such as 1.5 or 2). The judgment logic is: if the average difference (absolute value) of the current time period exceeds (for example) its corresponding dynamic tolerance threshold for three consecutive time periods, then it is determined that the sensor has experienced a statistically significant systematic drift, rather than just random fluctuations caused by environmental noise. This continuous judgment mechanism effectively reduces the possibility of false alarms.
[0148] S6: Calculate the correction coefficient;
[0149] Once a significant drift is determined, the system calculates the required correction factor based on the determined trend direction (positive or negative drift) and trend magnitude (the size of the difference). The correction factor is obtained by looking up a "correction factor lookup table" pre-stored in non-volatile memory. This table was calibrated before the sensor left the factory by conducting aging experiments under standard gases of different known concentrations to simulate various drift conditions. The table lists the optimal correction factor values corresponding to drift ranges for different amplitude intervals. For example, for a moderate positive drift, the correction factor obtained from the table might be a multiplier factor slightly less than 1.
[0150] Apply correction factors;
[0151] The calculated correction coefficient (usually a digital value) is fed into the microprocessor's digital-to-analog converter (DAC) control module. The DAC generates a corresponding analog voltage signal based on this coefficient value. This voltage signal is applied to the subsequent signal conditioning circuitry of the sensor detection unit, typically by adjusting the feedback resistor network of its operational amplifier, thereby altering the gain of the entire signal path. For example, for positive drift, the applied voltage reduces the gain, resulting in a smaller final output value and offsetting the drift's effect. This adjustment is performed in real time, and the subsequent sensor output is the corrected value.
[0152] In addition to the basic fixed window size, the system also incorporates a dynamic adjustment mechanism to adjust the time period length. Onboard temperature and humidity sensors monitor environmental conditions in real time. A preset lookup table is stored in the microprocessor, defining recommended time period lengths (window sizes) for different temperature and humidity ranges. For example, when the ambient temperature exceeds a certain threshold or humidity changes drastically, the system considers the environment unstable and potentially introducing short-term interference. In this case, the system automatically and temporarily reduces the window size from the standard 60 data points to 30 points. This improves the system's response speed, allowing statistical calculations to more quickly reflect environmental changes or potential sensor drift, and avoiding the smoothing out of important changes due to an excessively large window. Once environmental conditions stabilize, the window size returns to the standard value.
[0153] Retrieve and sort measurements: Extract 60 measurements corresponding to the current time period from the circular buffer and sort them strictly according to the chronological order of their timestamps to ensure the continuity of the time series. The sorted data is copied to a temporary array for subsequent calculations.
[0154] Calculate the arithmetic mean: Summate the 60 values in the temporary array, then divide the sum by 60. Division operations are typically performed using floating-point numbers to maintain precision, and the final result is rounded to three decimal places.
[0155] Calculate the range: Perform a linear scan on the temporary array, initialize the maximum and minimum value variables, compare and update them one by one, and finally find the maximum and minimum values in the array, and calculate the difference between the two, which is the range.
[0156] Calculate the median: Sort the 60 measurements in the temporary array in ascending order of numerical value. Since 60 is an even number, take the 30th and 31st values after sorting and calculate their arithmetic mean as the median for that time period. The median is not sensitive to outliers (such as transient disturbances) and better reflects the central trend of the data.
[0157] Combined statistical parameter: The calculated arithmetic mean, range, and median are weighted and summed according to pre-set weights (e.g., mean weight 0.5, median weight 0.3, range weight 0.2) to obtain a combined statistical parameter. This combined parameter integrates information on central tendency, central resistance to interference, and dispersion, making it more robust than a single parameter.
[0158] Record parameters: This comprehensive statistical parameter for the current time period, along with the timestamp of the time period's end, is saved to the historical parameter queue in non-volatile memory. The queue uses a first-in, first-out (FIFO) strategy, retaining only records from the most recent 100 time periods for historical trend analysis.
[0159] Select a reference group: Determine the number of time periods M included in the reference group, for example, M=5. Retrieve the comprehensive statistical parameters of the five consecutive time periods preceding the current time period from the historical parameter queue.
[0160] Calculate the baseline statistical parameter: Add these 5 comprehensive statistical parameters together, then divide by 5 to obtain the arithmetic mean of the comprehensive statistical parameters for these 5 time periods, which is used as the current "baseline statistical parameter".
[0161] Calculate the absolute deviation: Calculate the difference between the comprehensive statistical parameters of the current time period and the baseline statistical parameters obtained in the previous step, and take the absolute value of the difference to obtain the absolute deviation.
[0162] Calculating the volatility benchmark: To assess the inherent volatility of the reference group itself, the standard deviation of the composite statistical parameters across the five reference time periods is calculated as the "volatility benchmark." The calculation process is as follows: first, calculate the difference between each reference parameter and the benchmark parameter; then, calculate the sum of the squares of these differences; next, divide by the number of parameters minus one (i.e., 4); finally, take the square root of this quotient. This process quantifies the normal fluctuation range of the reference group data.
[0163] Set and compare thresholds: Multiply the fluctuation baseline by a predetermined safety factor (e.g., 2) to obtain a dynamic threshold. Compare this threshold with the absolute deviation calculated in S4-3.
[0164] Determining a significant change: If the absolute deviation exceeds the dynamic threshold, then the current time period is determined to have undergone a significant change relative to the reference group.
[0165] Record the trend direction and magnitude: Record the current direction of change (based on the sign of the difference) and magnitude (i.e., the absolute deviation value). This information will be used for subsequent drift judgment and correction.
[0166] Continuity judgment logic: The determination of significant drift is not based on a single exceedance of the threshold, but requires continuity. The system sets a consecutive number of times N (e.g., N=3). This means that the changes in statistical parameters in the current time period and the (N-1) time periods before it (a total of 3 consecutive time periods) must all be judged as significant changes (i.e., their absolute deviations all exceed their respective dynamic thresholds) before it is finally confirmed that the sensor has experienced a "significant drift" that requires correction. This design effectively filters out transient, sporadic interference.
[0167] Details of the lookup table method: The pre-stored correction coefficient lookup table has a detailed structure. It divides the trend magnitude (absolute deviation value) into multiple consecutive intervals (e.g., 0-0.1, 0.1-0.2, 0.2-0.3, ...) and assigns a specific correction coefficient to each interval. Furthermore, the table has different mappings based on the trend direction (positive / negative). For example, for positive drift (higher readings), the correction coefficient is less than 1, used to attenuate the output; for negative drift, the coefficient is greater than 1. After calculating the trend magnitude and direction, the microprocessor maps them to the corresponding intervals and reads the stored correction coefficient values within those intervals.
[0168] Circuit tuning details: The application of the correction factor (K) is specific to the hardware circuit. The microprocessor passes the digital value K to the integrated digital-to-analog converter (DAC). The DAC converts K into a precise analog voltage (V_adj) based on its reference voltage (V_ref) and resolution, where... (or proportional to it). This V_adj voltage is output to a pin in the sensor signal conditioning circuit specifically for gain control (such as the inverting input of an operational amplifier or the control terminal of an analog multiplier), directly changing the amplification factor of the analog signal, thereby achieving linear correction of the sensor's original output.
[0169] To verify the correction effect, the system does not immediately make a new drift judgment for a period of time after applying the correction coefficient (e.g., the next 1-2 time periods). Instead, it enters the verification phase. During this period, it continues to collect data and calculate statistical parameters, but focuses on monitoring whether the deviation between the current parameters and the baseline parameters before the drift occurred has significantly decreased. The system sets a verification threshold (e.g., half of the tolerance threshold). If, after correction, the deviation of the statistical parameters from the baseline falls below the verification threshold, the correction is considered successful. If the deviation is still higher than the verification threshold, the correction effect is deemed unsatisfactory. The system will record this failure and may re-trigger the drift detection and correction process starting from S3 at the next time point, or adopt a more aggressive correction strategy (e.g., using the coefficient corresponding to a larger correction magnitude from a lookup table).
[0170] Engineering considerations for setting the time interval: Setting a fixed time interval is crucial to ensuring data quality. Too short an interval will result in the collection of a large amount of highly correlated redundant data, and may also include noise from when the sensor is not stable; too long an interval may result in the loss of important environmental change information. In this embodiment, the interval is set to 1.5 to 2 times the sensor response time. This is an engineering balance choice that ensures that each sampling captures a stable, independent measurement value, thereby truly reflecting the instantaneous state of ambient air quality.
[0171] Alternative volatility measures, besides range, can be described by other statistics. Variance measures the average degree to which data deviates from the mean; it is calculated as the average of the squares of the differences between each data point and the mean. The coefficient of variation is the ratio of the standard deviation (the square root of the variance) to the mean; it is a dimensionless quantity suitable for comparing the volatility of datasets with different average levels. In practical applications, the most suitable volatility measure can be selected based on the characteristics of the sensor and the computing power of the processor. Range is simple to calculate and suitable for rapid assessment; variance and coefficient of variation contain more information but require slightly more computation.
[0172] In the simulation test, the sensor initially operated normally with stable statistical parameters. Subsequently, the sensor's sensitive element aged, causing a slow and continuous positive drift in the output value. The method successfully detected this continuous trend change, triggering the correction mechanism. After the correction coefficients obtained from the lookup table were applied to the circuit, the sensor output value gradually returned to the normal range. Monitoring during the verification phase confirmed the effectiveness of the correction. The detailed steps of the entire process are logically clear and interconnected, fully demonstrating the method's ability to autonomously and reliably correct sensor drift.
[0173] According to a second embodiment of the present invention, the present invention claims protection for an air quality sensor self-calibration system based on time series analysis, comprising:
[0174] One or more processors;
[0175] A memory storing one or more programs, which, when executed by one or more processors, enable the one or more processors to implement the aforementioned self-calibration method for air quality sensors based on time series analysis.
[0176] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, or indirect coupling or communication connection between apparatuses or units, and may be electrical, mechanical, or other forms.
[0177] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated units described above can be implemented in hardware or as software functional units. The above are merely embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made based on the description and drawings of this application, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
[0178] The specific embodiments of the invention have been described in detail above, but they are only examples, and this application is not limited to the specific embodiments described above. For those skilled in the art, any equivalent modifications or substitutions to the invention are also within the scope of this application. Therefore, all equivalent changes, modifications, and improvements made without departing from the spirit and principles of this application should be covered within the scope of this application.
Claims
1. A self-calibration method for air quality sensors based on time series analysis, characterized in that, Includes the following steps: S1: During normal operation of the sensor, air quality measurements are collected at fixed time intervals to form time series data; S2: Divide the time series data into consecutive time periods, each time period containing a predetermined number of measurements; S3: For each time period, calculate the statistical parameters of the measured values within that time period, including the average value and the range of fluctuation; S4: Compare the statistical parameters of the current time period with the statistical parameters of one or more previous time periods to determine the trend of the statistical parameters; S5: Based on the aforementioned trend, determine whether the sensor has experienced significant drift; S6: When a significant drift is detected, a correction coefficient is calculated based on the trend of change and the correction coefficient is applied to the output circuit of the sensor to adjust the measured value; The S5 also includes: Check whether the trend of change exceeds the predetermined number of times it exceeds the tolerance value, where the tolerance value is set based on the variability of historical statistical parameters; The tolerance value is adjusted by calculating the average fluctuation range of historical statistical parameters. If the trend of a series of consecutive predetermined time periods exceeds the tolerance value, it is considered a drift. S6 further includes: Based on the magnitude and direction of the trend, the correction coefficient is determined by looking up a table, where the table pre-stores the mapping relationship between the trend magnitude and the correction coefficient. When looking up the table, the trend amplitude is divided into multiple intervals, and each interval corresponds to a correction coefficient; when the direction is positive, the correction coefficient is negative, and when the direction is negative, the correction coefficient is positive; the table content is pre-filled based on sensor calibration experiments. The correction coefficients are converted into voltage or current signals, and the bias voltage or gain of the sensor is adjusted by a digital-to-analog converter. During conversion, the correction factor is multiplied by the reference voltage value to obtain the target voltage; The digital-to-analog converter converts the digital target voltage into an analog signal, which is then output to the bias pin of the sensor to change the operating point.
2. The self-calibration method for air quality sensors based on time series analysis according to claim 1, characterized in that, Step S2 also includes: The segmentation operation is achieved by setting a sliding window of fixed length, with each window containing the same number of measurements, and the windows are continuous and do not overlap. The predetermined quantity is set based on sensor stability and the frequency of environmental changes; The length of the time period is dynamically adjusted according to the type of sensor and environmental conditions, wherein the environmental conditions include at least one of temperature and humidity. During dynamic adjustment, the ambient temperature and humidity are monitored, and the time period is automatically shortened when the temperature or humidity changes exceed the preset range. The time period length can be adjusted by querying a predefined mapping table of environmental conditions and length.
3. The self-calibration method for air quality sensors based on time series analysis according to claim 1, characterized in that, Step S3 also includes: S31: Obtain all measured values within the current time period and arrange them in chronological order. Extract the measured values from the data buffer according to the timestamp to ensure that the order is consistent with the collection time. Store the arranged values as a temporary array. S32, calculate the arithmetic mean of the arranged measurements. The arithmetic mean is obtained by summing all the measurements and then dividing by the number of measurements. When summing, the temporary array is traversed and all values are accumulated. When dividing by the number, integer division or floating-point operation is used. S33, find the minimum and maximum values among the measured values, and calculate the difference between the maximum and minimum values as the range to represent the fluctuation range. When finding the minimum and maximum values, traverse the temporary array, compare each value, and record the current minimum and maximum. The range is calculated as the maximum value minus the minimum value. S34, Simultaneously calculate the median value of the measured values. The median value is obtained by sorting the measured values by size and taking the center value. The measured values are arranged in ascending order. If the number of measured values is odd, the value of the middle position after sorting is taken. If it is even, the arithmetic mean of the two middle values is taken. S35, based on the arithmetic mean, range and median, a comprehensive statistical parameter is formed by combining them. When combining, the arithmetic mean, range and median are weighted and summed according to a predetermined weight. S36, record the comprehensive statistical parameters for subsequent comparison. When recording, store the comprehensive statistical parameters together with the timestamp in non-volatile memory and retain records from multiple recent time periods.
4. The self-calibration method for an air quality sensor based on time series analysis according to claim 1, characterized in that, Step S4 also includes: S41, Select the most recent M time periods as the reference group, where M is an integer greater than 1. The value of M is set according to the stability of the sensor's historical data. Select the data of the M consecutive time periods before the current time period from the historical records. S42, calculate the average value of the statistical parameters for each time period in the reference group as the baseline statistical parameters. When calculating, add the statistical parameters for each time period in the reference group and then divide by M to obtain the baseline value. S43, calculate the absolute deviation between the statistical parameters of the current time period and the benchmark statistical parameters, wherein the absolute deviation is obtained by calculating the absolute value of the difference between the current statistical parameters and the benchmark value; S44, calculate the standard deviation of the statistical parameters in the reference group as the fluctuation benchmark. The standard deviation is calculated by the difference between each reference statistical parameter and the benchmark value, then the average of the squares of these differences is calculated, and finally the square root of the average value is taken as an approximation. S45, compare the absolute deviation with the threshold obtained by multiplying the fluctuation benchmark by a predetermined coefficient, set the predetermined coefficient based on experience, and calculate the threshold as the fluctuation benchmark multiplied by the predetermined coefficient; S46, if the absolute deviation exceeds the threshold, the change trend is determined to be a significant change, and the direction and magnitude of the change trend are recorded. When comparing, a numerical comparator is used. If the absolute deviation is greater than the threshold, a flag is triggered to indicate a significant change. The direction is recorded by the positive or negative value of the difference between the current statistical parameter and the benchmark value. A positive value indicates an upward trend, and a negative value indicates a downward trend. The magnitude is recorded as the absolute value of the difference.
5. The self-calibration method for an air quality sensor based on time series analysis according to claim 1, characterized in that, The process after step S6 also includes: To verify the correction effect, the changes in statistical parameters are monitored for a period of time after correction. If the trend of change does not return to normal, steps S3 to S6 are repeated. During verification, after calibration, the statistical parameters for the next time period are monitored. If the deviation from the baseline value still exceeds half of the tolerance value, it is determined that the system has not returned to normal and calibration is performed again.
6. The self-calibration method for an air quality sensor based on time series analysis according to claim 1, characterized in that, Step S1 also includes: The fixed time interval is set according to the response characteristics of the sensor; for sensors with slow response, a longer interval is set. For fast-response sensors, set short intervals; collect measurements including particulate matter concentration or gas concentration, and store them in real time in a circular data buffer to ensure that the data is arranged in chronological order; In step S3, the fluctuation range is also obtained by calculating the variance or coefficient of variation of the measured values, where the coefficient of variation is the ratio of the standard deviation to the mean. When calculating variance, first calculate the square of the difference between each measurement and the mean, and then calculate the mean. The coefficients of variation are obtained by dividing the variance by the mean.
7. A self-calibration system for an air quality sensor based on time series analysis, characterized in that, include: One or more processors; A memory having stored one or more programs that, when executed by one or more processors, cause the one or more processors to implement a time-series analysis-based self-calibration method for air quality sensors according to any one of claims 1 to 6.