2
計算Modelica中連續信號的平均值(平均值)和標準差(StdDev)的最佳方法是什麼?均值和StdDev應該計算固定的時間T;即從t-T到t。計算Modelica中的平均值和標準偏差
計算Modelica中連續信號的平均值(平均值)和標準差(StdDev)的最佳方法是什麼?均值和StdDev應該計算固定的時間T;即從t-T到t。計算Modelica中的平均值和標準偏差
下面是該問題的分立解決方案。它在Modelica中被編碼爲一個塊,具有1個連續輸入和2個連續輸出信號。使用Modelica內置函數樣本完成離散化:
block MeanStdDevDiscr
"Determines the mean value and standard deviation of a signal for a fixed time interval T."
extends Modelica.Blocks.Interfaces.BlockIcon;
import SI = Modelica.SIunits;
parameter SI.Time T = 0.1
"Time interval used for calculating mean value and standard deviation";
parameter Integer n = 10 "number of increments in T";
Modelica.Blocks.Interfaces.RealInput u "signal input"
annotation (Placement(transformation(extent={{-140,-20},{-100,20}})));
Modelica.Blocks.Interfaces.RealOutput[2] y
"y[1] = average value; y[2] = standard deviation"
annotation (Placement(transformation(extent={{100,-10},{120,10}})));
protected
parameter SI.Time dt = T/n "Precision of monitor";
Real[n] uArray;
initial equation
uArray = ones(n)*u;
equation
when sample(0, dt) then
uArray[1] = u;
for j in 2:n loop
uArray[j] = pre(uArray[j-1]);
end for;
end when;
y[1] = sum(uArray)/n; // mean value
y[2] = sqrt(sum((uArray .- y[1]).^2)/n); // standard deviation
annotation (Diagram(graphics));
end MeanStdDevDiscr;
是否有模擬連續解決方案? – AdrijanR