2016-12-14 89 views
2

我想知道在Openmodelica中是否有替代示例函数,该函数接受的参数不是type parameter。也就是说,替代方案应允许在模拟期间对可变范围的数值进行采样。采样函数的替代方案,可变采样范围

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

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

总之,我想计算一个变量采样范围内的RMS值,样本应该只有一个新的术语或每次迭代的值,而不是一组全新的值。

我是新来的modelica平台,并会欢迎所有有用的提示。

谢谢!

+0

我想你可以使用类似:http://doc.modelica.org/om/Modelica.Blocks.Discrete.TriggeredSampler.html 你立足于基于时间的一些表达触发输入。 –

回答

3

一些可能的解决方案(你应该检查我的数学,只使用他们的灵感;同时检查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; 

使用固定窗口中,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; 

使用可变窗口中,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; 
+0

这适合我的需要! – Gladson