<phyphox xmlns="http://phyphox.org/xml" version="1.14" locale="en">
  <title>Distance, velocity, acceleration (LOESS)</title>
  <category>LiDAR</category>
  <description>Test experiment for LiDAR development: distance, velocity and acceleration derived by LOESS.</description>
  <icon>dt</icon>
  <translations>
  </translations>
    <data-containers>
        <container size="0">x</container>
        <container size="0">t</container>

        <container size="1" init="0.02">dt</container>  <!-- Schrittweite für Glättung (kann normalerweise so bleiben) -->
        <container size="1" init="0.2">d</container>    <!-- Breite der Glättung in Sekunden -->

        <container size="0">tout</container>
        <container size="0">xout</container>
        <container size="0">vout</container>
        <container size="0">aout</container>

        <container size="0">toutpreview</container>
        <container size="0">xoutpreview</container>
        <container size="0">voutpreview</container>
        <container size="0">aoutpreview</container>
        <container size="0">aoutpreview2</container>

        <container size="1">newsmoothstart</container>
        <container size="1">newsmoothstop</container>
        <container size="1">tmaxsmooth</container>

        <container size="101">newsmoothti100</container>
        <container size="101">newsmoothti</container>
        <container size="101">newsmoothxi</container>
        <container size="101">newsmoothvi</container>
        <container size="101">newsmoothai</container>

        <container size="101">incompletesmoothti</container>
        <container size="101">incompletesmoothxi</container>
        <container size="101">incompletesmoothvi</container>
        <container size="101">incompletesmoothai</container>

        <container size="1">temp</container>

    </data-containers>
   <input>
    <depth x1="0.4" x2="0.6" y1="0.4" y2="0.6" mode="average">
      <output component="z">x</output>
      <output component="t">t</output>
    </depth>
  </input>
    <analysis>

        <!-- Neue Stützstellen für Glättung suchen -->

        <append>
            <input type="value">0</input>
            <input clear="false">tout</input>
            <output>temp</output>               <!-- Letzter schon berechneter Glättungswert -->
        </append>

        <add>
            <input>temp</input>
            <input clear="false">dt</input>
            <output>newsmoothstart</output>     <!-- Erster zu berechnender Glättungswert -->
        </add>

        <append>
            <input type="value">0</input>
            <input clear="false">t</input>
            <output>temp</output>               <!-- Letzter Rohdatenwert, der schon aufgenommen wurde -->
        </append>

        <subtract>
            <input>temp</input>
            <input clear="false">d</input>
            <output>tmaxsmooth</output>         <!-- Maximale Zeit, bis zu der eine Glättung schon sinnvoll wäre -->
        </subtract>

        <formula formula="[1]+100*[2]">
            <input clear="false">newsmoothstart</input>
            <input clear="false">dt</input>
            <output>newsmoothstop</output>      <!-- Höchster der möglichen neuen Glättungswerte, der aber weit hinter den sinnvollen liegen kann -->
        </formula>

        <ramp>
            <input as="start">newsmoothstart</input>
            <input as="stop">newsmoothstop</input>
            <output>newsmoothti100</output>     <!-- Mögliche neue Glättungswerte -->
        </ramp>

        <rangefilter>
            <input clear="false">newsmoothti100</input>
            <input as="max" clear="false">tmaxsmooth</input>
            <output>newsmoothti</output>        <!-- Die Zeiten, zu denen wir nun wirklich glätten -->
        </rangefilter>

        <append>
            <input type="value">0</input>
            <input clear="false">t</input>
            <output>temp</output>               <!-- Erneut letzter Rohdatenwert, der schon aufgenommen wurde -->
        </append>

        <rangefilter>
            <input>newsmoothti100</input>
            <input as="min" clear="false">tmaxsmooth</input>
            <input as="max">temp</input>
            <output>incompletesmoothti</output>        <!-- Die Zeiten für neuere Datenpunkt, die wir nur als Vorschau glätten -->
        </rangefilter>

        <!-- Glätten -->

        <loess>
            <input as="x" clear="false">t</input>
            <input as="y" clear="false">x</input>
            <input as="xi" clear="false">newsmoothti</input>
            <input as="d" clear="false">d</input>
            <output as="yi0">newsmoothxi</output>
            <output as="yi1">newsmoothvi</output>
            <output as="yi2">newsmoothai</output>
        </loess>

        <loess>
            <input as="x" clear="false">t</input>
            <input as="y" clear="false">x</input>
            <input as="xi" clear="false">incompletesmoothti</input>
            <input as="d" clear="false">d</input>
            <output as="yi0">incompletesmoothxi</output>
            <output as="yi1">incompletesmoothvi</output>
            <output as="yi2">incompletesmoothai</output>
        </loess>

        <!-- Ergebnisse anhängen -->

        <append>
            <input>newsmoothti</input>
            <output clear="false">tout</output>
        </append>

        <append>
            <input>newsmoothxi</input>
            <output clear="false">xout</output>
        </append>

        <append>
            <input>newsmoothvi</input>
            <output clear="false">vout</output>
        </append>

        <append>
            <input>newsmoothai</input>
            <output clear="false">aout</output>
        </append>

        <!-- Puffer mit finalen Ergebnissen und Vorschau-Ergebnissen -->

        <append>
            <input clear="false">tout</input>
            <input clear="true">incompletesmoothti</input>
            <output clear="true">toutpreview</output>
        </append>

        <append>
            <input clear="false">xout</input>
            <input clear="true">incompletesmoothxi</input>
            <output clear="true">xoutpreview</output>
        </append>

        <append>
            <input clear="false">vout</input>
            <input clear="true">incompletesmoothvi</input>
            <output clear="true">voutpreview</output>
        </append>

        <append>
            <input clear="false">aout</input>
            <input clear="true">incompletesmoothai</input>
            <output clear="true">aoutpreview</output>
        </append>

        <multiply>
            <input clear="false">aoutpreview</input>
            <input type="value">2</input>
            <output>aoutpreview2</output>
        </multiply>

    </analysis>
    <views>
        <view label="Graph">
            <graph label="Distance" timeOnX="true" labelX="[[quantity_short_time]]" unitX="[[unit_short_second]]" labelY="[[quantity_short_distance]]" unitY="[[unit_short_meter]]" partialUpdate="true">
                <input axis="x" lineWidth="2">toutpreview</input>
                <input axis="y">xoutpreview</input>
                <input axis="x" style="dots" color="white">t</input>
                <input axis="y">x</input>
            </graph>
            <graph label="Velocity" timeOnX="true" labelX="[[quantity_short_time]]" unitX="[[unit_short_second]]" labelY="[[quantity_short_velocity]]" unitY="[[unit_short_meter_per_second]]" partialUpdate="true">
                <input axis="x" lineWidth="2">toutpreview</input>
                <input axis="y">voutpreview</input>
            </graph>
            <graph label="Acceleration" timeOnX="true" labelX="[[quantity_short_time]]" unitX="[[unit_short_second]]" labelY="[[quantity_short_acceleration]]" unitY="[[unit_short_meter_per_square_second]]" partialUpdate="true">
                <input axis="x" lineWidth="2">toutpreview</input>
                <input axis="y">aoutpreview2</input>
            </graph>
        </view>
        <view label="Setup">
          <depth-gui label="Control" />
          <separator height="1" />
          <edit label="Width of LOESS fit" unit="s" default="0.2">
            <output>d</output>
          </edit>
        </view>
    </views>
    <export>
        <set name="Raw Data">
            <data name="Time (s)">tout</data>
            <data name="Distance (m)">xout</data>
            <data name="Time (s)">tout</data>
            <data name="Velocity (m/s)">vout</data>
            <data name="Time (s)">tout</data>
            <data name="Acceleration (m/s²)">aout</data>
        </set>
    </export>
</phyphox>