A Filter is a Physlet that takes data from a data source, processes the data, and passes this processed data to a data listener.
The Moments filter calculates the average and standard deviation (that is the square root of the mean squared deviation) of incoming data. In this example, the red ball sends its state (e.g., a sate datum for an Animator object contains the variables t, x, y, vx, vy, ax, ay, fx, fy, and m) to the filter at every clock tick. The script takes either the x or the x*x value and passes it to the Moments filter.
The Moments Physlet has two modes of operation whenever it receives complete data sets. These modes are determined by the setAutoReplaceData flag.
In the first mode, setAutoReplaceData=false, a new data set does not replace old data but is added to the old data.
In the second mode, setAutoReplaceData=true, a new data replaces and old data and the old values are lost. This is the default behavior.
The setAutoReplaceData signature is setAutoReplaceData(int sid, boolean set). The series identifier, sid, has no effect but has been included for consistency with other Physlets. The set variable determines the value.