UWAR:Tutorial:Matlab

From PublicWiki
Jump to: navigation, search


Running Matlab

Matlab (7.0 R14) is available for departmental Linux machines in the /projects/matlab directory. You can run Matlab with the following command from your favorite shell:

   /projects/matlab/bin/matlab

If you are in an X11 environment, this will bring up a graphical front-end to Matlab. There is also a terminal-based interface available, but you will not be able to display plots and other visualizations in terminal-mode.

Running Matlab From Windows

If you are not lucky enough to have your own copy of Matlab for your Windows machine, you can still run departmental Matlab. You can always SSH into one of the cycle servers and run Matlab from the command line. Alternately, if you need full X11 support, you can do X11 forwarding to your Windows machine as described here:

http://www.cs.washington.edu/lab/remote-access/xclients.html

Adding UWAR Support

To add UWAR functions to Matlab, add the following path in Matlab:

   >> addpath('/projects/ubicomp/uwar/bin/matlab2');

General Notes

It's important to note that all timestamps are specified in number of milliseconds since the Unix epoch. This number is directly comparable with the results of the Unix time command and time values in Java (ex. System.currentTimeMillis()).

Summary of UWAR Matlab Functions

All of the following Matlab functions should have internal help documentation, such that calling help function_name from within Matlab will produce useful documentation concerning functionality and calling conventions.

  • IO Functions:
    • uwar_io_init - Loads the UWAR Java IO library. Only call this directly if you are using a custom jar (that should be very few of you)
    • uwar_io_getSensorIds - List the available sensor data in a UWAR trace
    • uwar_io_getSensorData - Extract sensor data from a UWAR trace

Tutorial Data

Looking for UWAR Trace files to use in this tutorial? Check out files in:

   /projects/ubicomp/uwar/data/Tutorials

Loading UWAR Sensor Data Into Matlab

Loading UWAR sensor data into structures that can be easily handled by Matlab is one of the key first steps before more complex operations can be performed. Fortunately, the UWAR:Tools:IO input/output library makes it relatively easy to load UWAR data into Matlab.

Consider the tutorial trace Trace-ipaq.uwar. We can list the sensors data available in the trace by calling:

   >> uwar_io_getSensorIds('Trace-ipaq.uwar')
   
   ans = 
   
       'wifi'
       'latlon'
       'clock'

The uwar_io_getSensorIds function should produce a cell-array of sensor id names for data present in the trace. A similar call reveals the sensors present in the tutorial trace Trace-msp.uwar:

  >> uwar_io_getSensorIds('Trace-msp.uwar')

  ans =

      'msb/light_infrared'
      'msb/bar_temp_press'
      'MSPPowerLevels'
      'MicroStrain3DMGX1'
      'msb/sht_temp_humidity'
      'msb/hf_vis_light'
      'msb/acceleration'
      'msb/light_visible'

Once we have determined what data is available, we can retrieve the data itself with calls to uwar_io_getSensorData. Let's pull the 'wifi' data from the Trace-ipaq.uwar trace:

  >> r = uwar_io_getSensorData('Trace-ipaq.uwar','wifi')

  r =

        sensorId: 'wifi'
      timestamps: [2518x1 double]
          fields: {'bssid'  'rssi'}
            data: {{2518x1 cell}  [2518x1 int32]}

Here we see the general form for all data returned by uwar_io_getSensorData. The data is captured in a Matlab structure with the following fields:

  • sensorId - the name of the sensor for the data
  • timestamps - a vector of timestamps for each row of data
  • fields - the name of the columns for each column of data for the sensor
  • data - the actual columns of data, whose individual types are determined by the type of field

You'll notice that the timestamp vector and each data column vector should have the same size. While each vector may have the same size, we don't present them as one large matrix because the data types for each column may not support such a representation. For example, the 'bssid' data for the 'wifi' sensor is a collection of BSSID strings, which can't go in a matrix, but rather a cell.

It may help to think of the above data structure as a table in a database. The table has a name, which maps to the sensorId field. The table will always have a timestamps column for representing the time index of each records in the table. The table has additional columns, where each column has a name as represented by the fields field. The data for the table is presented in a column-by-column representation as represented by the data field.

Also just like a database table, you can think of sensor having its own schema. That is to say, the 'wifi' sensor will always have two fields 'bssid' and 'rssi'. Each sensor will have its own schema, and while there is no formal documentation for this schema outside of the source code itself, the format of the data should be relatively straight-forward upon examination in Matlab.

Other Matlab Resources