Controlpp
Loading...
Searching...
No Matches
Bode Utilities

Utilities to work with Bode data. More...

Functions

template<class T >
Bode< T > controlpp::prewarp_tustin (const Bode< T > &bode, const T &Ts)
 Prewarps the frequency axis of a bode plot for tustin discretisation.
 
template<class T >
Bode< T > controlpp::unwarp_tustin (const Bode< T > &bode, const T &Ts)
 Unwarps the frequency axis of a bode plot for tustin discretisation.
 
template<class T >
const Eigen::Vector< T, Eigen::Dynamic > & controlpp::frequencies (const Bode< T > &bode)
 Converts and returns the frequency vector in rad.
 
template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::frequencies_hz (const Bode< T > &bode)
 Converts and returns the frequency vector in Hz.
 
template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::real (const Bode< T > &bode)
 Converts and returns the frequency vector in rad/s.
 
template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::imag (const Bode< T > &bode)
 Converts and returns the frequency vector in rad/s.
 
template<class T >
const Eigen::Vector< T, Eigen::Dynamic > & controlpp::values (const Bode< T > &bode)
 Returns the complex values of the bode data.
 
template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::magnitudes (const Bode< T > &bode)
 Creates a vector containing the absolute magnitudes.
 
template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::magnitudes_dB (const Bode< T > &bode)
 Creates a vector of magnitudes in dB.
 
template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::phases (const Bode< T > &bode)
 Creates a vector of phases in rad.
 
template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::phases_deg (const Bode< T > &bode)
 Creates a vector of phases in degree.
 
template<class T >
TimeSeries< T > controlpp::impulse (const Bode< T > &bode, const T &time_step, const T &simulation_time)
 Calculates the impulse-response of frequency data.
 
template<class T >
TimeSeries< T > controlpp::impulse (const Bode< T > &bode)
 Calculates the time-series of a frequency response.
 
template<class T >
void controlpp::integrate (TimeSeries< T > &out, const TimeSeries< T > &in, const T &v0=T(0))
 Integrates the time series and writes it to out.
 
template<class T >
TimeSeries< T > controlpp::step (const Bode< T > &bode)
 Calculates the step response time-value pairs from frequency-value data.
 
template<class T >
TimeSeries< T > controlpp::step (const Bode< T > &bode, const T &time_step, const T &simulation_time)
 Calculates the step response time-value pairs from frequency-value data.
 
template<class T >
Bode< T > controlpp::operator+ (const Bode< T > &l, const Bode< T > &r)
 Adds two bode plots together.
 
template<class T , std::convertible_to< T > T2>
Bode< T > controlpp::operator+ (const Bode< T > &l, const T2 &r)
 Adds a bode plot and a scalar value together.
 
template<class T , std::convertible_to< T > T2>
Bode< T > controlpp::operator+ (const T2 &l, const Bode< T > &r)
 Adds a scalar value and a bode plot together.
 
template<class T >
Bode< T > controlpp::operator+ (const Bode< T > &b)
 Negates the bode plot values.
 

Detailed Description

Utilities to work with Bode data.

Function Documentation

◆ frequencies()

template<class T >
const Eigen::Vector< T, Eigen::Dynamic > & controlpp::frequencies ( const Bode< T > &  bode)

Converts and returns the frequency vector in rad.

Note that this will use a const reference from the bode data and will not allocate a new vector.

Parameters
bodeThe bode data to get the frequencies from
Returns
const-reference to an eigen vector
See also
frequencies_hz(const Bode<T>& bode)

◆ frequencies_hz()

template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::frequencies_hz ( const Bode< T > &  bode)

Converts and returns the frequency vector in Hz.

Note that this will allocate a new vector.

Parameters
bodeThe bode data to get the frequencies from
Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Returns
const-reference to an eigen vector

◆ imag()

template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::imag ( const Bode< T > &  bode)

Converts and returns the frequency vector in rad/s.

