Products & Services Solutions Academia Support User Community Company

Learn more about xPC Target   

Signal Logging

Introduction

Signal logging is the process for acquiring signal data during a real-time run, stopping the target application, and then transferring the data to the host PC for analysis. This is also known as real-time data streaming to the target PC. You can plot and analyze the data, and later save it to a disk. xPC Target signal logging samples at the base sample time. If you have a model with multiple sample rates, add xPC Target scopes to the model to ensure that signals are sampled at their appropriate sample rates.

Signal Logging with xPC Target Explorer

You plot the outputs and states of your target application to observe the behavior of your model, or to determine the behavior when you vary the input signals and model parameters.

This procedure uses a model named xpc_osc4.mdl as an example and assumes you have created a target application and downloaded it to the target PC. The xpc_osc4.mdl is the same as the my_xpc_osc3.mdl tutorial model with the xPC Target Scope block removed.

To create xpc_osc4:

  1. In the MATLAB window, type

    xpc_osc3

    The xpc_osc3 model opens.

  2. In the Simulink window, select and delete the xPC Target Scope block and its connecting line.

  3. From the File menu, click Save as. Enter xpc_osc4 and then click Save.

You can now build and download the model (see Building and Downloading the Target Application in the xPC Target Getting Started Guide).

  1. In xPC Target Explorer, select the downloaded target application node. For example, xpc_osc4.

    The right pane displays the target application properties dialog box for xpc_osc4.

  2. In the Logging pane, select the boxes of the signals you are interested in logging. For example, select Output and TET. Click Apply.

  3. Start the target application. For example, in the xPC Target Hierarchy pane, right-click the xpc_osc4 target application, then select Start.

  4. Stop the target application. For example, in the Target Hierarchy pane, right-click the xpc_osc4 target application, then select Stop.

  5. Send the selected logged data to the MATLAB workspace. In the target application properties dialog box for xpc_osc4, go to the Logging pane and click the Send to MATLAB Workspace button.

    In the MATLAB desktop, the Workspace pane displays the logged data.

You can examine and otherwise manipulate the data.

Signal Logging in the MATLAB Interface

You plot the outputs and states of your target application to observe the behavior of your model, or to determine the behavior when you vary the input signals and model parameters.

Time, states, and outputs — Logging the output signals is possible only if you add Outport blocks to your Simulink model before the build process, and in the Configuration Parameters Data Import/Export node, select the Save to workspace check boxes. See Entering Parameters for the Outport Blocks of the xPC Target Getting Started Guide.

Task execution time — Plotting the task execution time is possible only if you select the Log Task Execution Time check box in the Configuration Parameters xPC Target options tab. This check box is selected by default. See Adding an xPC Target Scope Block of the xPC Target Getting Started Guide.

All scopes copy the last N samples from the log buffer to the target object logs (tg.TimeLog, tg.OutputLog, tg.StateLog, and tg.TETLog). The xPC Target software calculates the number of samples N for a signal as the value of Signal logging buffer size in doubles divided by the number of logged signals (1 time, 1 task execution time ([TET]), outputs, states).

After you run a target application, you can plot the state and output signals. This procedure uses the Simulink model xpc_osc3.mdl as an example, and assumes you have created and downloaded the target application for that model. It also assumes that you have assigned tg to the appropriate target PC.

  1. In the MATLAB window, type

    tg=xpc
  2. Type

    +tg

    or

    tg.start

    or

    start(tg)

    The target application starts and runs until it reaches the final time set in the target object property tg.StopTime.

    The outputs are the signals connected to Simulink Outport blocks. The model xpcosc.mdl has just one Outport block, labeled 1, and there are two states. This Outport block shows the signals leaving the blocks labeled Integrator1 and Signal Generator.

  3. Plot the signals from the Outport block and the states. In the MATLAB window, type

    plot(tg.TimeLog,tg.Outputlog)

    Values for the logs are uploaded to the host PC from the target application on the target PC. If you want to upload part of the logs, see the target object method getlog.

    The plot shown below is the result of a real-time execution. To compare this plot with a plot for a non-real-time simulation, see Simulating the Model from MATLAB of the xPC Target Getting Started Guide.

  4. In the MATLAB window, type

    plot(tg.TimeLog,tg.TETLog)

    Values for the task execution time (TET) log are uploaded to the host PC from the target PC. If you want to upload part of the logs, see the target object method getlog.

    The plot shown below is the result of a real-time run.

    The TET is the time to calculate the signal values for the model during each sample interval. If you have subsystems that run only under certain circumstances, plotting the TET would show when subsystems were executed and the additional CPU time required for those executions.

  5. In the MATLAB window, type either

    tg.AvgTET

    or

    get(tg,'AvgTET')

    The MATLAB interface displays the following information about the average task execution time.

    ans =
      5.7528e-006

The percentage of CPU performance is the average TET divided by the sample time.

Note that each outport has an associated column vector in tg.OutputLog. You can access the data that corresponds to a particular outport by specifying the column vector for that outport. For example, to access the data that corresponds to Outport 2, use tg.outputlog(:,2).

Signal Logging with a Web Browser

When you stop the model execution, another section of the Web browser interface appears that enables you to download logging data. This data is in comma-separated value (CSV) format. This format can be read by most spreadsheet programs and also by the MATLAB interface using the dlmread function.

This section of the Web browser interface appears only if you have enabled data logging, and buttons appear only for those logs (states, output, and TET) that are enabled. If time logging is enabled, the first column of the CSV file is the time at which data (states, output, and TET values) was acquired. If time logging is not enabled, only the data is in the CSV file, without time information.

You analyze and plot the outputs and states of your target application to observe the behavior of your model, or to determine the behavior when you vary the input signals.

Time, states, and outputs — Logging the output signals is possible only if you add Outport blocks to your Simulink model before the build process, and in the Configuration Parameters Data Import/Export node, select the Save to workspace check boxes. See Entering Parameters for the Outport Blocks in xPC Target Getting Started Guide.

Task execution time — Logging the task execution time is possible only if you select the Log Task Execution Time check box in the Configuration Parameters xPC Target options node. This check box is selected by default. See Entering Parameters for an xPC Target Scope Block in xPC Target Getting Started Guide.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2010- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS