Modelica 在Dymola中平滑曲线

Modelica 在Dymola中平滑曲线,modelica,dymola,Modelica,Dymola,在Dymola中,绘制结果后,如何平滑曲线? 我不知道如何在绘图窗口中进行此操作,但平滑曲线可以通过多种方式进行。您必须意识到,您正在使用它操纵实际的模拟结果 我建议您自己使用一个滤波器,在不影响实际模拟的情况下创建一个平滑的信号。我用MSL的Butterworth滤波器制作了一个带有原始信号和滤波信号的小样本模型 我只是稍微复制和修改了一个示例,请忽略大多数内联注释。你必须稍微摆弄一下f_cut,这样它就可以为你的情况切割出正确的高频 model FilterTest "Demonstrate

在Dymola中,绘制结果后,如何平滑曲线?

我不知道如何在绘图窗口中进行此操作,但平滑曲线可以通过多种方式进行。您必须意识到,您正在使用它操纵实际的模拟结果

我建议您自己使用一个滤波器,在不影响实际模拟的情况下创建一个平滑的信号。我用MSL的Butterworth滤波器制作了一个带有原始信号和滤波信号的小样本模型

我只是稍微复制和修改了一个示例,请忽略大多数内联注释。你必须稍微摆弄一下f_cut,这样它就可以为你的情况切割出正确的高频

