替代具有不同采样范围的采样函数
alternative to sample function with varying sampling range
是否有 Openmodelica 中的 示例函数 的替代方法,它接受不属于 type parameter
的参数?也就是说,备选方案应该允许在模拟期间对可变范围的值进行采样。
最终目标是创建一个 class,我可以用它在模拟期间测量真实信号的 RMS 值。 RMS 值用作控制变量。真实信号的频率不断变化,因此为了获得更好的测量结果,我希望能够在模拟过程中连续改变采样范围,或者在某些 sections/periods 振荡中离散地改变采样范围。
是否也可以有一个"running RMS"的函数,让输出是连续的?
简而言之,我想计算可变采样范围内的 RMS 值,并且样本每次迭代应该只有一个新项或值,而不是一组全新的值。
一些可能的解决方案(您可能应该检查我的数学并将它们用作灵感;还检查标准库中的 RootMeanSquare 块,出于某种原因对 Mean 块进行采样):
运行 从时间开始的 RMS(无频率)。
model RMS
Real signal = sin(time);
Real rms = if time < 1e-10 then signal else sqrt(i_sq / time /* Assume start-time is 0; can also integrate the denominator using der(denom)=1 for a portable solution. Remember to guard the first period of time against division by zero */);
Real i_sq(start=0, fixed=true) "Integrated square of the signal";
equation
der(i_sq) = signal^2;
end RMS;
固定window,f:
model RMS
constant Real f = 2*2*asin(1.0);
Real signal = sin(time);
Real rms = if time < f then (if time < 1e-10 then signal else sqrt(i_sq / time)) else sqrt(i_sq_f / f);
Real i_sq(start=0, fixed=true);
Real i_sq_f = i_sq - delay(i_sq, f);
equation
der(i_sq) = signal^2;
end RMS;
有一个变量window,f(受限于f_max):
model RMS
constant Real f_max = 2*2*asin(1.0);
constant Real f = 1+abs(2*asin(time));
Real signal = sin(time);
Real rms = if time < f then (if time < 1e-10 then signal else sqrt(i_sq / time)) else sqrt(i_sq_f / f);
Real i_sq(start=0, fixed=true);
Real i_sq_f = i_sq - delay(i_sq, f, f_max);
equation
der(i_sq) = signal^2;
end RMS;
同步 Modelica 采样的可变时间:https://trac.modelica.org/Modelica/ticket/2022
旧版 Modelica 采样的可变时间:
when time>=nextEvent then
doSampleStuff(...);
nextEvent = calculateNextSampleTime(...);
end when;
是否有 Openmodelica 中的 示例函数 的替代方法,它接受不属于 type parameter
的参数?也就是说,备选方案应该允许在模拟期间对可变范围的值进行采样。
最终目标是创建一个 class,我可以用它在模拟期间测量真实信号的 RMS 值。 RMS 值用作控制变量。真实信号的频率不断变化,因此为了获得更好的测量结果,我希望能够在模拟过程中连续改变采样范围,或者在某些 sections/periods 振荡中离散地改变采样范围。
是否也可以有一个"running RMS"的函数,让输出是连续的?
简而言之,我想计算可变采样范围内的 RMS 值,并且样本每次迭代应该只有一个新项或值,而不是一组全新的值。
一些可能的解决方案(您可能应该检查我的数学并将它们用作灵感;还检查标准库中的 RootMeanSquare 块,出于某种原因对 Mean 块进行采样):
运行 从时间开始的 RMS(无频率)。
model RMS
Real signal = sin(time);
Real rms = if time < 1e-10 then signal else sqrt(i_sq / time /* Assume start-time is 0; can also integrate the denominator using der(denom)=1 for a portable solution. Remember to guard the first period of time against division by zero */);
Real i_sq(start=0, fixed=true) "Integrated square of the signal";
equation
der(i_sq) = signal^2;
end RMS;
固定window,f:
model RMS
constant Real f = 2*2*asin(1.0);
Real signal = sin(time);
Real rms = if time < f then (if time < 1e-10 then signal else sqrt(i_sq / time)) else sqrt(i_sq_f / f);
Real i_sq(start=0, fixed=true);
Real i_sq_f = i_sq - delay(i_sq, f);
equation
der(i_sq) = signal^2;
end RMS;
有一个变量window,f(受限于f_max):
model RMS
constant Real f_max = 2*2*asin(1.0);
constant Real f = 1+abs(2*asin(time));
Real signal = sin(time);
Real rms = if time < f then (if time < 1e-10 then signal else sqrt(i_sq / time)) else sqrt(i_sq_f / f);
Real i_sq(start=0, fixed=true);
Real i_sq_f = i_sq - delay(i_sq, f, f_max);
equation
der(i_sq) = signal^2;
end RMS;
同步 Modelica 采样的可变时间:https://trac.modelica.org/Modelica/ticket/2022
旧版 Modelica 采样的可变时间:
when time>=nextEvent then
doSampleStuff(...);
nextEvent = calculateNextSampleTime(...);
end when;