MATLAB Examples

Save an Infiniium waveform

The Keysight Infiniium application can load waveform data from a MATLAB® .mat file. The file must contain a set of required information, and be formatted in the right way. Waveform data, for example, must be converted to the int16 data type. The InfiniiumWaveform toolbox provides functions for automating this process, making it easy to create your own Infiniium waveform files. These files can be opened from within the Infiniium oscilloscope application.

There are two ways to save data to an Infiniium waveform .mat file. The simplest way is to use the infiniiumWfmSave utility function. This function does all the necessary formatting so that the file can be opened by Infiniium. It allows you to customize many of the file parameters as well, but is limited to saving only one waveform to each file. For users who want to save multiple waveforms to a single file, or who want low-level control over the data, the InfiniiumMatFile class offers an alternative. Note: In order to open multiple-waveform files in the Keysight Infiniium application, open them as 'Composite' files.

Contents

Path

In order to use the InfiniiumWaveform functions and the example files in this demo, they need to be on the MATLAB path. See the instructions in 'Setting the MATLAB Path' in either the InfiniiumWaveform help documents, or the UserGuide in help\html.

Set up the files

This demo uses some files which are included in the toolbox.

inputFilename = 'channel_1_Demo.mat';     % file has one waveform
multiFilename = 'multiChannel_Demo.mat';  % file has two waveforms
outputFilename = 'tmp.mat';               % output file

Save a waveform using infiniiumWfmSave

Create and save waveforms using raw data. You can open the output files in the Infiniium application.

Create some waveform data

x0 = 0;                         % waveform start time
dx = 1e-9;                      % waveform sample time
N = 100;                        % number of waveform samples
x = x0 + (0:N-1)*dx;            % time value of all samples
y = sin(pi*x/1e-8)';            % create waveform data (as a column vector)
figure(1), hold off, plot(x,y)  % plot the waveform data

Save data to file using default options.

infiniiumWfmSave(y,x0,dx,outputFilename);

Change the x-units for the data from seconds to meters.

infiniiumWfmSave(y,x0,dx,outputFilename,'XUnits','Meter');

Change the y-units for the data from volts to amps. Note, changes to the file are not cumulative. Even though the previous function call set the x-units to meters, the following function call will save data using the default x-units of seconds.

infiniiumWfmSave(y,x0,dx,outputFilename,'YUnits','Amp');

Change the way the waveform is displayed horizontally on the scope. Set the left axis to 5 ns, and the total range displayed to be 50 ns.

infiniiumWfmSave(y,x0,dx,outputFilename,'XDispOrigin',5e-9,'XDispRange',50e-9);

Change the way the waveform is displayed vertically on the scope. Set the center axis to .2, and the total range displayed to be 4 volts

infiniiumWfmSave(y,x0,dx,outputFilename,'YDispOrigin',.2,'YDispRange',4);

Change the source label of the waveform. Note: this will not affect the way the waveform is displayed on the scope, but can be helpful to have more meaningful labels when working with offline files.

infiniiumWfmSave(y,x0,dx,outputFilename,'Source','Filter2');

The InfiniiumMatFile class

The infiniiumWfmSave function uses the InfiniiumMatFile class to save Keysight Infiniium .mat files. Advanced users can use this class directly when dealing with files that have more than one waveform. It will save all of the waveforms in a file, and it allows for more low-level control.

Waveform data is stored in the class as an array of WaveformData objects. The WaveformData class is a simple class for holding data for a single waveform, and can do some basic tasks such as plotting the data.

Note: the InfiniiumMatFile is located in the +infiniiumWfm package directory. This prefix must be used when accessing the class and its methods, as demonstrated in the following examples. Also, the class is a handle class, which means that the class constructor returns a handle, or reference, to the object. Any function that modifies a handle object, passed as an input argument, does not need to return the object. See the MATLAB help files under Advanced Software Development for more on packages and handle versus value classes.

Save multiple waveforms using the InfiniiumMatFile class

Start with the data created above and create a second waveform. Store both waveforms as an [N,2] array.

y2 = .9*y;         % create a second waveform
yy = [y,y2];       % combine waveforms. each are column vectors

Initialize an InfiniiumMatFile object using default settings, and save to file.

obj = infiniiumWfm.InfiniiumMatFile(yy,x0,dx);    % create object using infiniiumWfm prefix
saveWfms(obj,outputFilename);                     % save data to file

Inspect the file header information. The default source names for the waveforms are 'Matlab_x'.

wfms = infiniiumWfmInfo(outputFilename) %#ok<*NASGU,*NOPTS>
wfms =

  1×2 cell array

    'Matlab_1'    'Matlab_2'

Create a new object using different source labels.

obj = infiniiumWfm.InfiniiumMatFile(yy,x0,dx,{'Data_1','Data_2'});
obj.waveformSourceList
ans =

  1×2 cell array

    'Data_1'    'Data_2'

Manually change the waveform data.

wfm = getWaveform(obj,'Data_2');         % get the WaveformData object Data_2
wfm.y = wfm.y + .2*rand(size(wfm.y));    % add noise
wfm.source = 'Data_2_PlusNoise';         % create a new label

Plot the data. Note that the x and y labels on the graph are empty. This is because the wfm.fileData.XUnits and wfm.fileData.YUnits properties have not been set. These are only set when reading or saving files.

figure(2), hold off, plot(wfm)

Save the modified object data. Define x and y units. These units will be used for both waveforms in the file.

saveWfms(obj,outputFilename,'XUnits','Hertz','YUnits','dBm'); % save to file
wfms = infiniiumWfmInfo(outputFilename) % inspect results to see new source names
wfms =

  1×2 cell array

    'Data_1'    'Data_2_PlusNoise'

Make a new plot, showing the x and y labels created while saving.

figure(3), hold off, plot(wfm)