MATLAB Example 2. Pre-Emphasis Script

Meas. mode:
Scope
Eye
TDR
Package License:
L-RND
L-SNT

This MATLAB example creates a pre-emphasis measurement that runs in oscilloscope mode in the FlexDCA / MATLAB environment. The measurement takes one source waveform as an input and runs two dependent measurements. Dependent measurements are automatically run before the script. The dependent measurement results are passed as variables to your script. Although not required, it is a good practive to give the XML file and script files the same or similar base filename, but using different filename extensions of course! As the number of your measurements grow, you'll appreciate being able to quckly associate the different files at a glance.

Color has been added to the following example lines of the XML and script code to make them easier to read. After you finish this lesson, continue with Example 3 to convert this operator into a MATLAB standalone application.

Procedure

  1. Complete Example 1, if you have not already done so.
  2. Place FlexDCA into Oscilloscope mode and display a single-valued waveform.
  3. Copy the following XML listing into a text editor. Name the XML file PreEmphasis.xml and save the file in FlexDCA's user measurements folder (\Documents\Keysight\FlexDCA\User Measurements).
    • Later, when this XML file is imported into the User Measurement Setup dialog, it identifies the PreEmphasis.m script, populates the dialog, identifies two dependent measurements, and creates the user measurement button as shown in these figures.

Copy

PreEmphasis.xml

<?xml version="1.0" encoding="utf-8"?>
<Measurement xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Script>PreEmphasis.py</Script>
<Name>Pre-Emphasis</Name>
<Abbreviation>PreEmp</Abbreviation>
<!-- <Icon>MyPicture.png</Icon> -->
<Comments>This measures the amount of pre-emphasis on a signal.</Comments>
<MeasurementType>1 Source</MeasurementType>
<ValidMode>Scope</ValidMode>
<Dependent Name = "Amplitude">
    <SourceIndex>1</SourceIndex>
</Dependent>
<Dependent Name = "Peak-Peak">
    <SourceIndex>1</SourceIndex>
</Dependent>
</Measurement>
    

The <Icon> element is optional. This element allows you to place a picture on your user operator icon.
Example without <Icon> element Example with <Icon> element
  1. Copy the following script into MATLAB's editor and save the script as PreEmphasis.m in FlexDCA's user measurements folder (\Documents\Keysight\FlexDCA\User Measurements). In the following script notice:
    • Output variables that are initialized and input waveform, SrcData, is tested for data.
    • Dependent measurements (MeasData structure) that is iterated through checking for valid results.
    • The Result output variable that is assigned the value of the pre-emphasis measurement.

    Copy

    PreEmphasis.m

    % These values need to be set by the script.
    % Set Status to Correct only when Result is computed.
    Result = 0.0;Units = 'dB';Status = 'Invalid';ErrorMsg = '';
    % Do nothing if there is no input waveform.
    if isempty(SrcData)
       return;
    end
    % Variables only get cleared when a MATLAB measurement is installed.
    % So, clear dependent measurement results to prevent another MATLAB
    % measurement from creating them and confusing the script.
    clear Vpp Vamptd
    % Iterate through MeasData to find V p-p and V amptd
    NumMeas = length(MeasData);
    for i=1:NumMeas
       if strcmp(MeasData(i).Name, 'Peak-Peak') &amp;&amp; strcmp(MeasData(i).Source1, Source)
          Vpp.Result = MeasData(i).Result;
          Vpp.Status = MeasData(i).Status;
          Vpp.Source = MeasData(i).Source1;
       elseif strcmp(MeasData(i).Name, 'Amplitude') &amp;&amp; strcmp(MeasData(i).Source1, Source)
          Vamptd.Result = MeasData(i).Result;
          Vamptd.Status = MeasData(i).Status;
          Vamptd.Source = MeasData(i).Source1;
       end;
    end;
    % Verify required measurements have been made.
    if (~exist('Vpp') || ~exist('Vamptd'))
       ErrorMsg = ['Error: Unable to retrieve "Peak-Peak" and "Amplitude" measurements.\n' ...
          'Please be in Oscilloscope Mode and make "Peak-Peak" and "Amplitude" '...
          'measurements from Amplitude Measurement Tab on ' Source '.'];
       
       return;
    end;
    % Compute Result
    Result = 20 * log10(Vpp.Result/Vamptd.Result);
    % Status of dependent measurements
    if (strcmp(Vpp.Status, 'Correct') &amp;&amp; strcmp(Vamptd.Status, 'Correct'))
       Status = 'Correct';
    elseif (strcmp(Vpp.Status, 'Invalid') || strcmp(Vamptd.Status, 'Invalid'))
       Status = 'Invalid';
       % Return now before possibly setting to Questionable later.
       return;
    else
       Status = 'Questionable';
    end

    Do not use spaces or hyphens when selecting a filename for your script.

    Enter the above script exactly as written. Otherwise, the script will fail.

  2. In FlexDCA's User measurement tab, click the User Meas Setup button.
  3. In the dialog, select an available tab.
  4. Click Browse and select your XML configuration file, PreEmphasis.xml and close the dialog.
  5. Click on your new Pre-Emphasis measurement button and view the results in the Results panel. Notice that the results of the two dependent measurements are not listed.
  6. You may have to wait a few seconds for the waveform to appear.