OpenSim Moco  0.4.0
Functions
Numeric and data utilities

Interpolate or resample data, and read/write tables. More...

Functions

OSIMMOCO_API SimTK::Vector OpenSim::createVectorLinspace (int length, double start, double end)
 Create a SimTK::Vector with the provided length whose elements are linearly spaced between start and end.
 
OSIMMOCO_API SimTK::Vector OpenSim::createVector (std::initializer_list< SimTK::Real > elements)
 Create a SimTK::Vector using modern C++ syntax.
 
OSIMMOCO_API SimTK::Vector OpenSim::interpolate (const SimTK::Vector &x, const SimTK::Vector &y, const SimTK::Vector &newX, const bool ignoreNaNs=false)
 Linearly interpolate y(x) at new values of x. More...
 
template<typename FunctionType >
std::unique_ptr< FunctionSet > OpenSim::createFunctionSet (const TimeSeriesTable &table)
 
template<>
std::unique_ptr< FunctionSet > OpenSim::createFunctionSet< GCVSpline > (const TimeSeriesTable &table)
 
template<typename TimeVector , typename FunctionType = GCVSpline>
TimeSeriesTable OpenSim::resample (const TimeSeriesTable &in, const TimeVector &newTime)
 Resample (interpolate) the table at the provided times. More...
 
OSIMMOCO_API Storage OpenSim::convertTableToStorage (const TimeSeriesTable &)
 Create a Storage from a TimeSeriesTable. More...
 
OSIMMOCO_API TimeSeriesTable OpenSim::filterLowpass (const TimeSeriesTable &table, double cutoffFreq, bool padData=false)
 Lowpass filter the data in a TimeSeriesTable at a provided cutoff frequency. More...
 
OSIMMOCO_API void OpenSim::writeTableToFile (const TimeSeriesTable &, const std::string &)
 Write a single TimeSeriesTable to a file, using the FileAdapter associated with the provided file extension.
 

Detailed Description

Interpolate or resample data, and read/write tables.

To use these utilities in MATLAB, prepend the function names with "opensimMoco."; for example, opensimMoco.interpolate() or org.opensim.modeling.opensimMoco.interpolate(). In Python, use opensim.interpolate().

Function Documentation

◆ convertTableToStorage()

OSIMMOCO_API Storage OpenSim::convertTableToStorage ( const TimeSeriesTable &  )

Create a Storage from a TimeSeriesTable.

Metadata from the TimeSeriesTable is not copied to the Storage. You should use TimeSeriesTable if possible, as support for Storage may be reduced in future versions of OpenSim. However, Storage supports some operations not supported by TimeSeriesTable (e.g., filtering, resampling).

◆ filterLowpass()

OSIMMOCO_API TimeSeriesTable OpenSim::filterLowpass ( const TimeSeriesTable &  table,
double  cutoffFreq,
bool  padData = false 
)

Lowpass filter the data in a TimeSeriesTable at a provided cutoff frequency.

The table is converted to a Storage object to use the lowpassIIR() method to filter, and then converted back to TimeSeriesTable.

◆ interpolate()

OSIMMOCO_API SimTK::Vector OpenSim::interpolate ( const SimTK::Vector &  x,
const SimTK::Vector &  y,
const SimTK::Vector &  newX,
const bool  ignoreNaNs = false 
)

Linearly interpolate y(x) at new values of x.

The optional 'ignoreNaNs' argument will ignore any NaN values contained in the input vectors and create the interpolant from the non-NaN values only. Note that this option does not necessarily prevent NaN values from being returned in 'newX', which will have NaN for any values of newX outside of the range of x.

Exceptions
Exceptionif x and y are different sizes, or x or y is empty.

◆ resample()

template<typename TimeVector , typename FunctionType = GCVSpline>
TimeSeriesTable OpenSim::resample ( const TimeSeriesTable &  in,
const TimeVector &  newTime 
)

Resample (interpolate) the table at the provided times.

In general, a 5th-order GCVSpline is used as the interpolant; a lower order is used if the table has too few points for a 5th-order spline. Alternatively, you can provide a different function type as a template argument (e.g., PiecewiseLinearFunction).

Exceptions
Exceptionif new times are not within existing initial and final times, if the new times are decreasing, or if getNumTimes() < 2.