File Exchange

image thumbnail

Script to create VCD file from simulink data

version 1.5 (6.99 KB) by

This scrip is used to generate a VCD file for the simulation data generated by simulink.



View License

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%.

Comments and Ratings (1)


Vit (view profile)

thank you - you saved my time. I can confirm it can store file from matlab vector and then open them using cadence simvision 8.20.

But I hit problem with time axes - due to some adjustments it has more decimal point and script was not capable of distinguish required precision - I modify it to specify precision manually and it works nicely...



v1.2 - Revome the characters $, # from identifier name. Modified resolution calculation to support upto 1 fs resolution.


Updated from Initial to v1.1
Fixed the bug in CreateVCD.m which was causing error when sample time >= 1sec.

MATLAB Release
MATLAB 7.5 (R2007b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today