Modelica 具有不同采样范围的采样函数的替代方案

Modelica 具有不同采样范围的采样函数的替代方案,modelica,dymola,openmodelica,Modelica,Dymola,Openmodelica,Openmodelica中的sample函数是否有替代方法,该函数接受的参数不是类型的parameter?也就是说,替代方案应允许在模拟期间对可变范围的值进行采样 最终目标是创建一个类,在模拟过程中,我可以使用该类测量真实信号的RMS值。RMS值用作控制变量。真实信号的频率不断变化,因此为了获得更好的测量结果,我希望能够在模拟过程中连续地改变采样范围,或者在振荡的某些部分/周期中离散地改变采样范围 是否也可以具有“运行RMS”功能,以便输出连续 简言之,我想计算可变采样范围内的RMS值,样本每次

Openmodelica中的sample函数是否有替代方法,该函数接受的参数不是
类型的parameter
?也就是说,替代方案应允许在模拟期间对可变范围的值进行采样

最终目标是创建一个类,在模拟过程中,我可以使用该类测量真实信号的RMS值。RMS值用作控制变量。真实信号的频率不断变化,因此为了获得更好的测量结果,我希望能够在模拟过程中连续地改变采样范围,或者在振荡的某些部分/周期中离散地改变采样范围

是否也可以具有“运行RMS”功能,以便输出连续

简言之,我想计算可变采样范围内的RMS值,样本每次迭代应该只有一个新的项或值,而不是一组全新的值

一些可能的解决方案(您可能应该检查我的数学,并将其用于灵感;还可以检查标准库中的RootMeanSquare块,出于某种原因,它对平均块进行采样):

从时间开始运行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;
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;
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;
when time>=nextEvent then
  doSampleStuff(...);
  nextEvent = calculateNextSampleTime(...);
end when;