具有不同采样范围的采样函数的替代方案 [英] alternative to sample function with varying sampling range

查看:48
本文介绍了具有不同采样范围的采样函数的替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there an alternative to the sample function in Openmodelica, which accepts arguments which are not of type parameter? That is, the alternative should permit the sampling of a variable range of values during a simulation.

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

The end goal is to create a class with which I can measure the RMS value of a real signal during a simulation. The RMS value is used as a control variable. The real signal has a continuously changing frequency so in order to have better measurements, I want to either be able to varry the sampling range continuously during simulation or discretely in some sections/periods of the oscillation.

是否也可以有一个运行RMS"功能,以便输出是连续的?

Is it also possible to have a "running RMS" function so that the output is continuous?

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

In short, I would like to calculate the RMS value over a variable sampling range and the sample should only have one new term or value per iteration and not a completely new set of values.

推荐答案

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

Some possible solutions (you probably should check my math and just use them for inspiration; also check the RootMeanSquare block in the standard library which for some reason samples the Mean block):

从时间开始运行 RMS(无频率).

Running RMS from beginning of time (no frequency).

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 限制):

With a variable window, f (limited by 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/门票/2022

Variable time for sampling in synchronous Modelica: https://trac.modelica.org/Modelica/ticket/2022

旧版 Modelica 中采样的可变时间:

Variable time for sampling in older Modelica:

when time>=nextEvent then
  doSampleStuff(...);
  nextEvent = calculateNextSampleTime(...);
end when;

这篇关于具有不同采样范围的采样函数的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