Controlpp
Loading...
Searching...
No Matches
conversion.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <numbers>
4#include <cmath>
5#include <Eigen/Dense>
6
7namespace controlpp{
8
15 template<class T>
16 T to_hz(const T& radps){
17 constexpr T factor = std::numbers::inv_pi_v<T> / 2;
18 return radps * factor;
19 }
20
21 template<class T, int N>
22 Eigen::Vector<T, N> to_hz(const Eigen::Vector<T, N>& radps){
23 constexpr T factor = std::numbers::inv_pi_v<T> / 2;
24 return radps * factor;
25 }
26
33 template<class T>
34 T to_radps(const T& hz){
35 constexpr T factor = 2 * std::numbers::pi_v<T>;
36 return hz * factor;
37 }
38
39 template<class T, int N>
40 Eigen::Vector<T, N> to_radps(const Eigen::Vector<T, N>& hz){
41 constexpr T factor = 2 * std::numbers::pi_v<T>;
42 return hz * factor;
43 }
44
45 template<class T>
46 T to_deg(const T& rad){
47 constexpr T factor = static_cast<T>(180) / std::numbers::pi_v<T>;
48 return rad * factor;
49 }
50
51 template<class T, int N>
52 Eigen::Vector<T, N> to_deg(const Eigen::Vector<T, N>& rad){
53 constexpr T factor = static_cast<T>(180) / std::numbers::pi_v<T>;
54 return rad * factor;
55 }
56
57 template<class T>
58 T to_rad(const T& deg){
59 constexpr T factor = std::numbers::pi_v<T> / static_cast<T>(180);
60 return deg * factor;
61 }
62
63 template<class T, int N>
64 Eigen::Vector<T, N> to_rad(const Eigen::Vector<T, N>& deg){
65 constexpr T factor = std::numbers::pi_v<T> / static_cast<T>(180);
66 return deg * factor;
67 }
68
69 template<class T>
70 T to_dB(const T& value){
71 return 20 * std::log10(value);
72 }
73
74 template<class T>
75 T from_dB(const T& value){
76 return std::pow(static_cast<T>(10), value / static_cast<T>(20));
77 }
78
114 template<class T>
115 T prewarp_tustin(const T& omega, const T& Ts){
116 const T result = (static_cast<T>(2) / Ts) * std::tan(omega * Ts / static_cast<T>(2));
117 return result;
118 }
119
128 template<class T, int N>
129 Eigen::Vector<T, N> prewarp_tustin(const Eigen::Vector<T, N>& omegas, const T& Ts){
130 const Eigen::Vector<T, N> result = ((static_cast<T>(2) / Ts) * (omegas.array() * Ts / static_cast<T>(2)).tan()).matrix();
131 return result;
132 }
133
156 template<class T>
157 T unwarp_tustin(const T& omega, const T& Ts){
158 const T result = (static_cast<T>(2) / Ts) * std::atan(omega * Ts / static_cast<T>(2));
159 return result;
160 }
161
170 template<class T, int N>
171 Eigen::Vector<T, N> unwarp_tustin(const Eigen::Vector<T, N>& omegas, const T& Ts){
172 const Eigen::Vector<T, N> result = ((static_cast<T>(2) / Ts) * (omegas.array() * Ts / static_cast<T>(2)).atan()).matrix();
173 return result;
174 }
175
176}
Bode< T > prewarp_tustin(const Bode< T > &bode, const T &Ts)
Prewarps the frequency axis of a bode plot for tustin discretisation.
Definition Bode.hpp:427
Bode< T > unwarp_tustin(const Bode< T > &bode, const T &Ts)
Unwarps the frequency axis of a bode plot for tustin discretisation.
Definition Bode.hpp:445
The main namespace for the Control++ library.
Definition Bode.cpp:3
T to_hz(const T &radps)
Converts a number from radiants per second to herz.
Definition conversion.hpp:16
T to_radps(const T &hz)
Converts a number from herz to radiants per second.
Definition conversion.hpp:34
T to_rad(const T &deg)
Definition conversion.hpp:58
T to_dB(const T &value)
Definition conversion.hpp:70
T to_deg(const T &rad)
Definition conversion.hpp:46
T from_dB(const T &value)
Definition conversion.hpp:75