Languages

CommunityCategory: XMODELExporting waveform data in CSV format

XMODEL

Exporting waveform data in CSV format

SA Support Team Staff 2024-07-31

I'd like to post-process the waveforms simulated by XMODEL, using other tools. Is there a way to export the waveform data in a text format, such as CSV (comma-separated values)?

1 Answers
SA Support Team Staff 2024-07-31

Yes, you can use the XMULAN Python library to read a waveform file in JEZ format and export its waveform data in another format. Here is an example of a Python script exporting the waveform of a signal named 'TOP.A' stored in a file named 'xmodel.jez' in CSV format.

export_waveform.py:

#!/usr/bin/env xmodelpy

import xmulan
import csv

waveform_filename = "xmodel.jez"
signal_name       = "TOP.A"             
output_filename   = "data.csv"

# read waveform data
row = xmulan.rowml().readmeas(waveform_filename)
trace = row[signal_name]
wf = trace.get_waveform()
T, V = wf.sweep[0,:], wf

# write time-value pairs in CSV format
csvfile = open(output_filename, "w")
writer = csv.writer(csvfile)
writer.writerows(zip(T, V))
csvfile.close()

The script shown above will work equally well for xreal, xbit, real, wire, reg, and bit type signals. But for xreal type signals, you have multiple ways to get their time-value pairs.
For example, the get_waveform() method used in the script, by default, returns the time-value pairs of points that approximate the original waveform when they are connected in a piecewise-linear fashion. In this case, the returned points may have non-uniform time spacings.

wf = trace.get_waveform()
T, V = wf.sweep[0,:], wf

Alternatively, one may want to obtain the time-value pairs of points with uniform time spacings. To achieve this, you can use the mode="fixedstep" argument and assign the timestep value to the 'tstep' argument.

wf = trace.get_waveform(mode="fixedstep", tstep=1e-12)
T, V = wf.sweep[0,:], wf

Also, you can obtain the values of the waveforms sampled at a set of arbitrary time instants. Here is an example of sampling the waveform at 20ps intervals from 0 to 100ns.

import numpy as np

T = np.r_[0.0:100e-9:20e-12]
V = trace.eval_at(T)

XMODEL

파형 정보를 CSV 포맷으로 export하는 법

SA Support Team Staff 2024-07-31

XMODEL로 시뮬레이션한 파형을 다른 툴로 옮겨서 후처리를 하고 싶습니다. 파형 정보를 CSV와 같은 텍스트 형식으로 export하는 방법이 있을까요?

1 Answers
SA Support Team Staff 2024-07-31

Yes, you can use the XMULAN Python library to read a waveform file in JEZ format and export its waveform data in another format. Here is an example of a Python script exporting the waveform of a signal named 'TOP.A' stored in a file named 'xmodel.jez' in CSV format.

export_waveform.py:

#!/usr/bin/env xmodelpy

import xmulan
import csv

waveform_filename = "xmodel.jez"
signal_name       = "TOP.A"             
output_filename   = "data.csv"

# read waveform data
row = xmulan.rowml().readmeas(waveform_filename)
trace = row[signal_name]
wf = trace.get_waveform()
T, V = wf.sweep[0,:], wf

# write time-value pairs in CSV format
csvfile = open(output_filename, "w")
writer = csv.writer(csvfile)
writer.writerows(zip(T, V))
csvfile.close()

The script shown above will work equally well for xreal, xbit, real, wire, reg, and bit type signals. But for xreal type signals, you have multiple ways to get their time-value pairs.
For example, the get_waveform() method used in the script, by default, returns the time-value pairs of points that approximate the original waveform when they are connected in a piecewise-linear fashion. In this case, the returned points may have non-uniform time spacings.

wf = trace.get_waveform()
T, V = wf.sweep[0,:], wf

Alternatively, one may want to obtain the time-value pairs of points with uniform time spacings. To achieve this, you can use the mode="fixedstep" argument and assign the timestep value to the 'tstep' argument.

wf = trace.get_waveform(mode="fixedstep", tstep=1e-12)
T, V = wf.sweep[0,:], wf

Also, you can obtain the values of the waveforms sampled at a set of arbitrary time instants. Here is an example of sampling the waveform at 20ps intervals from 0 to 100ns.

import numpy as np

T = np.r_[0.0:100e-9:20e-12]
V = trace.eval_at(T)