Script to create VCD file from simulink data
%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=
This scrip is used to generate a VCD file for the simulation data generated by
simulink. Generated VCD file can be opened in wave-analyzer tools like "GTKWave"
for analysis.
%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=
The steps to use the script is described here....
(1) Compile the .c file using command
>> mex mexWriteVCD.c
to generate the mex file which is being called in the script "CreateVCD.m".
Copy the generated mex file in the same location as CreateVCD.m
(2) Save the simulation data of simulink to base workspace using "To Workspace" blocks or data-logging feature of simulink.
(3) Simulation data should be in "Structure with Time (Time series)" formate AND data for
all the signals should have the same number of elemets. (Number of elements
in arrays for all the signals will be automatically same if they are generate
from same model at same time.)
For example:
signal1.Time = [1 2 3];
signal1.Data = [50 9 7];
signal2.Time = [1 2 3];
signal2.Data = [500 900 5500];
(4) Now its time to collect all the signal informations (name, datatype, flow & value)
in one structure which can be passed to script. Create an array of structure with
above fields as shown below
SignalStruct(n).Name --> String - Contains name of the signal
SignalStruct(n).Type --> String - contains data type of signal
SignalStruct(n).Flow --> String - showing signal flow ('Input' or 'Output')
SignalStruct(n).Value --> Array of signal value logged in the workspace.
DataType string can be one of the folowing
For bolean --> 'B'
For uint8 --> 'U8'
For uint16 --> 'U16'
For uint32 --> 'U32'
For uint64 --> 'U64'
For int8 --> 'S8'
For int16 --> 'S16'
For int32 --> 'S32'
For int64 --> 'S64'
For signle --> 'F32'
For double --> 'F64'
For Example:
SignalStruct(1).Name --> 'signal1'
SignalStruct(1).Type --> 'U8'
SignalStruct(1).Flow --> 'Input'
SignalStruct(1).Value --> signal1.Data;
SignalStruct(2).Name --> 'signal2'
SignalStruct(2).Type --> 'U8'
SignalStruct(2).Flow --> 'Output'
SignalStruct(2).Value --> signal2.Data;
Note: Store all input signals first in the array and then all output signals.
(5) Now call the CreateVCD.m with all the info as
CreateVCD([Full VCD file path & name without extension], signal1.Time, SignalStruct);
Time series (here signal1.Time) could be time vactor of any signal as they all are same.
(6) VCD file will be created with the given name & path which can be opened with supported
wave analyzer tools.
Here mex file is used for writing the data into the file. Using mex file reduces the
execution time by upto 80%.
Cite As
TAB (2025). Script to create VCD file from simulink data (https://www.mathworks.com/matlabcentral/fileexchange/36943-script-to-create-vcd-file-from-simulink-data), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Code Generation > HDL Verifier > Algorithm Verification > Simulink Cosimulation >
- FPGA, ASIC, and SoC Development > HDL Verifier > Algorithm Verification > Simulink Cosimulation >
Tags
Acknowledgements
Inspired by: Simulink block set for Gtkwave : An alternative of simulink scope.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.5.0.0 | v1.2 - Revome the characters $, # from identifier name. Modified resolution calculation to support upto 1 fs resolution. |
||
1.3.0.0 | Updated from Initial to v1.1
|
||
1.0.0.0 |