Note that this will allocate a new vector.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
bodeThe bode data
Returns
A vector containing the imaginary parts of the complex magnitudes

◆ impulse() [1/2]

template<class T >
TimeSeries< T > controlpp::impulse ( const Bode< T > &  bode)

Calculates the time-series of a frequency response.

Allows for arbitrary number, spacing and density-changes of samples.

Automatically estimates time-steps and the simulation time from the bode data.

Tip: For step responses do not do:

stp = impulse(bode * 1/s);
TimeSeries< T > impulse(const Bode< T > &bode, const T &time_step, const T &simulation_time)
Calculates the impulse-response of frequency data.
Definition Bode.hpp:614
Bode< T > bode(const ContinuousTransferFunction< T, NumOrder, DenOrder > &tf, const Eigen::Vector< T, Eigen::Dynamic > &freqs)
Calculates the bode response for a pre defined frequency (rad/s) vector.
Definition Bode.hpp:1071

instead use the step function

stp = step(bode * 1/s);
TimeSeries< T > step(const DiscreteStateSpace< T, NStates, 1, 1 > &dss, double Ts, double simulation_time)
calculates the step response of a system
Definition analysis.hpp:34
Parameters
bodeA frequency response or bode plot/measurement
Returns
a time series
See also
template<class T> TimeSeries<T> step(const Bode<T>& bode)

◆ impulse() [2/2]

template<class T >
TimeSeries< T > controlpp::impulse ( const Bode< T > &  bode,
const T &  time_step,
const T &  simulation_time 
)

Calculates the impulse-response of frequency data.

Assumes the frequency-response is only the one sided analytical form containing only positive frequencies. Thus it extends the frequency response to negative frequencies by mirroring it around the y axis in its conjugate complex form.

Uses linear piecewise first order integration in between data points

If the bode does not include a DC frequency sample (at 0 Hz) one will be added with the value of the smallest frequency in the data

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
bodeThe frequency response data (assumed to only contain the one sided positive frequencies)
time_stepThe timestep for the integration
simulation_timeThe simulation time over which to simulate. This is the minimal simulation time and may be overstepped by one timestep.
Returns
A timeseries containing the impulse frequency response of the bode data

◆ integrate()

template<class T >
void controlpp::integrate ( TimeSeries< T > &  out,
const TimeSeries< T > &  in,
const T &  v0 = T(0) 
)

Integrates the time series and writes it to out.

Resizes out accordingly

out and in may be the same time-series object

Template Parameters
TThe value type
Parameters
outThe output time-series where the result will be written to
inThe input time-series that will be integrated over
v0The start of the integration. Integration constant C in other nomiclatures.

◆ magnitudes()

template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::magnitudes ( const Bode< T > &  bode)

Creates a vector containing the absolute magnitudes.

Calculates the absolute magnitudes from the complex magnitudes.

Will allocate a new vector and return it.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
bodeThe bode data
Returns
A vector containing the absolute magnitudes

◆ magnitudes_dB()

template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::magnitudes_dB ( const Bode< T > &  bode)

Creates a vector of magnitudes in dB.

Calculates the magnitudes from the complex magnitudes.

Will allocate a new vector and return it.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
bodeThe bode data
Returns
A vector containing the magnitudes in dB

◆ operator+() [1/4]

template<class T >
Bode< T > controlpp::operator+ ( const Bode< T > &  b)

Negates the bode plot values.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
bBode data to negate
Returns
Bode data containing the negated values of the bode plot

◆ operator+() [2/4]

template<class T >
Bode< T > controlpp::operator+ ( const Bode< T > &  l,
const Bode< T > &  r 
)

Adds two bode plots together.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
lBode data on the left side of the addition operator
rBode data on the right side of the addition operator
Returns
Bode data containing the sum of the two bode plots

◆ operator+() [3/4]

template<class T , std::convertible_to< T > T2>
Bode< T > controlpp::operator+ ( const Bode< T > &  l,
const T2 &  r 
)

Adds a bode plot and a scalar value together.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
T2The value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
lBode data on the left side of the addition operator
rA scalar value on the right side of the addition operator
Returns
Bode data containing the sum of the bode plot and the scalar value

◆ operator+() [4/4]

template<class T , std::convertible_to< T > T2>
Bode< T > controlpp::operator+ ( const T2 &  l,
const Bode< T > &  r 
)

Adds a scalar value and a bode plot together.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
T2The value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
lA scalar value on the left side of the addition operator
rBode data on the right side of the addition operator
Returns
Bode data containing the sum of the scalar value and the bode plot

◆ phases()

template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::phases ( const Bode< T > &  bode)

Creates a vector of phases in rad.

Calculates the phases from the complex magnitudes

Will allocate a new vector.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
bodeThe bode data
Returns
A vector containing the phases in rad

◆ phases_deg()

template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::phases_deg ( const Bode< T > &  bode)

Creates a vector of phases in degree.

Calculates the phases from the complex magnitudes

Will allocate a new vector.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
bodeThe bode data
Returns
A vector containing the phases in degree

◆ prewarp_tustin()

template<class T >
Bode< T > controlpp::prewarp_tustin ( const Bode< T > &  bode,
const T &  Ts 
)

Prewarps the frequency axis of a bode plot for tustin discretisation.

Note that this will allocate a new Bode object.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
bodeThe bode data to prewarp
TsThe sample time that also the tustin discretisation is using.
Returns
A bode plot with prewarped frequencies
See also
unwarp_tustin(const Bode<T>& bode, const T& Ts)

◆ real()

template<class T >
Eigen::Vector< T, Eigen::Dynamic > controlpp::real ( const Bode< T > &  bode)

Converts and returns the frequency vector in rad/s.

Note that this will allocate a new vector.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
bodeThe bode data
Returns
A vector containing the real parts of the complex magnitudes

◆ step() [1/2]

template<class T >
TimeSeries< T > controlpp::step ( const Bode< T > &  bode)

Calculates the step response time-value pairs from frequency-value data.

Internally this will calculate the impulse response first and then integrates in the time domain. This way is numerically more stable than integrating in the frequency domain by 1/s multiplication and transforming that.

Automatically estimates the time-step and simulation time from the bode/frequency-response data.

Template Parameters
TThe data type. Typically float or double.
Parameters
bodeThe step response of the system
Returns
A TimeSeries containing time-value pairs

◆ step() [2/2]

template<class T >
TimeSeries< T > controlpp::step ( const Bode< T > &  bode,
const T &  time_step,
const T &  simulation_time 
)

Calculates the step response time-value pairs from frequency-value data.

Template Parameters
TThe data type. Typically float or double.
Parameters
bodeThe step response of the system
time_stepThe time step used for the time series data
simulation_timeThe time until the step response will be calculated (+1 for rounding).
Returns
The TimeSeries step response of the bode data

◆ unwarp_tustin()

template<class T >
Bode< T > controlpp::unwarp_tustin ( const Bode< T > &  bode,
const T &  Ts 
)

Unwarps the frequency axis of a bode plot for tustin discretisation.

Note that this will allocate a new Bode object.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
bodeThe bode data to unwarp
TsThe sample time that also the tustin discretisation is using.
Returns
A bode plot with unwarped frequencies
See also
prewarp_tustin(const Bode<T>& bode, const T& Ts)

◆ values()

template<class T >
const Eigen::Vector< T, Eigen::Dynamic > & controlpp::values ( const Bode< T > &  bode)

Returns the complex values of the bode data.

Will allocate a new vector and return it.

Template Parameters
TThe value type used to represent numbers. Usually float, double or a custom fixpoint type
Parameters
bodeThe bode data
Returns
A vector containing the complex magnitudes