model FilterTest "Demonstrates the Continuous.Filter block with various options"
  extends Modelica.Icons.Example;

  Real original = add.y;
  Real filtered = Butterworth.y;
  protected
  parameter Integer order=3;
  parameter Modelica.SIunits.Frequency f_cut=2;
  parameter Modelica.Blocks.Types.FilterType filterType=Modelica.Blocks.Types.FilterType.LowPass
    "Type of filter (LowPass/HighPass)";
  parameter Modelica.Blocks.Types.Init init=Modelica.Blocks.Types.Init.SteadyState
    "Type of initialization (no init/steady state/initial state/initial output)";
  parameter Boolean normalized=true;
  Modelica.Blocks.Continuous.Filter Butterworth(

    analogFilter = Modelica.Blocks.Types.AnalogFilter.Butterworth,
    f_cut= 100,
    f_min=1,
    filterType=Modelica.Blocks.Types.FilterType.LowPass, gain = 1,
    init=init,normalized=normalized,
    order=order)
    annotation (Placement(visible = true, transformation(extent = {{38, 18}, {58, 38}}, rotation = 0)));
  Modelica.Blocks.Sources.Sine sineHigh(freqHz = 200)  annotation(
    Placement(visible = true, transformation(origin = {-62, 54}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Sources.Sine sineLow(amplitude = 10, freqHz = 3)  annotation(
    Placement(visible = true, transformation(origin = {-56, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Math.Add add annotation(
    Placement(visible = true, transformation(origin = {-8, 28}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(add.u1, sineHigh.y) annotation(
    Line(points = {{-20, 34}, {-20, 55}, {-51, 55}, {-51, 54}}, color = {0, 0, 127}));
  connect(add.u2, sineLow.y) annotation(
    Line(points = {{-20, 22}, {-33.5, 22}, {-33.5, 2}, {-45, 2}}, color = {0, 0, 127}));
  connect(Butterworth.u, add.y) annotation(
    Line(points = {{36, 28}, {3, 28}}, color = {0, 0, 127}));
  annotation(
    experiment(StopTime = 0.9),
    Documentation(info = "<html>

<p>
This example demonstrates various options of the
<a href=\"modelica://Modelica.Blocks.Continuous.Filter\">Filter</a> block.
A step input starts at 0.1 s with an offset of 0.1, in order to demonstrate
the initialization options. This step input drives 4 filter blocks that
have identical parameters, with the only exception of the used analog filter type
(CriticalDamping, Bessel, Butterworth, Chebyshev of type I). All the main options
can be set via parameters and are then applied to all the 4 filters.
The default setting uses low pass filters of order 3 with a cut-off frequency of
2 Hz resulting in the following outputs:
</p>

<img src=\"modelica://Modelica/Resources/Images/Blocks/Filter1.png\"
   alt=\"Filter1.png\">
</html>"),
    uses(Modelica(version = "3.2.2")));
end FilterTest;
model FilterTest“演示带有各种选项的连续.Filter块”
扩展Modelica.Icons.Example;
真实原始=添加.y;
实际过滤=巴特沃斯.y;
受保护的
参数整数阶=3;
参数Modelica.SIunits.Frequency f_cut=2;
参数Modelica.Blocks.Types.FilterType FilterType=Modelica.Blocks.Types.FilterType.LowPass
“滤波器类型(低通/高通)”;
参数Modelica.Blocks.Types.Init Init=Modelica.Blocks.Types.Init.SteadyState
“初始化类型(无初始/稳态/初始状态/初始输出)”;
参数Boolean normalized=true;
Modelica.Blocks.Continuous.Filter Butterworth(
analogFilter=Modelica.Blocks.Types.analogFilter.Butterworth,
f_截面积=100,
f_min=1,
filterType=Modelica.Blocks.Types.filterType.LowPass,增益=1,
init=init,normalized=normalized,
订单=订单)
注释(位置(可见=真,转换(范围={38,18},{58,38}},旋转=0));
Modelica.Blocks.Sources.Sine Sinehous(频率=200)注释(
位置(可见=真,变换(原点={-62,54},范围={{-10,-10},{10,10},旋转=0));
Modelica.Blocks.Sources.Sine sineLow(振幅=10,频率=3)注释(
位置(可见=真,变换(原点={-56,2},范围={{-10,-10},{10,10},旋转=0));
Modelica.Blocks.Math.Add添加注释(
位置(可见=真,变换(原点={-8,28},范围={{-10,-10},{10,10},旋转=0));
方程式
连接(add.u1,sinehous.y)注释(
线(点={-20,34},{-20,55},{-51,55},{-51,54},颜色={0,0,127});
连接(add.u2,sineLow.y)注释(
线(点={-20,22},{-33.5,22},{-33.5,2},{-45,2},颜色={0,0,127});
connect(Butterworth.u,add.y)注释(
线(点={36,28},{3,28},颜色={0,0,127});
注释(
实验(停止时间=0.9),
文件(信息=”

此示例演示了
块
阶跃输入从0.1s开始,偏移量为0.1,以演示
初始化选项。此步骤输入驱动4个
具有相同的参数,但所用模拟滤波器类型除外
(I型临界阻尼、贝塞尔、巴特沃斯、切比雪夫)。所有主要选项
可通过参数设置,然后应用于所有4个过滤器。
默认设置使用3阶低通滤波器,截止频率为
2 Hz,产生以下输出:

"), 使用(Modelica(version=“3.2.2”)); 末端过滤器试验;
Dymola中的绘图窗口具有一些信号运算符,可用于后期处理。但它们没有平滑功能

如果要在Dymola中执行此操作,最简单的选择是在模拟过程中连续计算平均值,就像kabdelhak建议的那样


另一种方法是在Dymola创建的.mat结果文件上应用Matlab或Python中的信号处理滤波器。

我个人发现用时间常数来表示滤波的“量”比用截止频率来表示更容易。 如果你不介意写几行代码,你可以写一阶滤波器的方程,得到类似于kabdelhak的答案,即

model Preheater_Model_Validation
  Modelica.SIunits.MassFlowRate m_flow_filtered;
  parameter Modelica.SIunits.Time tau=120 "filter time constant" annotation(Evaluate=false);

  ... (other declarations)
initial equation
  der(m_flow_filtered) = 0 "steady-state initialization";
equation
  tau*der(m_flow_filtered) = hex.summary.m_flow_in - m_flow_filtered;
end Preheater_Model_Validation;
代码中的
Evaluate=false
注释意味着您可以在Dymola的“变量浏览器”中调整时间常数,而无需重新翻译代码

致意


Rene Just Nielsen现在还有一个移动平均线信号算子。