Programming Reference:PhysicalUnit Class

From BCI2000 Wiki
Jump to: navigation, search

Location

src/shared/types

Synopsis

An object of type PhysicalUnit represents a linear mapping from physical units to raw numbers, and an expected range of values. Apart from its use in conjunction with signal values, this class is also used for element or channel indexing when appropriate, e.g. to map a frequency value to a spectral bin (element index).

Methods

PhysicalUnit()

The constructor initializes a PhysicalUnit object to the identity mapping.

Clear()

Resets the PhysicalUnit object to identity mapping.

bool IsPhysical(string)

Tests whether a string is valid as a physical value. This is the case if the string represents

  • a plain number,
  • a plain number followed with an optional magnitude prefix, and the physical unit's symbol, without separating white space, such as "10.3ms",
  • an arithmetic expression involving numbers and arithmetic operators, optionally followed with a unit string, such as "(5/4)muV".

number PhysicalToRaw(string)

Transforms a physical value into a raw number as defined by the object's offset, gain, and symbol properties.

string RawToPhysical(number)

Transforms a raw number into a physical value as defined by the object's offset, gain, and symbol properties.

WriteToStream(ostream), ReadFromStream(istream)

Writes/reads offset, gain, and symbol properties into/from the specified std::iostream objects, enclosed into braces, and separated with space characters.

Properties

number Offset (rw), Gain (rw)

Offset and gain value defining the linear relation between raw and physical values. Consistently with the definition of the SourceChOffset and SourceChGain parameters, the relation between raw and physical value is

PhysicalValue = ( RawValue - Offset ) * Gain

string Symbol (rw)

The symbol of the physical unit, such as "s" for seconds, "V" for Volts, etc., without magnitude prefix. For signal visualizations, units are displayed in the visualization window.

number RawMin, RawMax (rw)

Minimum and maximum of an expected range of values. For signals, this is used to adapt ranges in visualization windows, with the ValueUnit's range determining signal scaling, and the ElementUnit's range determining the number of elements displayed in the visualization window.

Magnitude Prefixes

The PhysicalUnit class recognizes the following magnitude prefixes:

Recognized Prefix Name Value
p pico 1e-12
n nano 1e-9
u, mu micro 1e-6
m milli 1e-3
k kilo 1e3
M mega 1e6
G giga 1e9
T tera 1e12

See also

Programming Reference:Signals, Programming Reference:GenericVisualization Class, Programming Reference:LabelIndex Class