-
Notifications
You must be signed in to change notification settings - Fork 194
Non-sampled and derivative-free detection of signal extrema by means of FMI #4381
beutlich
started this conversation in
Show and tell
This is to demonstrate both a non-sampled and derivative-free detection of signal extrema - aka the online-minimum.
Let's start from the two corresponding PRs:
- Add a block (based on time events) to calculate the extrema of a signal #3762 introduced a sample-based detection of signal extrema - leading to many time events if sample time is chosen small for high accuray.
- Implement continuous version of SignalExtrema #4015 introduced a derivative-based detection of signal extrema - where the derivative is approximated by introducing a time constant.
Based on LastLib and its demonstrator MinimumTest (available in the same repository) an FMI-based approach can be used to detect the signal extrema. This approach neither results in time events nor requires approximated time derivatives, but solely depends on the solver step size. The adapted example model Modelica.Blocks.Examples.DemonstrateSignalExtrema now looks like:
model DemonstrateSignalExtrema "FMI-based detection of signal extrema" extends Modelica.Icons.Example; Sources.Sine amplitude( amplitude=2, f=63, offset=3) annotation (Placement(transformation(extent={{-80,10},{-60,30}}))); Sources.Cosine frequency( amplitude=45, f=77, offset=55) annotation (Placement(transformation(extent={{-80,-30},{-60,-10}}))); Modelica.Blocks.Sources.SineVariableFrequencyAndAmplitude sine( useConstantFrequency=false, phi(fixed=true)) annotation (Placement(transformation(extent={{-40,-10},{-20,10}}))); MinimumTest.Minimum min( redeclare model Last = LastLib.Last_dymola_windows) annotation (Placement(transformation(extent={{60,10},{80,30}}))); Math.Gain negated(k=-1) annotation (Placement(transformation(extent={{0,-30},{20,-10}}))); Math.Gain max(k=-1) annotation (Placement(transformation(extent={{60,-30},{80,-10}}))); MinimumTest.Minimum minNegated( redeclare model Last = LastLib.Last_dymola_windows) annotation (Placement(transformation(extent={{30,-30},{50,-10}}))); equation connect(amplitude.y, sine.amplitude) annotation (Line(points={{-59,20},{-50,20},{-50,6},{-42,6}}, color={0,0,127})); connect(frequency.y, sine.f) annotation (Line(points={{-59,-20},{-50,-20},{-50,-6},{-42,-6}}, color={0,0,127})); connect(negated.u, sine.y) annotation (Line(points={{-2,-20},{-12,-20},{-12,0},{-19,0}}, color={0,0,127})); connect(min.u, sine.y) annotation (Line(points={{58,20},{-12,20},{-12,0},{-19,0}}, color={0,0,127})); connect(negated.y, minNegated.u) annotation (Line(points={{21,-20},{28,-20}}, color={0,0,127})); connect(max.u, minNegated.y) annotation (Line(points={{58,-20},{51,-20}}, color={0,0,127})); annotation ( uses(Modelica(version="4.0.0"), LastLib(version="2.0.0"), MinimumTest(version="2.0.0")), experiment(StopTime=1.5, Interval=1e-05, Tolerance=1e-06), Documentation(info="<html> <p> This example uses a sinusoidal signal with amplitude varying sinusoidally in the range of [1,5] with a frequency of 63 Hz, and frequency varying according to a cosine function in the range of [10, 100] Hz with a frequency of 77 Hz. </p> </html>")); end DemonstrateSignalExtrema;
There is one drawback, too: LastLib is not tool-agnostic and requires a tool-specific redeclaration of LastLib.Last for the imported FMU. In the example above, it is redeclared for usage on Dymola for Windows.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment