The communication process between Matlab and TDS series digital oscilloscope

Publisher:缘到泉Latest update time:2015-07-06 Source: dzscKeywords:Matlab Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  Tektronix's TDS series digital real-time oscilloscopes have been widely used in China. The expansion modules TDS2CM and TDS2MM have the ability to communicate with external devices in two directions. They can be directly connected to printers and microcomputers, making the storage and printing of waveforms very convenient. TDS2MM also has FFT function, which can perform real-time spectrum analysis on waveforms. The Wavestar software distributed with the same machine provides the function of two-way communication between PC and oscilloscope, and has a good user interface. However, its data processing function is very limited. It can only measure the amplitude, frequency, period, rise and fall time of the waveform. In addition, most users configure the TDS2CM module for price considerations. It does not have the spectrum analysis function of the TDS2MM module, which limits the further development and utilization of the oscilloscope. Matlab, the famous numerical calculation software of Mathworks, has powerful numerical calculation functions. Its Instrument Control Toolbox provides powerful peripheral control functions, which can control GPIB, RS-232, VXI, and Centronics ports. The data communication between the oscilloscope and the microcomputer can be realized by using Matlab and TDS2CM module. The waveform data recorded by the oscilloscope can be analyzed and processed by using the powerful numerical processing and matrix operation functions of Matlab.

  Digital oscilloscopes are high-performance oscilloscopes made with a series of technologies such as data acquisition, A/D conversion, and software programming. Digital oscilloscopes generally support multi-level menus, which can provide users with a variety of choices and analysis functions. Some oscilloscopes can also provide storage to save and process waveforms. At present, high-end digital oscilloscopes mainly rely on American technology. For oscilloscopes within 300MHz bandwidth, domestic brands of oscilloscopes can compete with foreign brands in performance and have obvious cost-effectiveness advantages. Digital oscilloscopes are becoming increasingly popular because of their unique advantages such as waveform triggering, storage, display, measurement, and waveform data analysis and processing. Due to the large performance difference between digital oscilloscopes and analog oscilloscopes, if used improperly, large measurement errors will occur, thus affecting the test tasks.

  1 Communication Principles

  MATLAB is a high-tech computing environment released by MathWorks, an American company, mainly for scientific computing, visualization and interactive programming. It integrates many powerful functions such as numerical analysis, matrix calculation, scientific data visualization, and modeling and simulation of nonlinear dynamic systems in an easy-to-use window environment, providing a comprehensive solution for scientific research, engineering design and many scientific fields that must perform effective numerical calculations. It has largely gotten rid of the editing mode of traditional non-interactive programming languages ​​(such as C and Fortran), and represents the advanced level of international scientific computing software today. MATLAB, Mathematica and Maple are known as the three major mathematical software. It is second to none in numerical computing among mathematical science and technology application software. MATLAB can perform matrix operations, plot functions and data, implement algorithms, create user interfaces, connect programs in other programming languages, etc. It is mainly used in engineering computing, control design, signal processing and communication, image processing, signal detection, financial modeling design and analysis and other fields.

  The Instrument Control Toolbox in Matlab consists of two major components: M-file functions and interface driver adapters. These two components provide the communication function between Matlab and peripherals. The communication principle with the serial communication port is shown in Figure 1.

  As shown in Figure 1, the two major components of Matlab provide an interactive channel between the peripheral and Matlab, allowing users to obtain and transmit information between the peripheral. Like many high-level languages, Matlab creates a device object by calling the M file function to obtain the file handle of the device. The device driver, as a module in the operating system that directly controls the hardware, is a key module that links the operating system kernel and the I/O operations of the system's external devices. It hides the specific hardware details to achieve transparency of peripheral operations, so Matlab can implement read and write operations on peripherals like operating files. The data transmission format, input and output buffer size, and read and write overflow time during reading and writing are defined by the attribute values ​​in Figure 1, which are based on the specific communication port, communication method, and data size. The events and states generated by the oscilloscope are saved by the oscilloscope in the standard event status register (SESR), the status byte register (SBR), and the event queue for (Matlab) callback functions to read. At the same time, users can control which events or states are saved in the status register and event queue by setting the three enable registers: device event status enable register (DESER), event status enable register (ESER), and service request enable register (SRER). Matlab's setting query command for the oscilloscope is output in the form of a string by the fprintf function. The setting and query commands are defined by the specific oscilloscope manufacturer, and their format is: Header Arguments, with multiple parameters separated by commas. When reading and writing data of the oscilloscope waveform in binary format, the conversion between the read and write data and the actual data of the oscilloscope is given by the following formula:

  Xn=Xzero+Xincr·n

 

  Yn=Yzero+Ymult(yn-Yoff) (1)

  Among them, yn is the data in the input and output buffers, n is the number of data, and Xn and Yn are the actual sampling time and signal amplitude in the oscilloscope.

  2 Data Transmission

  In the field of communication, there are two data communication modes: parallel communication and serial communication. With the development of computer networking and hierarchical distributed application systems of microcomputers, the function of communication is becoming more and more important. Communication refers to the transmission of information between computers and the outside world, including both transmission between computers and transmission between computers and external devices such as terminals, printers and disks. Serial communication refers to the use of a data line to transmit data one bit at a time, with each bit of data occupying a fixed length of time. It only requires a few lines to exchange information between systems, and is especially used for long-distance communication between computers and computers, and between computers and peripherals. [page]

  RS-232 serial communication interface is widely used in the mutual communication between computers and terminals at short distances. TDS210 oscilloscope is also equipped with RS-232 interface with DB9 plug-in. When hardware handshake is used for communication control, the oscilloscope uses three control signals CD, CTS, and RI to indicate its current state, while Matlab uses RTS signal to request data transmission. Since the asynchronous communication protocol does not require strict clock synchronization between the two communicating parties, the start bit of the data is used as the synchronization signal for the communication between the two parties. Therefore, asynchronous communication is used between Matlab and the oscilloscope. The part of the program compiled to read data from the oscilloscope is as follows:

  %Create device object

  g = Serial('COM1');

  %Communication initialization g.InputBufferSize=10000;

  g.timeout=10;

  %Set the transmission baud rate to 9600b/s, the character format to: 8 data bits, 1 stop bit, terminator to LF, no parity bit, use hardware handshake.

  g.BaudRate=9600;

  g.Parity='none';

  g.StopBits=1;

  g.Terminator='LF';

  g.FlowControl='hardware';

  %Connect device object

  fopen(g)

  %data transmission

  fprintf(g,'select: refa on');

  fprintf(g,'data:source refa');

  fprintf(g,'data:encdg srib');

  fprintf(g,'data:start 1');

  fprintf(g,'data:stop 2500');

  fprinft(g,data:width 2');

  fprintf(g,'wfmpre:xzero?');

  xzero = fscanf(g,'%f');

  fprintf(g,'wfmpre:xincr?');

  xincr = fscanf(g,'%f');

  fprintf(g,'wfmpre:yzero?');

  yzero = fscanf(g,'%f');

  fprintf(g,wfmpre:ymult?');

  ymult = fscanf(g,'%f');

  fprintf(g,'wfmpre:yoff?');

  yoff = fscanf(g,'%f');

  fprintf(g,'curve?');

  out=fread(g,2500,'int16');

  

  

  %Release device objects and ports

  fclose(g);

  delete(g);

  freeserial('com1');

  The square wave signal read by the oscilloscope using the above program is shown in Figure 2.

  3 Data Analysis and Examples

  The data read from the oscilloscope is converted according to formula (1) to achieve the measured waveform data value, and the corresponding sampling frequency is 1/Xincr. The signal in L1 space meets the absolute integrability condition, and the spectrum analysis can be directly performed using the fast Fourier transform algorithm. Figure 3 shows the FFT result of the read square wave. Since the interception of the sampled signal is equivalent to adding a rectangular window to the signal, it will inevitably cause spectrum leakage and aliasing. Under the conditions of satisfying the sampling theorem and ensuring the integrity of the oscilloscope waveform cycle, the spectrum analysis result is independent of the number of waveform cycles obtained by the oscilloscope. The power spectrum estimation can be performed for the noise signal, and the power spectrum estimation of the above sampled signal is shown in Figure 4.

  From the above data communication process and the example of spectrum analysis and power spectrum estimation of sampled signals, it can be seen that Matlab and oscilloscope form a signal acquisition and analysis system, in which the oscilloscope plays the role of data acquisition and storage, while Matlab realizes the analysis and processing of the sampled signals.

Keywords:Matlab Reference address:The communication process between Matlab and TDS series digital oscilloscope

Previous article:Briefly describe the effects of digital oscilloscope dead time and waveform capture rate on measurement results
Next article:Why is the impedance of the oscilloscope 1M and 50 ohms?

Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号