我有一個簡單的一階傳輸,如「3/s + 3」或「tf(3,[1 3])」函數,我想用c代碼實現。我因爲最後一次迭代被稱爲與增量時間C函數:將一階傳輸函數轉換爲c代碼
double output(double input, double t); //usually, t is around 0.01 second
如何實現在C傳遞函數3次/ s + 3?
我有一個簡單的一階傳輸,如「3/s + 3」或「tf(3,[1 3])」函數,我想用c代碼實現。我因爲最後一次迭代被稱爲與增量時間C函數:將一階傳輸函數轉換爲c代碼
double output(double input, double t); //usually, t is around 0.01 second
如何實現在C傳遞函數3次/ s + 3?
這不僅僅是直接執行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;
}
爲什麼你需要通過z域?您可以簡單地獲得連續時間等價物的符號表示,然後在需要的任何採樣率下對其進行評估。 – 2013-03-12 01:10:58
由於您在給定採樣率下的連續時間等效採樣等效於z變換,所以爲什麼不直接去那裏而不是引入中間步驟。 – 2013-03-12 01:34:12
僅僅因爲使用簡單的身份表比通過z變換更簡單! – 2013-03-12 01:35:56
這還不清楚。拉普拉斯域是「5/s + 3」嗎?你在問如何以編程方式執行逆拉普拉斯變換? – 2013-03-12 00:46:07
我想它是在拉普拉斯域。順便說一句,那應該是'3 /(s + 3)',不是嗎? – 2013-03-12 00:47:16
我編輯了這個問題。是的,它是3 /(s + 3),它在拉普拉斯域。 – gregoiregentil 2013-03-12 00:51:34