PsdData Class Instantiation

From ControlTheoryPro.com

Jump to: navigation, search
Symbol.gif
PsdData Class Instantiation
Green carrot left.gif
psdData Class Example psdData Class Coding Notes
Green carrot.jpg
In order to prevent spam, users must register before they can edit or create articles.

1 Introduction to psdData Class Instantiation

The instantiation of the psdData class for most input data is simple.

If you have a vector of frequencies and magnitudes from a measured or calculated PSD then you simply create the psdData class like this:

 >> a = psdData('My Test Data: PSD', freq, mag);

This will create a PSD with a frequency vector of freq and magnitude vector of mag. It will assume that freq is in Hz and mag is in rad/sec.

If you have a vector of time stamps (t) and magnitudes (mag) from sensor data or Simulink runs then you simply create the psdData class like this:

 >> a = psdData('My Test Data: Time Series', t, mag, 'time');

or

 >> a = psdData('My Test Data: Time Series', t, mag, 'time', window);

where window can be any number greater than 0 and less than or equal to the time length of the time vector t.

Below is a brief description of the arguements for a full psdData instantiation:

 >> [obj] = psdData(name, xData, yData, type, window, varargin);

Input Arguments:

  • name: Description of the data (this will become the title when the plot method is used)
  • xData: For PSD data vectors the xData is a vector of frequencies. For time series the xData is a vector of time stamps.
  • yData: For PSD data vectors the yData is a vector of magnitudes at the frequencies specified in xData. For time series data the yData is a vector of magnitudes at each time stamp in xData.
  • type: The psdData class can accept PSD vectors or it can create a PSD from time series data. If the input data is PSD data then type should be set to 'psd'. For time series inputs then type should be set ot 'time'.
  • window: (Optional and only valid for time series input data.) If this argument is set to empty ([]) then the window is the full time length of the measure time series. However, if you wished for the lower end of the PSD to end at 1 Hz then you could set the window argument to 1 (sec). For 1/2 Hz set the window argument to 2 (sec).
  • varargin: See Property/Value Pairs in Table 1 (next Section)

1.1 Valid Property/Value Pairs

The instantiation of the psdData class can include a number of property/value pairs for creating the psdData class properly. Table 1 shows the available properties and valid values for those properties.

Table 1: psdData Class Property/Value Pairs
Property Description Valid Values

Interpolate

Number of Total Points in Desired Vector

Integer > 0

PlotFreqUnit

Units to Plot PSD in

{Hz}|rad/sec

RootPSD

Some PSDs are specified in units per rt(Hz) instead of units2 per Hz. If the PSD is provided in units per rt(Hz) then this property should be set to TRUE.

{True}|False

TimeUnit

PSDs typically are measurements of acceleration, rate, or position. The psdData class defaults to rate but the if the data is jerk, acceleration, or position then the TimeUnit property should be changed to reflect the the proper measurement. This allows the psdData class to plot your PSD and RMS with the correct units. It also allows psdData to correctly change the units when the integrate or differentiate functions are called.

Jerk|Acceleration|{Rate}|Position

UnitBaseFreq

The base frequency unit for the PSD measurement. Currently psdData assumes the data is in Hz. (For time series inputs the PSD is in Hz by default.) If the data is provided in rad/sec then this property should be updated. This allows the plot method to provide use the correct units in the label and it is vital to the integration and differentiation methods.

{Hz}|rad/sec

UnitBaseMag

The PSD is a measurement of something over time. When the psdData class was created it was being used for measured rate data. Therefore the default unit is radians (rad). If the measurements were of translation instead of angle then this property would be changed to feet, meters, etc.

Any valid unit

2 Examples of Creation of the psdData Class from PSD data vectors

The most basic usage of the psdData class is to feed the class a vector of frequencies and magnitudes (at each frequency). The examples in this section are on how to create psdData classes using PSD data.

Let's define:

  • freq: Vector of frequencies from a measured or calculated PSD data set.
  • mag: Vector of magnitudes from a measured or calculated PSD data set.

Simple Instantiation:

 >> a = psdData('Example PSD', freq, mag);

Instantiation with property/value pair arguments:

 >> a = psdData('Example PSD', freq, mag, 'psd', [], 'interpolate', 5000);

Note that the 4th and 5th arguments ('psd' & []) are not property/value pair arguments. The psdData class can accept input data of type 'psd' or 'time' where type 'psd' require the 2nd and 3rd arguments (freq & mag) to be vectors of frequencies and magnitudes. The psdData class can also accept time series data (see next section).

3 Examples of Creation of psdData Class from Time Series Data Vectors

I find that the most common usage of the psdData class is with the use of time series data. I frequently use the psdData class to create PSDs (and calculate the RMS) from the Simulink Scope data. The examples below show how to use time series data:

Simple Instantiation:

 >> a = psdData('Example PSD from Time Series Data', time, magnitude, 'time'); 
 >> a = psdData('Example PSD from Time Series Data', time, magnitude, 'time', [], 'interpolate', 5000);

Simulink Example

 >> a = psdData('Example Simulink PSD', Scope.time, Scope.signals(1).values(:, 1), 'time', [], 'interpolate', 5000);

This will take Simulink scope data and calculate a PSD from it then interpolate the resulting frequency and magnitude vectors of the PSD to be 5000 points long. The maximum frequency of the PSD will be half the sample rate of the scope. The minimum PSD frequency will be equal to 1 over the total length of time captured by the scope.

4 How to use psdData class Property/Value pairs

The psdData class arguments are:

  1. Name
  2. Frequency Vector
  3. Magnitude Vector
  4. Type
  5. Window

After those arguments come the Property/Value pairs. The examples below start after the window argument.

Examples:

  • Create the psdData class with the vectors interpolated so that there are 5000 total points in the resulting vectors. The input vectors can have only a few points but the resulting vectors will be 5000 total points.
 >> a = psdData(..., 'interpolate', 5000);
  • Create the psdData class and set the units for the frequency points (x-axis) plotted in rad/sec instead of the default Hz.
 >> b = psdData(..., 'plotfrequnit', 'rad/sec');
  • Create the psdData class and set the PSD units to root Hz. The typical PSD has units of magnitude squared over Hz but a root PSD is magnitude over rt(Hz).
 >> c = psdData(..., 'rootpsd', true);
  • Create the psdData class and set the magnitude to a Jerk, Acceleration or Position (Rate is the default).
 >> d = psdData(..., 'timeunit', 'jerk');
 >> d = psdData(..., 'timeunit', 'acceleration');
 >> d = psdData(..., 'timeunit', 'position');
  • Create the psdData class and set the base frequency units of the PSD to rad/sec (default is Hz).
 >> e = psdData(..., 'unitbasefreq', 'rad/sec');
  • Create the psdData class and set the base amgnitude units to something other than rad.
 >> f = psdData(..., 'unitbasemag', 'm');
 >> f = psdData(..., 'unitbasemag', 'ft');
 >> f = psdData(..., 'unitbasemag', 'deg');
  • The Property/Value pairs can be combined in any order.
 >> g = psdData(..., 'interpolate', 5000, 'timeunit', 'jerk', 'plotfrequnit', 'rad/sec');
 >> g = psdData(..., 'plotfrequnit', 'rad/sec', 'interpolate', 5000, 'timeunit', 'jerk');