High-precision calibration method and system for digital sinusoidal signal generator
Through the particle swarm algorithm combined with the Raspberry Pi 4B and DA-AD development boards, the sine signal error curve is fitted, which solves the local optimal problem when fitting complex sinusoidal signals in the existing technology, and realizes high-precision signal calibration and Improved stability.
Patent Information
- Application Number
- CN202411212408.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-30
- Publication Date
- 2024-12-31
AI Technical Summary
The prior art is prone to falling into local optimal solutions when fitting complex sinusoidal signal errors, making it difficult to obtain high-precision signal calibration, especially for high-complexity functions containing multiple trigonometric function terms, resulting in signal instability and harmonic distortion. .
The particle swarm algorithm is used to combine Raspberry Pi 4B and DA-AD development board to generate an ideal sinusoidal array for DAC error extraction, and fit it through polynomial and trigonometric functions, using the global search ability and nonlinear optimization ability of the particle swarm algorithm to accurately compose it. Compensate the error curve.
High-precision fitting of sinusoidal signal errors is achieved, the risk of local optimal solutions is reduced, the stability and accuracy of the signal is improved, the time is short, and the fitting results are more in line with the actual error laws.
Smart Images

Figure CN119232150A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of instrumentation and relates to a high-precision calibration method and system for a digital sine signal generator Background Art
[0002] DAC is a converter that converts digital signals into analog current or voltage output. It is an important component that connects digital systems and natural information. It is widely used in integrated devices and systems such as control, communication, and detection. DAC is often used as a signal source in the design system to produce high-precision analog output. For example, a high-speed and high-precision signal generator requires high-performance DAC devices as support.
[0003] A sine signal generator is a common electronic device or circuit that can generate a stable and pure sine signal. It is widely used in industrial production, scientific experiments, communication systems, audio equipment, instrument calibration and measurement, and engineering design. The main function of a sine signal generator is to provide the required sine wave signal for various applications, meeting the needs of signal debugging, frequency response testing, communication signal generation, sound measurement and calibration, and circuit function verification. They play an important role in different fields and provide the basis and support for related applications.
[0004] Ideally, the DAC will convert the received digital signal into an analog signal at a certain ratio. However, due to manufacturing defects and the influence of the working environment, the actual DAC's digital-to-analog conversion ratio under different conditions is not a fixed constant, which mainly includes offset error, gain error and nonlinear error. These errors will cause signal instability and harmonic distortion, and have a great impact on the quality and accuracy of the converted analog signal, so it is necessary to compensate for the DAC error. Before compensation, the DAC error law is usually obtained by fitting, and then digital compensation is performed at the DAC input based on the error curve obtained by fitting.
[0005] The least squares method is the most commonly used method to solve curve fitting problems. The basic idea is to minimize the sum of squares of the residuals, which is called the least squares criterion. The least squares method is applicable to many fitting scenarios, especially polynomial fitting. However, for functions containing multiple trigonometric terms, with high complexity and degrees of freedom, it is easy to fall into local optimality, resulting in failure to obtain ideal fitting results. Therefore, the least squares method has limitations on the error of fitting sinusoidal signals.
[0006] The particle swarm algorithm originated from the study of bird flock predation behavior, and it seeks the global optimal solution through collaboration and information sharing between individuals in the group. When fitting nonlinear function expressions, the idea of the particle swarm algorithm is to randomly generate some parameter vectors, i.e. particles, in the function space. Each particle represents a set of function parameters, and then evaluates its quality based on the difference between the function represented by the particle and the actual data, and continuously updates the position and speed of all particles to search for the optimal solution in the space.
[0007] When fitting complex trigonometric functions, the particle swarm optimization algorithm has the following advantages over the least squares method:
[0008] (1) The particle swarm algorithm has the ability of global search, and can find the global optimal solution through multiple particles iterating in the search space. This is very valuable for fitting complex trigonometric functions, because the least squares method may fall into the local optimal solution and cannot obtain the global optimal fitting result.
[0009] (2) Nonlinear optimization: Particle swarm optimization is a nonlinear optimization algorithm that can handle complex nonlinear fitting problems. In contrast, the least squares method is a linear optimization method that may not be flexible and accurate enough for high-order or complex trigonometric function fitting.
[0010] (3) Robustness: The particle swarm algorithm is highly robust to outliers and noise. When fitting complex trigonometric functions, the data may be affected by noise or interference, and the particle swarm algorithm can reduce the sensitivity to outliers and improve the robustness of the fitting through the collaboration of multiple particles.
[0011] (4) Wide applicability: Particle swarm optimization has good applicability to different types of problems, including function optimization, fitting, combinatorial optimization, etc.
[0012] Therefore, when it is necessary to fit complex trigonometric functions and other types of nonlinear functions, the particle swarm algorithm is a more feasible choice. Of course, the particle swarm algorithm also has disadvantages, such as high sensitivity to parameter adjustment and high computational complexity. In specific applications, it is necessary to comprehensively consider the nature of the problem and actual needs and select an appropriate algorithm for fitting. Summary of the invention
[0013] The purpose of the present invention is to provide a high-precision calibration method and system for a digital sinusoidal signal generator, thereby compensating for errors and improving the accuracy of sinusoidal signals.
[0014] In order to achieve the above object, the present invention provides the following technical solutions:
[0015] A high-precision calibration system for a digital sinusoidal signal generator comprises an ideal sinusoidal signal array generation module, a data processing module and a sinusoidal signal error extraction module;
[0016] The sinusoidal signal error extraction module consists of a Raspberry Pi 4B and a DA-AD development board.
[0017] The ideal sine array is generated by the signal generation script written in the ideal sine signal array generation module as the ideal input of the DAC, simulating the scenario when the DAC is used as a sine signal generator; the generated ideal sine array is transferred to the Raspberry Pi 4B via a VNC file as the input of the sine signal error extraction hardware;
[0018] The DAC on the DA-AD development board is connected to the ADC. After the ideal sine array is input into the DAC, the DA-AD conversion program is started by the Raspberry Pi 4B. After receiving the ADC output result, it is temporarily stored in the Raspberry Pi 4B. The result is looped several times to obtain multiple groups of outputs, and the actual output array is obtained. Then the data is sent back to the data processing module for processing via VNC file transfer.
[0019] A high-precision calibration method for a digital sine signal generator, the specific process is as follows:
[0020] S1: Generate an ideal sine array as DAC input through a script program;
[0021] S2: Raspberry Pi 4B and DA-AD development board form the sinusoidal signal error extraction hardware, perform the DA-AD conversion process, and obtain the actual output array at the ADC output for error extraction;
[0022] S3: DAC error curve is calculated based on the actual output array and the ideal input array, and the error curve is fitted by polynomial type and trigonometric function type using the least square method and particle swarm algorithm respectively;
[0023] S4: Compensate the error fitting result to the DAC input, run the DA-AD conversion again to obtain the output array, and calculate the compensated DAC output error to characterize the accuracy of the sinusoidal signal.
[0024] Further, the step S2 is specifically as follows:
[0025] S21: The ADC output result should include DAC gain error, offset error, nonlinear error and random noise interference, wherein the random noise interference is reduced by averaging to obtain a systematic error law;
[0026] S22: The DAC in the sinusoidal signal error extraction hardware is 16 bits, and is the main object of error extraction, with DAC channel 0 as input; the ADC is 24 bits, and is a standard device with relatively negligible error, with ADC channel 0 as output;
[0027] Further, the step S3 is specifically as follows:
[0028] S31: The polynomial type adopts a third-order polynomial when verifying the fitting effect, and the form is:
[0029] y=w3x 3 +w2x 2 +w1x+w0
[0030] Where y is the actual output array, x is the ideal input array, and w3 to w0 are the coefficients to be fitted;
[0031] S32: The trigonometric function type adopts a sine function of superposition of fundamental wave and high-order harmonics when verifying the fitting effect, in the form of:
[0032] y=a0+a1*sin((2*π / N)*x)+a2*sin(2*(2*π / N)*x)+a3*sin(3*(2*π / N)*x)+a4*sin(4*(2*π / N)*x)+a5*sin(5*(2*π / N)*x)
[0033] Where a0 to a5 are coefficients to be fitted, and N is the number of signal sampling points per cycle.
[0034] The beneficial effects of the present invention are:
[0035] After comparison and research, the present invention uses a particle swarm algorithm to compensate for the error of the DAC generating a sinusoidal signal. This method can accurately fit the error curve in the form of a sinusoidal function, which takes less time. The error fitting in the form of a sinusoidal function is more in line with the theoretical error law when using a DAC to generate a sinusoidal signal, while the traditional least squares method is not ideal when fitting the sinusoidal error law. In addition, it is also verified that even if a polynomial form is used to fit the error law, the particle swarm algorithm can still show an effect that is basically consistent with the least squares method. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 is a flow chart of the method of the present invention;
[0037] Figure 2 Calibrate the system for the sine signal generator;
[0038] Figure 3 It is the result of DAC sinusoidal signal error extraction;
[0039] Figure 4 is the least squares error fit (polynomial);
[0040] Figure 5 is the least squares error fit (trigonometric function);
[0041] Figure 6 is the least squares error fitting parameter;
[0042] Figure 7 Implementing process for particle swarm algorithm;
[0043] Figure 8 is the particle swarm algorithm error fitting (polynomial);
[0044] Fig. 9 is the particle swarm algorithm error fitting (trigonometric function);
[0045] Fig.10 is the error fitting parameter of the particle swarm algorithm;
[0046] Fig.11 This is the error curve of the DAC output sinusoidal signal after compensation. DETAILED DESCRIPTION
[0047] The embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
[0048] like Figure 2 As shown, a high-precision calibration system for a digital sinusoidal signal generator comprises an ideal sinusoidal signal array generation module, a data processing module and a sinusoidal signal error extraction module;
[0049] The sinusoidal signal error extraction module is composed of a Raspberry Pi 4B and a DA-AD development board;
[0050] The ideal sine array is generated by the signal generation script written in the ideal sine signal array generation module as the ideal input of the DAC, simulating the scenario when the DAC is used as a sine signal generator; the generated ideal sine array is transferred to the Raspberry Pi 4B via a VNC file as the input of the sine signal error extraction hardware;
[0051] The DAC on the DA-AD development board is connected to the ADC. After the ideal sine array is input into the DAC, the DA-AD conversion program is started by the Raspberry Pi 4B. After receiving the ADC output result, it is temporarily stored in the Raspberry Pi 4B. The result is looped several times to obtain multiple groups of outputs, and the actual output array is obtained. Then the data is sent back to the data processing module for processing via VNC file transfer.
[0052] It should be noted that the above-mentioned ideal sinusoidal signal array generation module and data processing module are both implemented by running in Matlab.
[0053] The actual output array and the ideal input array are calculated in Matlab to obtain the DAC error curve. The error curves are averaged and the theoretical form should be a trigonometric function. The two types are fitted using the traditional least squares method and the particle swarm algorithm in Matlab. The RMSE and time consumption are used to analyze the fitting advantages of the particle swarm algorithm in the DAC application scenario.
[0054] The ideal DAC input is compensated with the error fitting result, and the compensated result is transmitted to the Raspberry Pi. The DA-AD conversion program is run again to obtain the compensated output array from the ADC output. The compensated DAC output error curve is calculated by the output array and the ideal input array, and the accuracy of the compensated sinusoidal signal is analyzed.
[0055] like Figure 1 , a high-precision calibration method for a digital sine signal generator, the specific process is as follows:
[0056] S1: Generate an ideal sine array as DAC input through a script program;
[0057] S2: Raspberry Pi 4B and DA-AD development board form the sinusoidal signal error extraction hardware, perform the DA-AD conversion process, and obtain the actual output array at the ADC output for error extraction;
[0058] S3: DAC error curve is calculated based on the actual output array and the ideal input array, and the error curve is fitted by polynomial type and trigonometric function type using the least square method and particle swarm algorithm respectively;
[0059] S4: Compensate the error fitting result to the DAC input, run the DA-AD conversion again to obtain the output array, and calculate the compensated DAC output error to characterize the accuracy of the sinusoidal signal.
[0060] In the above process, a script is used to create an ideal array of sinusoidal signals as DAC input. After being converted into analog signals by DAC, the ADC is used to collect and convert them back into digital signals. Then, the difference between the output digital signal and the ideal input digital signal is fitted to obtain the DAC error law. The mean square error between the fitting result and the actual error is used as the evaluation index to compare the fitting effects of the two methods. Finally, the DAC input is compensated according to the fitting error, and the DAC output error after compensation is observed.
[0061] When extracting the error of the sinusoidal signal generated by the DAC, the development board is configured through Raspberry Pi programming, and the DAC conversion frequency and ADC sampling frequency are set to 30kHz. At the same time, the ideal sine array is defined to consist of 512 digital quantities per signal cycle. In order to use the mean method to reduce the interference of random errors such as noise and improve the accuracy of the error law to be extracted, 100 DA-AD conversion cycles are performed during error extraction. The ADC output and the DAC ideal input are calculated as the difference between the corresponding sampling points, and the average of the 100 error results at each sampling point is taken to obtain the following: Figure 3 The error pattern shown.
[0062] The least squares fitting algorithm was written to perform polynomial fitting and trigonometric function fitting on the error extraction results. During the fitting process, it was found that the third-order function could roughly fit the error law, while for the fitting of trigonometric functions that were more in line with the actual error law, the least squares method fell into the local minimum point and did not obtain a good fitting effect. The effect of the least squares method on the error fitting using these two types of functions is as follows: Figure 4 and Figure 5 The fitting parameters are shown in Figure 6 shown.
[0063] Write a particle swarm fitting algorithm, the implementation process is as follows Figure 7 shown.
[0064] When the particle swarm algorithm is used to fit the error extraction results, it is found that for the third-order polynomial fitting error law, the particle swarm algorithm shows a fitting effect that is basically the same as the least squares method. For the trigonometric function fitting error law, the particle swarm algorithm consumes less time and also obtains a more ideal fitting effect. The RMSE value is lower, indicating that the particle swarm algorithm has better applicability for fitting the sinusoidal error law. The fitting results of the particle swarm algorithm are shown in Figure 2. Figure 8 and Fig. 9 The fitting parameters are shown in Fig.10 shown.
[0065] In order to fully verify the effect of using the particle swarm algorithm to fit the error law of trigonometric function, the corresponding compensation value is added to each digital quantity in the DAC input array according to the error fitting result. Then, the DA-AD conversion is run again, and the compensated DAC output error waveform is drawn according to the results collected by the ADC. Here, the average of 100 sets of experimental data is also used as the final result, as shown in Fig.11 Comparing this figure with the uncompensated error fitting curve in the previous article, it can be seen that the mean value of the error at each point after compensation has basically fallen back to near 0, leaving some random errors such as noise fluctuating around 0, that is, some system errors have been effectively reduced.
[0066] The above contents are merely examples and explanations of the structure of the present invention. The technicians in this technical field may make various modifications or additions to the specific embodiments described or replace them in a similar manner. As long as they do not deviate from the structure of the invention or exceed the scope defined by the claims, they should all fall within the protection scope of the present invention.
Claims
1. A high-precision calibration system for a digital sinusoidal signal generator, characterized in that: It includes an ideal sinusoidal signal array generation module, a data processing module and a sinusoidal signal error extraction module; The sinusoidal signal error extraction module is composed of a Raspberry Pi 4B and a DA-AD development board; The ideal sine array is generated by the signal generation script written in the ideal sine signal array generation module as the ideal input of the DAC, simulating the scenario when the DAC is used as a sine signal generator; the generated ideal sine array is transferred to the Raspberry Pi 4B via a VNC file as the input of the sine signal error extraction hardware; The DAC on the DA-AD development board is connected to the ADC. After the ideal sine array is input into the DAC, the DA-AD conversion program is started by the Raspberry Pi 4B. After receiving the ADC output result, it is temporarily stored in the Raspberry Pi 4B. The result is looped several times to obtain multiple groups of outputs, and the actual output array is obtained. Then the data is sent back to the data processing module for processing via VNC file transfer.
2. A high-precision calibration method for a digital sine signal generator, characterized in that: The specific process is as follows: S1: Generate an ideal sine array as DAC input through a script program; S2: Raspberry Pi 4B and DA-AD development board form the sinusoidal signal error extraction hardware, perform the DA-AD conversion process, and obtain the actual output array at the ADC output for error extraction; S3: DAC error curve is calculated based on the actual output array and the ideal input array, and the error curve is fitted by polynomial type and trigonometric function type using the least square method and particle swarm algorithm respectively; S4: Compensate the error fitting result to the DAC input, run the DA-AD conversion again to obtain the output array, and calculate the compensated DAC output error to characterize the accuracy of the sinusoidal signal.
3. A high-precision calibration method for a digital sinusoidal signal generator according to claim 2, characterized in that: S2 is specifically: S21: The ADC output result should include DAC gain error, offset error, nonlinear error and random noise interference, where the random noise interference is reduced by averaging to obtain the systematic error law; S22: In the sinusoidal signal error extraction hardware, the DAC is 16 bits, and DAC channel 0 is used as input; the ADC is 24 bits, and ADC channel 0 is used as output.
4. A high-precision calibration method for a digital sinusoidal signal generator according to claim 3, characterized in that: S3 is specifically: S31: The polynomial type uses a third-order polynomial when verifying the fitting effect, in the form of: y=w3x 3 +w2x 2 +w1x+w0 Where y is the actual output array, x is the ideal input array, and w3 to w0 are the coefficients to be fitted; S32: The trigonometric function type uses a sine function that superimposes the fundamental wave and higher harmonics when verifying the fitting effect. The form is: y=a0+a1*sin((2*π / N)*x)+a2*sin(2*(2*π / N)*x)+a3*sin(3*(2*π / N)*x) +a4*sin(4*(2*π / N)*x)+a5*sin(5*(2*π / N)*x) Where a0 to a5 are coefficients to be fitted, and N is the number of signal sampling points per cycle.
Citation Information
Cited By
Current sensor error analysis system for multi-dimensional signal anomaly detection
CN122692857A
Current sensor error analysis system for multi-dimensional signal anomaly detection
CN122692857B
