AD sampling processing method and system based on periodic variable signals
By performing square sum-average processing of periodic variable signals and combining with the preset mapping relationship table, the problem of strong algorithm dependence in traditional methods is solved, and AD sampling processing that reduces the amount of computing and improves reliability is realized.
Patent Information
- Application Number
- CN202411944873.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-27
AI Technical Summary
The traditional AD sampling method of periodic variable signals requires the adjustment of algorithms according to different hardware circuits, resulting in large calculation volume and low reliability.
An AD sampling processing method based on periodic variable signals is adopted. By calculating the square sum of the signals and averaging them within the preset time interval, the effective value D1 is obtained, and then the offset Diff is found through the preset mapping relationship table, and the actual value D0 is calculated.
There is no need to adjust the algorithm according to different hardware circuits, which reduces the calculation amount, improves reliability, and obtains a relatively constant effective value while ensuring that the input power remains unchanged.
Smart Images

Figure CN119892085A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electrical signal detection, and in particular to an AD sampling and processing method based on a periodic variable signal, and an AD sampling and processing system based on a periodic variable signal. Background Art
[0002] In electronic devices, it is often necessary to perform AD sampling on a known periodic variable signal to achieve operating parameter monitoring and automatic control. The traditional AD sampling method for periodic variable signals often requires continuous sampling within the same period, and then obtains an effective value D1 through various algorithms (for example, mean, root mean square, maximum value, etc.), and combines hardware design to find the relationship between the effective value D1 and the actual value D0, and finally obtains the effective value D1 close to the actual value D0, and outputs the effective value D1 as the actual value D0. The defects of this traditional AD sampling method for periodic variable signals are:
[0003] The algorithm used needs to be adjusted according to the specific hardware circuit, that is, different hardware needs to use different algorithms to obtain the effective value. For example, when using the root mean square algorithm or finding the peak voltage, it is necessary to consider whether there is a DC bias in the circuit, whether the rectification is full-wave or half-wave, what the voltage division ratio is, and some necessary filtering algorithms are also required to finally obtain the effective value D1. Any error in any link during the process will affect the calculation result. Therefore, different hardware circuits need to use different algorithms, and the algorithms are highly dependent on hardware. This results in the MCU of the electronic device performing AD sampling tasks according to the preset algorithms of different hardware circuits, which has a large amount of calculation and low reliability. Summary of the invention
[0004] Based on this, the present invention provides an AD sampling processing method based on a periodic variable signal, so that when the MCU of the electronic device performs the AD sampling task, it is not necessary to perform calculations according to the algorithms preset by different hardware circuits, thereby reducing the amount of calculations and improving reliability.
[0005] An AD sampling and processing method based on a periodic variable signal comprises the following steps:
[0006] S10: performing AD sampling on the periodic variable signal; wherein the periodic variable signal is sampled once at every interval △t to obtain a sampling value dx; wherein △t=(T0 / N1), T0 is the variation period of the periodic variable signal, and N1 is a positive integer;
[0007] S20: Calculate the square sum of the sampled values dx collected within one period T0 of the periodic variable signal to obtain SUM(∑dx 2 );
[0008] S30: SUM(∑dx 2 ) calculate the average to obtain the effective value D1; wherein, T1 = N2*T0, and N2 is a positive integer;
[0009] S40: Find the offset Diff mapped to the effective value D1 in step S30 from the preset effective value D1-offset Diff mapping relationship table, then the actual value D0 of the periodic variable signal = D1 + Diff.
[0010] The above-mentioned AD sampling and processing method based on periodic variable signals performs square sum processing on the sampled values dx collected within one cycle T0 of the variable signal, and then performs averaging processing according to the preset time interval T1. The processing method of square sum averaging can be used to measure the power of the signal. When the input power remains unchanged, a result with a very small oscillation amplitude can be obtained. Therefore, under this processing method, there is no need to pay attention to whether the circuit has a DC bias, full wave or half wave, or voltage divider ratio. Under the condition of ensuring that the input power remains unchanged, a relatively constant value, that is, effective value D1, can be obtained. Then, the effective value D1 is used to look up the table to map the offset Diff, and then the effective value D1 and the offset Diff are summed to obtain the actual value D0. Through the above design, the MCU of the electronic device does not need to perform calculations according to the preset algorithms of different hardware circuits when performing AD sampling tasks, thereby reducing the amount of calculations and improving reliability.
[0011] In one embodiment, in step S10, if the number of bits of AD sampling is greater than 8, the sampling value dx is right-shifted so that the number of bits of the sampling value dx does not exceed 8. In order to reduce the computing load of the MCU, when the number of bits of AD sampling is greater than 8, the sampling value dx is right-shifted, thereby reducing the number of bits of the sampling value dx and controlling it within 8 bits.
[0012] In one embodiment, in step S30, the value of N2 is a positive integer not less than 2. When the value of N2 is larger, the interference of noise can be reduced by sampling a plurality of cycles, thereby reducing the influence of noise on the operation result and achieving a filtering effect. Therefore, the value of N2 is preferably a positive integer not less than 2.
[0013] In one embodiment, the method for obtaining the mapping relationship table of effective value D1-offset Diff comprises the steps of:
[0014] S01: Provide signal source to electronic equipment through frequency converter and perform AD sampling processing;
[0015] S02: gradually adjusting the output signal of the frequency converter to the electronic device according to the preset signal strength interval and recording the actual value D0' at each adjustment; at the same time, executing steps S10, S20, and S30 to obtain the effective value D1 corresponding to each actual value D0', and calculating the difference between each effective value D1 and the corresponding actual value D0' to obtain the offset Diff=D0'-D1;
[0016] S03: Create a mapping relationship table of effective value D1-offset Diff and archive it.
[0017] The frequency converter is used as an adjustable and stable signal source to simulate the periodic variable signal when the electronic device is working. By gradually adjusting the signal strength, the mapping relationship between the actual value D0 and the effective value D1 calculated according to steps S10 to S30 is measured, thereby establishing a mapping relationship table of the effective value D1-offset Diff. For each electronic device, an exclusive mapping relationship table of the effective value D1-offset Diff can be obtained.
[0018] In one embodiment, in step S40, if the current effective value D1 has no corresponding value in the preset effective value D1-offset Diff mapping relationship table, then the partition in the effective value D1-offset Diff mapping relationship table where the current effective value D1 is located is found, and the offset Diffs corresponding to the two endpoints of the partition where the current effective value D1 is located are averaged, and then the average is output as the offset Diff corresponding to the current effective value D1. Considering that it is impossible to exhaustively cover all possible effective values D1 when making the effective value D1-offset Diff mapping relationship table, therefore, if the current effective value D1 has no corresponding value in the preset effective value D1-offset Diff mapping relationship table, then the average is output as the offset Diff corresponding to the current effective value D1 by averaging the offset Diffs mapped to the two endpoints of the partition where the current effective value D1 is located.
[0019] In one of the embodiments, in step S10, AD sampling is performed on the periodic variable signal by a timer.
[0020] At the same time, the present invention also provides an AD sampling and processing system based on a periodic variable signal.
[0021] An AD sampling and processing system based on a periodic variable signal is controlled by using the AD sampling and processing method based on a periodic variable signal of any of the above embodiments.
[0022] The above AD sampling and processing system based on periodic variable signals performs square sum processing on the sampled values dx collected within one cycle T0 of the variable signal, and then performs averaging processing according to the preset time interval T1. The processing method of square sum averaging can be used to measure the power of the signal. When the input power remains unchanged, a result with a very small oscillation amplitude can be obtained. Therefore, under this processing method, there is no need to pay attention to whether the circuit has a DC bias, full wave or half wave, or voltage divider ratio. Under the condition of ensuring that the input power remains unchanged, a relatively constant value, i.e., effective value D1, can be obtained. Then, the effective value D1 is used to look up the table to map the offset Diff, and then the effective value D1 and the offset Diff are summed to obtain the actual value D0. Through the above design, the MCU of the electronic device does not need to perform calculations according to the preset algorithms of different hardware circuits when performing AD sampling tasks, thereby reducing the amount of calculations and improving reliability. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 The present invention is a flowchart of an AD sampling and processing method based on a periodic variable signal according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without violating the connotation of the present invention, so the present invention is not limited by the specific embodiments disclosed below.
[0025] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as limiting the present invention.
[0026] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0027] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0028] In the present invention, unless otherwise clearly specified and limited, a first feature being "above" or "below" a second feature may mean that the first and second features are in direct contact, or the first and second features are in indirect contact through an intermediate medium. Moreover, a first feature being "above", "above" or "above" a second feature may mean that the first feature is directly above or obliquely above the second feature, or simply means that the first feature is higher in level than the second feature. A first feature being "below", "below" or "below" a second feature may mean that the first feature is directly below or obliquely below the second feature, or simply means that the first feature is lower in level than the second feature.
[0029] It should be noted that when an element is referred to as being "fixed to" or "disposed on" another element, it may be directly on the other element or there may be a central element. When an element is considered to be "connected to" another element, it may be directly connected to the other element or there may be a central element at the same time. The terms "vertical", "horizontal", "upper", "lower", "left", "right" and similar expressions used herein are for illustrative purposes only and are not intended to be the only implementation method.
[0030] like Figure 1 As shown, it is an AD sampling processing method based on a periodic variable signal according to an embodiment of the present invention.
[0031] like Figure 1 As shown, the AD sampling and processing method based on the periodic variable signal includes the steps of:
[0032] S10: Perform AD sampling on the periodic variable signal; wherein, the periodic variable signal is sampled once at every interval △t to obtain a sampling value dx; wherein, △t=(T0 / N1), T0 is the variation period of the periodic variable signal, and N1 is a positive integer.
[0033] For example, in step S10, AD sampling is performed on the periodic variable signal by a timer.
[0034] In step S10, in order to effectively sample the periodic variable signal during AD sampling, the sampling interval △t must not be greater than the period T0 of the periodic variable signal, so in this solution, △t is set to one N1 of T0. It should be noted that this solution is AD sampling for a known periodic variable signal, so T0 of the periodic variable signal is a known value.
[0035] Preferably, in step S10, if the number of bits of AD sampling is greater than 8, the sampling value dx is right-shifted so that the number of bits of the sampling value dx does not exceed 8. In order to reduce the computing load of the MCU, when the number of bits of AD sampling is greater than 8, the sampling value dx is right-shifted, thereby reducing the number of bits of the sampling value dx to be controlled within 8 bits. For example, if 10-bit AD sampling is used, the sampling result is limited, and the sampling value dx is right-shifted by 2 bits to be limited to 8 bits (i.e., within 2 to the 8th power).
[0036] S20: Calculate the square sum of the sampled values dx collected within one period T0 of the periodic variable signal to obtain SUM(∑dx 2 ).
[0037] For example, in step S20, if 100 valid sampling values dx are collected within a period T0, each sampling value dx is squared and then summed to obtain SUM(∑dx 2 ).
[0038] S30: SUM(∑dx 2 ) calculate the average to obtain the effective value D1; wherein, T1 = N2*T0, and N2 is a positive integer.
[0039] In step S30, a calculation cycle T1 is defined as not less than two cycles T0, and all SUMs (∑dx 2) are summed and then the average value is calculated to obtain the effective value D1. Step S20 and step S3 are the core processing steps of this solution. The processing method of using the square sum to calculate the average can be used to measure the power of the signal. When the input power remains unchanged, a result with a very small oscillation amplitude can be obtained. The purpose is to find the corresponding effective value based on the input power, thereby ignoring the algorithmic influence caused by the specific hardware settings in the circuit, such as DC bias, full-wave or half-wave processing, and voltage division ratio, etc., and there is no need to introduce a filtering algorithm in the subsequent process.
[0040] Further, in step S30, the value of N2 is a positive integer not less than 2. When the value of N2 is larger, the interference of noise can be reduced by sampling a plurality of cycles, thereby reducing the influence of noise on the operation result and achieving a filtering effect. Therefore, the value of N2 is preferably a positive integer not less than 2.
[0041] S40: Find the offset Diff mapped to the effective value D1 in step S30 from the preset effective value D1-offset Diff mapping relationship table, and then sum the effective value D1 and the offset Dif to obtain the actual value D0.
[0042] In step S40, the mapping relationship table of effective value D1-offset Diff is a relationship table pre-stored in the storage unit of the circuit. After obtaining the effective value D1 in step S30, the corresponding offset Diff can be found by looking up the table, and then the actual value D0 can be obtained by summing the effective value D1 and the offset Dif, that is, D0=D1+Diff.
[0043] In this embodiment, the method for obtaining the mapping relationship table of effective value D1-offset Diff includes the following steps:
[0044] S01: Provide a signal source to the electronic device through a frequency converter and perform AD sampling processing.
[0045] S02: gradually adjust the output signal of the frequency converter to the electronic device according to the preset signal strength interval and record the actual value D0' at each adjustment; at the same time, execute steps S10, S20, and S30 to obtain the effective value D1 corresponding to each actual value D0', calculate the difference between each effective value D1 and the corresponding actual value D0, and obtain the offset Diff=D0'-D1;
[0046] S03: Create a mapping relationship table of effective value D1-offset Diff and archive it.
[0047] The frequency converter is used as an adjustable and stable signal source to simulate the periodic variable signal when the electronic device is working. By gradually adjusting the signal strength, the mapping relationship between the actual value D0' and the offset Diff calculated according to steps S10 to S30 is measured, thereby establishing a mapping relationship table of the effective value D1-offset Diff. For each electronic device, an exclusive mapping relationship table of the effective value D1-offset Diff can be obtained.
[0048] Further, in step S40, if the current effective value D1 has no corresponding value in the preset effective value D1-offset Diff mapping relationship table, then the partition in the effective value D1-offset Diff mapping relationship table where the current effective value D1 is located is found, and the offset Diffs corresponding to the two endpoints of the partition where the current effective value D1 is located are averaged, and then the average is output as the offset Diff corresponding to the current effective value D1. Considering that it is impossible to exhaustively cover all possible effective values D1 when making the effective value D1-offset Diff mapping relationship table, therefore, if the current effective value D1 has no corresponding value in the preset effective value D1-offset Diff mapping relationship table, then the average is output as the offset Diff corresponding to the current effective value D1 by averaging the offset Diffs mapped to the two endpoints of the partition where the current effective value D1 is located.
[0049] Brief description of working principle:
[0050] After the sampling values dx collected within a period T0 of the variable signal are processed by square sum, they are averaged according to the preset time interval T1. The square sum averaging method can be used to measure the power of the signal. When the input power remains unchanged, a result with a very small oscillation amplitude can be obtained. Therefore, under this processing method, there is no need to pay attention to whether the circuit has a DC bias, whether it is a full wave or a half wave, or whether it is a voltage divider ratio. While ensuring that the input power remains unchanged, a relatively constant value, namely the effective value D1, can be obtained. Then, the offset Diff is mapped out by looking up the table through the effective value D1, and the actual value D0 of the periodic variable signal is D1+Diff.
[0051] The above-mentioned AD sampling processing method based on periodic variable signals enables the MCU of the electronic device to perform AD sampling tasks without having to perform calculations according to algorithms preset by different hardware circuits, thereby reducing the amount of calculations and improving reliability.
[0052] For ease of understanding, the AC voltage sampling of 50Hz (corresponding to a period of 20ms) is taken as an example:
[0053] During sampling, the AC voltage is AD sampled at an interval of 100 μs using a timer to obtain a sampled value dx, and the number of sampling times within 20 ms is 200.
[0054] Next, the square sum of the 200 sampled values is calculated to obtain SUM(∑dx 2 ).
[0055] Next, the above SUM(∑dx 2 ) to find the average value and obtain the effective value D1.
[0056] Finally, the table is looked up according to the obtained effective value D1 to find out the offset Diff mapped thereto, and the actual value D0 = D1 + Diff.
[0057] The mapping relationship table of effective value D1-offset Diff is as follows:
[0058] Serial number D1 value / V Offset Diff / V 0 28 82 1 30 85 2 34 86 3 37 88 4 41 89 5 43 92 6 47 93 7 50 95 8 54 96 9 58 97 10 62 98 11 66 99 12 70 100 13 75 100 14 79 101 15 84 101 16 89 101 17 94 101 18 99 101 19 104 101 20 109 101 21 114 101 22 120 100 23 126 99 24 131 99 25 138 97 26 143 97 27 150 95 28 156 94 29 163 92 30 169 91
[0059] For example, if the effective value D1 calculated according to the AD sampling processing method of this solution is 28, then a table lookup shows that the offset is 82, and the actual value D0=28+82=110.
[0060] For example, if the effective value D1 calculated by the AD sampling processing method of this solution is 40, then it can be seen from the table that when the effective value D1 is 40, it is in the [37, 41] partition of the D1 value. Therefore, the offset Diff corresponding to the effective value D1 is (88+89) / 2=88.5. At this time, the value after the decimal point is discarded by default in the calculation of the MCU (the common specification MCU does not have the calculation capability of rounding, and chooses to directly erase the decimal place), then the offset Diff is 88, and the actual value D0=40+88=128.
[0061] Furthermore, the above-mentioned AC voltage AD sampling processing method is verified, and the frequency converter is used as the experimental signal source. At this time, the voltage output by the frequency converter is the most accurate real value D0'. The program of the electronic device executes the above AD sampling method to obtain the calculated actual value D0, and compares the error between D0' and D0, that is, δ = ABS (D0-D0') / D0', where ABS is the operation symbol of the absolute value function in the Excel table. The results are as follows:
[0062]
[0063] At the same time, the present invention also provides an AD sampling and processing system based on a periodic variable signal.
[0064] The AD sampling and processing system based on a periodic variable signal is controlled by using the AD sampling and processing method based on a periodic variable signal in any of the above embodiments.
[0065] The above AD sampling and processing system based on periodic variable signals performs square sum processing on the sampled values dx collected within a period T0 of the variable signal, and then performs average processing according to the preset time interval T1. The processing method of square sum averaging can be used to measure the power of the signal. When the input power remains unchanged, a result with a very small oscillation amplitude can be obtained. Therefore, under this processing method, there is no need to pay attention to whether the circuit has a DC bias, full wave or half wave, or voltage divider ratio. Under the condition of ensuring that the input power remains unchanged, a relatively constant value, namely the effective value D1, can be obtained. Then, the offset Diff is mapped out by looking up the table through the effective value D1, and the actual value D0 of the periodic variable signal is D1+Diff. Through the above design, the MCU of the electronic device does not need to perform calculations according to the preset algorithms of different hardware circuits when performing AD sampling tasks, thereby reducing the amount of calculations and improving reliability.
[0066] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0067] The above embodiments only express the preferred implementation modes of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for those of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.
Claims
1. An AD sampling and processing method based on a periodic variable signal, characterized in that: Includes steps: S10: performing AD sampling on the periodic variable signal; wherein the periodic variable signal is sampled once at every interval △t to obtain a sampling value dx; wherein △t=(T0 / N1), T0 is the variation period of the periodic variable signal, and N1 is a positive integer; S20: Calculate the square sum of the sampled values dx collected within one period T0 of the periodic variable signal to obtain SUM(∑dx 2 ); S30: SUM(∑dx 2 ) calculate the average to obtain the effective value D1; wherein, T1 = N2*T0, and N2 is a positive integer; S40: Find the offset Diff mapped to the effective value D1 in step S30 from the preset effective value D1-offset Diff mapping relationship table, then the actual value D0 of the periodic variable signal = D1 + Diff.
2. The AD sampling and processing method based on periodic variable signals according to claim 1, characterized in that: In step S10 , if the number of bits of the AD sampling is greater than 8, the sampling value dx is right-shifted so that the number of bits of the sampling value dx does not exceed 8.
3. The AD sampling and processing method based on periodic variable signals according to claim 1, characterized in that: In step S30, the value of N2 is a positive integer not less than 2.
4. The AD sampling and processing method based on periodic variable signals according to claim 1, characterized in that: The method for obtaining the mapping relationship table of the effective value D1-offset Diff comprises the steps of: S01: Provide signal source to electronic equipment through frequency converter and perform AD sampling processing; S02: gradually adjusting the output signal of the frequency converter to the electronic device according to the preset signal strength interval and recording the actual value D0' at each adjustment; at the same time, executing steps S10, S20, and S30 to obtain the effective value D1 corresponding to each actual value D0', and calculating the difference between each effective value D1 and the corresponding actual value D0' to obtain the offset Diff=D0'-D1; S03: Create a mapping relationship table of effective value D1-offset Diff and archive it.
5. The AD sampling and processing method based on periodic variable signals according to claim 1, characterized in that: In step S40, if the current effective value D1 has no corresponding value in the preset effective value D1-offset Diff mapping relationship table, then find out the partition in the effective value D1-offset Diff mapping relationship table where the current effective value D1 is located, and average the offset Diff corresponding to the two endpoints of the partition where the current effective value D1 is located, and output it as the offset Diff corresponding to the current effective value D1.
6. The AD sampling and processing method based on periodic variable signals according to claim 1, characterized in that: In step S10, AD sampling is performed on the periodic variable signal by a timer.
7. An AD sampling and processing system based on a periodic variable signal, characterized in that: The control is performed by using the AD sampling and processing method based on a periodic variable signal as described in any one of claims 1 to 6.
Citation Information
Patent Citations
TIADC system DC bias and gain error calibration method and device
CN112087232A
Frequency-adaptive AC signal effective value acquisition method
CN112505391A
Driving power supply control method, voltage effective value determination method, system and device
CN115734438A
Electric signal effective value calculation method and device, electronic equipment and storage medium
CN116381312A
Automatic detection method of radio frequency signal amplitude based on programmable function
CN116707528A