0

我有一个简单的一阶传输,例如“3/s+3”或“tf(3,[1 3])”函数,我想用 c 代码实现。我有一个 C 函数,它使用自上次迭代以来的增量时间调用:

double output(double input, double t); //usually, t is around 0.01 second

如何在 C 中实现传递函数 3/s+3?

4

1 回答 1

2

这不仅仅是直接实现 3/(s+3) 的问题。您需要使用适当的技术(前向欧拉、后向欧拉、tustin、零阶保持)将其离散到 z 域,然后实现滤波器的离散版本。

以下是 Tustin 转换的简单版本。正如所写,需要初始化状态并将其存储在此函数外部的某个位置。

double firstOrderLag(double input, double coeff, double dT, double *state){
// Function to implement the discretization of a continuous time first
// order lag sys = coeff/(s+coeff) using the Tustin (Bilinear) transformation.

    double num = (1/(1+2/coeff/dT)); // numerator
    double den = (1-2/coeff/dT)*num; // denominator
    double temp;
    double output;

    temp = input - den*(*state);
    output = num*(temp + (*state));
    *state = temp;

    return output;
}
于 2013-03-12T01:09:45.867 回答