PsdData Properties
 PsdData Properties psdData Class Example psdData Methods In order to prevent spam, users must register before they can edit or create articles.

## 1 Introduction to psdData Class Properties

In Stochastic Controls Power Spectral Densities (PSDs) are often used to represent or define disturbance and noise environments. However, there are several implementation issues that must be dealt with when using PSDs.

The basics of a PSD are as follows:

1. The PSD is represented in MATLAB by a vector of frequencies and magnitudes at those frequencies.
2. PSDs typically (but not always) have units of magnitude squared (^2) over Hz.
3. The primary metric used to compare one PSD to another is the Root Mean Square (RMS).
• As with most metrics the RMS does not tell you everything.
• Particularly important is where in the frequency range does most of the PSD energy resides. More specifically, "Is the energy in the low, mid, or high frequency range by comparison to your designed rejection and performance requirements?"

Some of the PSD implementation issues are:

1. PSD measurements are often very coarse particularly in the low frequencies. The result of this is that low frequency measurements might be at 0.01 Hz, 0.1 Hz, 1 Hz, 2 Hz, 5 Hz, 10 Hz, ... For noise PSDs this is not usually an issue. However, disturbance PSDs are often dominated by low frequency content. The RMS is an integration under the curve and coarse measurements often lead to inaccurate RMS calculations.
2. Addition and subtraction of PSDs must occur at the same frequency and this often dictates the use of an interpolated PSD.
3. Measured data comes in the form that is easiest to capture with the least noise. This often leads to measurements in rate (from good MEMS gyros) or acceleration (from good MEMS accelerometers). While the measurements are in rate or acceleration the disturbances that need to be in any simulation may need to be integrated to a position PSD.

## 2 psdData Class Properties

All of the property attributes that a MATLAB class can have may be found in the article: MATLAB 2009a Class Property Attributes.

The psdData Class object uses 3 types of property attributes:

1. Public: These are the most commonly used and needed properties
2. Private: These are read-only properties
3. Hidden: These are read-write properties that you shouldn't need to change and won't show up when you type the variable for the class into the MATLAB command prompt

### 2.1 Display of the psdData Class

Let's psdData Class Instantiation class object:

``` >> a = psdData('Test PSD', time, data, 'type', [], 'interpolate', 5000);
```

Then the displayed properties and values are:

```               >> a
psdData
Properties:
Name: 'Test PSD'
Freq: [1x5000 double]
Mag: [1x5000 double]
UnitBaseFreq: 'Hz'
RootPSD: 0
PlotFreqUnit: 'Hz'
psdData_Version: 0.1000
xTime: [32768x1 double]
yTime: [32768x1 double]
Methods
```

In this case you can see that the time vector was a 32768x1 vector stored in the private property xTime. This is a private property and private class properties can only be set through psdData class methods. The UnitBaseFreq, UnitBaseMag, RootPSD, and PlotFreqUnit are set to the values shown by default. They can all be set using the instantiation method (the call to psdData as shown above) or by using a command like this:

``` >> a.UnitBaseMag = 'meters';
```

or

``` >> a.UnitBaseFreq = 'rad/sec';
```

### 2.2 Public Properties

Public properties are visible and settable via the property name - a.{Property} - such as:

``` >> a.Freq
```

or

``` >> a.Name = 'My PSD Data';
```

Below is the MATLAB code for the Public properties of the psdData Class.

```               % --- Public Properties
properties
Name = ;
Freq = [];
Mag = [];
UnitBaseFreq = 'Hz';
RootPSD = false;
PlotFreqUnit = 'Hz';
end % --- properties
```

Description:

• Name: The name or description of the class. This is used in plotting and should describe the data in a unique manner.
• Freq: Vector of frequencies in Hz or rad/sec but the class will assume Hz unless UnitBaseFreq is set to 'rad/sec';
• Mag: Vector of magnitudes at the frequencies in Freq. The class will assume the units are 'rad^2 / Hz' unles UnitBaseFreq, UnitBaseMag, or RootPSD are changed.
• UnitBaseMag: Base Magnitude Units for the PSD. If the PSD is '(m/s)^2 / Hz' then UnitBaseMag should be set to 'm/s'. This defaults to 'rad'.
• UnitBaseFreq: Units for frequency vector. Valid values are 'Hz' and 'rad/sec'. Defaults to 'Hz'.
• RootPSD: Some measurement equipment will return a PSD in units / √Hz instead of units^2 / Hz. (Some noise specifications for sensors are also provided in √Hz.) This is referred to a Root PSD for purposes of the psdData class. The RootPSD property defaults to FALSE, however, should the PSD be provided in this manner then the RootPSD property should be set to TRUE.
• PlotFreqUnit: This property sets the frequency units desired on any output plot. It defaults to 'Hz' but can be changed to 'rad/sec'.

### 2.3 Private Properties

These properties are visible and returnable (i.e. a.xTime will return a value). However, the values of these properties can only be set by psdData class methods.

Below is the MATLAB code for the Private properties of the psdData Class.

```               % --- Private Properties
% The following properties can be set only by class methods
properties (SetAccess = private)
psdData_Version = 0.1;
xTime = [];
yTime = [];
end % --- properties (SetAccess private)
```

Description:

• psdData_Version: This is the version of the psdData class that you are using. For the most part this is useless. However, as the class matures this parameter may become useful when dealing with legacy code.
• xTime: If the class is instantiated with time series data instead of frequency and magnitude vectors then the original time stamps are stored in the xTime property. These time stamps are assumed to be in seconds and there is no means of changing that at this time.
• yTime: If the class is instantiated with time series data instead of frequency and magnitude vectors then the original measurements are stored in the yTime property.
• With time series data the units of the calculated PSD are the default units unless the user changes those properties to non-default values.

### 2.4 Hidden Properties

These properties are not visible but they are returnable and settable just like public properties. Like this:

``` >> a.TimeUnit
```

or

``` >> a.TimeUnit = 2;
```

Knowing the property name allows you to set them and return them. These properties are Hidden primarily because the user shouldn't need access to them.

Below is the MATLAB code for the Hidden properties of the psdData Class.

```               % --- Hidden Properties
properties (Hidden)
TimeUnit = 3;			% Rate --> Jerk = 1, Accel = 2, Rate = 3, Pos = 4, ...
TimeStrs = {'Jerk', 'Acceleration', 'Rate', 'Position'};
MinNumPnts = 5000;
clrs = {'b', 'r', 'g', 'm', 'k', 'c'};
lines = {'-', '-.', '--', '.-'};
end % --- properties (Hidden)
```

Description:

• TimeUnit: This is an index into TimeStrs (and can be used beyond the provided TimeStrs). This defaults to a values of Rate which equal to 3 but also equal to 'units/sec'. When the PSD is integrated the class is smart enough to change the TimeUnit to 4 where it becomes 'units'. Should the PSD be integrated again then TimeUnit becomes 5 and the base unit of the PSD is 'units-sec'.
• TimeStrs: This cell array contains descriptions of the most common measurements. Because of this string the psdData class can be instantiated with a property pair of (..., 'TimeUnit', 4) or (..., 'TimeUnit', 'Position'). See psdData Class Instantiation for more information.
• MinNumPnts: This is the minimum number of points to check for in the PSD - whether provided directly or calculated from time series data. If the PSD does not contain this many points a warning will be displayed when using the psdData RMS method. When using the psdData plot method the forward and backward RMSs are compared. If the two RMS calculations don't agree then this is a sign that the PSD is too coarse. The coarse PSD is interpolated so that it has MinNumPnts and the RMSs are recalculated.
• clrs & lines: The plotted lines are a combination of clrs and lines. The first PSD plotted will be 'b-', the second 'r-.', the third 'g--', and so on. The fifth will be 'k-' - the 5th from clrs and the 1st from lines since there are only 4 - and the seventh will be 'b--'.

## 3 Notes

None at this time.