Oscilloscope spectrum analysis method based on Qt
By using QCustomPlot and FFTW libraries in Qt development, the problem of QT native graphics library QChart has been solved, and efficient time domain graph and spectrum graph mapping is realized, which meets actual work needs and improves the cross-platform capability and real-timeness of the software.
Patent Information
- Application Number
- CN202411738988.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-14
AI Technical Summary
In the prior art, when using Qt's native graphics drawing library QChart, the data volume will cause lag when it is large, which cannot meet the actual work needs.
The third-party library QCustomPlot and FFTW libraries are used, combined with Qt development, and the oscilloscope spectrum analysis method is implemented, the main thread is notified to process data through the signal and slot mechanism, and the time domain diagram and spectrum diagram are drawn using QCustomPlot when initializing the graphics drawing area.
Even if the data volume reaches 100,000 levels, the program using QCustomPlot drawing still runs smoothly and there is no lag, which meets the actual production needs and improves the cross-platform capability of the software and the real-time data reception.
Smart Images

Figure CN119621218A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of wind power generation, and in particular to an oscilloscope spectrum analysis method based on Qt. Background Art
[0002] In actual work, it is usually necessary to use display and control software to collect data from the signal acquisition board to check whether the signal acquisition board is working properly. At the same time, the corresponding time domain diagram of the collected data is drawn in the display and control software, and the corresponding Fourier transform curve is drawn in real time based on the collected data after analysis. Therefore, the frequency and other information of the data can be determined based on the drawn image.
[0003] Furthermore, Qt's native graphics drawing library QChart can be used to draw real-time curves, but when the amount of data is large, if native QChart is used, the program will be very stuck when the amount of data reaches 2000. After consulting the information, it is necessary to turn on OpenGL at the same time when using QChart to draw curves. Therefore, OpenGL is turned on as needed, and the program operation has improved significantly. Even if the amount of data reaches 20,000, there will be no stuck. However, after exceeding 20,000, such as when the amount of data is 25,000, there will still be very obvious stuck. The current minimum amount of data is more than 100,000. If the above method is used, it will be far from meeting the actual work needs. Therefore, it is urgent to adopt another method to solve the problem of program stuck. Summary of the invention
[0004] To solve the above technical problems, the present invention provides an oscilloscope spectrum analysis method based on Qt, wherein a new Qt project is created, a QCustomPlot library and an FFTW library are imported for subsequent drawing of curve graphs, a new UDPSocket class is created as a network class for communication between a host computer and a slave computer, a new fftwCalcul class is created for calculating the FFT of a data point, and a corresponding spectrum graph is drawn according to the FFT, comprising the following steps:
[0005] Step S1: Initialize the graphics drawing area;
[0006] Step S2: Drawing function, after receiving a complete frame of data, notifies the main thread to process the data through the signal and slot mechanism, and starts drawing the time domain graph and spectrum graph corresponding to the data;
[0007] Step S3: Data playback function. After receiving a frame of data, the Qt display control software writes the data into a file and stores it in the local disk for subsequent data playback.
[0008] In one embodiment of the present invention, during the initialization in step S1, the indicator light displaying the system self-test result on the software interface is gray, indicating that the system has not started. If a fault occurs in the lower computer system, the display and control interface will change the indicator light state to red based on logical judgment. When the lower computer system is working normally, the indicator light on the display and control interface will be green.
[0009] In one embodiment of the present invention, when the program receives data uploaded by the lower computer or plays back data in step S3, the upper left corner of the program software interface is a time domain diagram of the data, and the lower left corner of the interface is a spectrum diagram corresponding to the data time domain diagram according to Fourier transform.
[0010] In one embodiment of the present invention, the pseudo code of the drawing function part of step S2 is as follows:
[0011]
[0012] In one embodiment of the present invention, the data playback in step S3 is as follows, and the pseudo code snippet is used to obtain all files in a specified format in a selected folder before data playback:
[0013]
[0014] The following pseudo code snippet is used for data playback, which reads all the acquired files in sequence and processes and plays them back:
[0015]
[0016]
[0017] }.
[0018] The above technical solution of the present invention has the following advantages over the prior art: the oscilloscope spectrum analysis method described in the present invention integrates the third-party library file QCustomPlot, which has better drawing capabilities than Qchart. At the same time, the use of Qt for development greatly improves the cross-platform capability of the software, and the software has good real-time performance in receiving data, which can better meet actual production needs. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to make the contents of the present invention more clearly understood, the present invention is further described in detail below based on specific embodiments of the present invention in conjunction with the accompanying drawings.
[0020] Figure 1 It is a software interface diagram of oscilloscope spectrum analysis implemented based on Qt in the present invention;
[0021] Figure 2 It is a software interface diagram of a failure of the lower computer system described in the present invention;
[0022] Figure 3 It is a software interface diagram of the normal operation of the lower computer system of the present invention;
[0023] Figure 4 It is a program operation interface diagram of the data playback described in the present invention;
[0024] Figure 5 It is a time domain diagram of the program operation data of the present invention;
[0025] Figure 6 It is an enlarged view of the time domain data described in the present invention. DETAILED DESCRIPTION
[0026] Currently, the methods for drawing curve graphs in Qt include: Qt built-in chart QChart, third-party library file QCostomPlot, QWT, etc. Since the program is running with a very obvious jam when using the built-in chart QChart to draw the curve, it cannot meet the actual work needs. Therefore, we try to reconstruct the program framework and use the third-party library QCustomPlot to draw the curve. After testing, even when the amount of data reaches 100,000, the program using QCustomPlot to draw the curve still runs smoothly without jamming, so it can better meet the functional requirements in actual project applications.
[0027] After drawing the data points, since it is difficult to understand a signal from the time domain, it is necessary to analyze the drawn graph and simultaneously draw its corresponding discrete Fourier transform curve. By converting the time domain signal into the frequency domain signal, the signal analysis is more intuitive and efficient.
[0028] This embodiment provides an oscilloscope spectrum analysis method based on Qt, wherein a new Qt project is created, a QCustomPlot library and an FFTW library are imported for subsequent drawing of curve graphs, a new UDPSocket class is created as a network class for communication between a host computer and a slave computer, a new fftwCalcul class is created for calculating the FFT of a data point, and a corresponding spectrum graph is drawn according to the FFT, including the following steps:
[0029] 1) Graphic drawing area initialization. Here we only list the graphic interface initialization of the time domain diagram. The drawing interface initialization of the spectrum analysis diagram is similar and will not be repeated here.
[0030]
[0031]
[0032] When the mouse is pressed, released, or moved, the corresponding processing is analyzed. For example, when the mouse moves, the X and Y points corresponding to the current point will be displayed at the cursor. The significance of this method is that the peak value of the waveform can be obtained through this method. When the right mouse button is pressed and released, a rectangular area will be obtained. When the mouse is released, the graphic will be enlarged according to the selected rectangular area. The pseudo code corresponding to the mouse event is as follows:
[0033]
[0034]
[0035] 2) Drawing function: after receiving a complete frame of data, the main thread is notified through the signal and slot mechanism to process the data and start drawing the time domain graph and spectrum graph corresponding to the data.
[0036]
[0037] 3) Data playback function: after receiving a frame of data, the display and control software writes the data into a file and stores it in the local disk for subsequent data playback.
[0038] The following pseudo code snippet is used to obtain all files of a specified format in a selected folder before data playback.
[0039]
[0040]
[0041] The following pseudo code snippet is used for data playback, which reads all the acquired files in sequence and processes and plays them back.
[0042]
[0043] }
[0044] After drawing the data points, since it is difficult to understand a signal from the time domain, it is necessary to analyze the drawn curve graph and simultaneously draw its corresponding high-scatter Fourier transform curve. By converting the time domain signal into the frequency domain signal, the signal analysis is more intuitive and efficient.
[0045] So after completing all the above steps, connect the upper computer and the lower computer so that they can communicate normally. The upper computer sends the working parameters, and the lower computer will start working and send data to the upper computer. The upper computer can change the working status of the lower computer by adjusting the parameters.
[0046] The initial state of the program is as follows Figure 1As shown, the indicator light showing the system self-test result is gray, indicating that the system is not started. If the lower computer system fails, the display control software will change the indicator light state to red based on logical judgment. Figure 2 As shown;
[0047] When the lower computer system is working normally, the indicator light of the display and control software will be green. Figure 3 shown.
[0048] When the program receives data uploaded by the lower computer or plays back data, the program running interface is as follows Figure 4 As shown, the upper left corner of the interface is the time domain diagram of the data, and the lower left corner of the interface is the spectrum diagram corresponding to the data time domain diagram according to Fourier transform. It can be seen from the diagram that the frequency of the data signal is approximately 100KHZ.
[0049] Due to the large amount of data, when drawing the time domain graph, it can be found that all the data points are piled up together, which cannot be effectively observed and analyzed. Therefore, it is necessary to enlarge the time domain graph. By enlarging the time domain graph, the trend and curve characteristics of the time domain graph can be clearly seen, as shown below Figure 5 and Figure 6 As shown, the time domain diagram can be partially enlarged by rolling the mouse wheel.
[0050] The method of this embodiment integrates the third-party library files Q0ustcP1ot_ and FFIW, and can draw the corresponding channel analysis diagram in real time while drawing the time domain diagram: compared with Qchart, it has good drawing capabilities, and is developed using Qchart, which greatly improves the cross-platform capability of the software, and the software has good real-time data reception, which can better meet actual production needs.
[0051] The oscilloscope spectrum analysis method described in this embodiment is based on the attached Figures 4 to 6The test results show that the system method is relatively complete. It has good performance and can draw time domain graphs and their corresponding spectrum analysis graphs at the same time. Compared with the previous chart drawing method, only 30,000 data can be drawn at most. However, when drawing 25,000 data in actual use, the program has been running with obvious jams, which seriously affects the use: but when using QCustompPlot to draw graphics, even if 100,000 data are drawn, the program is very smooth to use, and the performance has been greatly improved. At the same time, in this software, mouse events are rewritten, including mouse click events, cursor release events, drag events, etc. Users can freely zoom in, zoom out, and drag the time domain and spectrum analysis graphs on the drawing interface, and can also zoom in and out of the graphs locally, which greatly facilitates viewing and analysis. The corresponding working parameters can be changed according to needs, which can meet the commonly used data frequency analysis. In actual applications, it can also be modified according to the needs of the project, so that different analysis functions can be realized.
[0052] In summary, the oscilloscope spectrum analysis method of this embodiment is implemented in software:
[0053] a) The upper computer and the lower computer communicate through UDP;
[0054] b) The upper computer software can send working parameters to the lower computer software to control the working mode of the lower computer;
[0055] c) The upper computer receives the data uploaded by the lower computer in real time, and draws a time domain diagram and its corresponding spectrum analysis diagram on the interface according to the data;
[0056] d) The host computer needs to store the received data in real time and have the function of data playback.
[0057] Obviously, the above embodiments are merely examples for clear explanation and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived from these are still within the protection scope of the invention.
Claims
1. An oscilloscope spectrum analysis method based on Qt, characterized in that: A new Qt project is created, and the QCustomPlot library and FFTW library are imported for subsequent drawing of curve graphs. A new UDPSocket class is created as the network class for communication between the host computer and the slave computer. A new fftwCalcul class is created to calculate the FFT of the data points and draw the corresponding spectrum according to the FFT. The following steps are included: Step S1: Initialize the graphics drawing area; Step S2: Drawing function, after receiving a complete frame of data, notifies the main thread to process the data through the signal and slot mechanism, and starts drawing the time domain graph and spectrum graph corresponding to the data; Step S3: Data playback function. After receiving a frame of data, the Qt display control software writes the data into a file and stores it in the local disk for subsequent data playback.
2. The oscilloscope spectrum analysis method according to claim 1, characterized in that: During the initialization in step S1, the indicator light showing the system self-test result on the software interface is gray, indicating that the system has not started. If a failure occurs in the lower computer system, the display and control interface will change the indicator light status to red based on the logic judgment. When the lower computer system is working normally, the indicator light on the display and control interface will be green.
3. The oscilloscope spectrum analysis method according to claim 1, characterized in that: When the program receives data uploaded by the lower computer or plays back data in step S3, the upper left corner of the program software interface is a time domain diagram of the data, and the lower left corner of the interface is a spectrum diagram corresponding to the data time domain diagram according to Fourier transform.
4. The oscilloscope spectrum analysis method according to claim 1, characterized in that: The pseudo code of the drawing function part of step S2 is as follows:
5. The oscilloscope spectrum analysis method according to claim 1, characterized in that: The data playback in step S3 is as follows: the pseudo code snippet is used to obtain all files in the specified format in the selected folder before data playback: The following pseudo code snippet is used for data playback, which reads all the acquired files in sequence and processes and plays them back: