Skip to content

caisingbo/transfer_function

 
 

Repository files navigation

UnitTests Build Status codecov CodeFactor

C++ GitHub Actions TravisCI

Transfer Function Library


Overview


This is C++ library which provides set of opertions on transfer functions. Those are operations like:

  • calculate transfer functions of series/parrallel/feedback connection,
  • discretize transfer function,
  • analyse stability,
  • calculate step/impulse response,
  • calculate Bode/Nyquist plot,
  • simulation of discrete transfer function.

Development enironment

  • Programming language:
    • C++20 standard - g++10.3 or higher
  • Build system:
    • CMake 3.12 or higher
  • Static code analysis:
    • cppcheck 1.90 or higher
    • pygments
  • Test coverage:
    • gcov
    • lcov
  • Coding style check
    • cpplint 1.5.5 or higher

Usage


Create Transfer Function

// Prepare num and den of TF, where tf_core::TransferFunction::CoefficientsVector = std::vector<float>
tf_core::TransferFunction::CoefficientsVector num = {1.0f};
tf_core::TransferFunction::CoefficientsVector den = {1.0f, 2.0f};

auto tf = tf_core::TransferFunction(num, den);

Connect Transfer Functions

  • Parallel

parallel

// Prepare TF
auto G = tf_core::TransferFunction(num_g, den_g);
auto H = tf_core::TransferFunction(num_h, den_h);

auto parallel_connection = G + H;
//Or
auto parallel_connection = G.Parallel(H);
  • Serial

serial

// Prepare TF
auto G = tf_core::TransferFunction(num_g, den_g);
auto H = tf_core::TransferFunction(num_h, den_h);

auto serial_connection = G * H;
//Or
auto serial_connection = G.Serial(H);
  • Feedback

feedback

// Prepare TF
auto G = tf_core::TransferFunction(num_g, den_g);
auto H = tf_core::TransferFunction(num_h, den_h);

auto feedback_connection = G.Feedback(H);
// Or positive feedback
auto feedback_connection = G.Feedback(H, true);

Discretize

//Define TF
auto G = tf_core::TransferFunction(num_g, den_g);

// Define discretization time and method
float sampling_time = 0.01f;
auto discretization_method = tf_core::DiscretizationMethod::Tustin;

// Discretize
auto discrete_G = G.Discretize(sampling_time, discretization_method);

Simulate

//Define TF
auto G = tf_core::TransferFunction(num_g, den_g);

// Define signal, where using Signal = std::vector<float>;
Signal input_signal = {...};

// Simulate
auto output_signal = G.Simulate(input_signal);

About

Transfer function C++ library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 86.0%
  • CMake 14.0%