Matlab to the Modelsim simulation data processing is also through the file read and write implementation. That is, through the Verilog statement, a signal in the simulation process is written to the file, and then in MATLAB in the data of this file read out, you can be analyzed in MATLAB.
A simple example is also given to illustrate the whole process.
The following Verilog statement is implemented to write the data of the signal data_out to the Data_out.txt file
Integer w_file;
Initial W_file = $fopen ("Data_out.txt");
Always @ (i)
Begin
$fdisplay (W_file, "%h", data_out);
if (i = = 8 ' d255)//total of 256 data written
$stop;
End
is part of the intercepted Data_out.txt:
Then you can make a small part of the MATLAB program to analyze the data read in the Data_out.txt. The following MATLAB program is to read the data, and graphically display the data waveform.
FID = fopen (' data_out.txt ', ' R ');
For i = 1:256;
num (i) = fscanf (FID, '%x ', 1); The meaning of this sentence is to read a data in 16 binary ways from the file that the FID refers to.
End
Fclose (FID);
Plot (num);
When using the FSCANF function, pay attention to two points,
First: Ensure that the read data format and the file is saved in the format of the data is the same, for example, the format of the file is hexadecimal, so read the time should also be read in 16 binary form.
Second: Be sure to keep the number of data in the file and the number of readings set (here is 256) consistent. For example, to get rid of the extra line breaks in the makefile data_out.txt (usually one more line in the end), MATLAB will use the empty line as a data, so that the two number is inconsistent, resulting in MATLAB error.
is the MATLAB will read the data in the Data_out.txt, and display the waveform:
Of course, with MATLAB this powerful tool, it can be very convenient to see the signal spectrum and other information.
In addition, there are a number of ways to write data to a file via Verilog, which is $fdisplay this system function, and of course, $fmonitor and $fwrite, and a few other commands, the following is a brief discussion of the different commands.
Analysis of data generated by Modelsim simulation by MATLAB