View License

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

» Watch video

Highlights from
Script to create VCD file from simulink data

3.0 | 1 rating Rate this file 4 Downloads (last 30 days) File Size: 6.99 KB File ID: #36943 Version: 1.5
image thumbnail

Script to create VCD file from simulink data


TAB (view profile)


31 May 2012 (Updated )

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

| Watch this File

File Information

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


Simulink Block Set For Gtkwave : An Alternative Of Simulink Scope. inspired this file.

Required Products Simulink
MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
18 Jan 2013 Vit

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

07 Jun 2012 1.3

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

12 Jun 2012 1.5

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

Contact us