Class OffsetCorrectionFilter

  • All Implemented Interfaces:
    SampleProvider

    public class OffsetCorrectionFilter
    extends AbstractFilter
    The OffsetCorrectionFilter is used to correct sensors that have an unknown offset error.
    The offset error is calculated by this class and then substracted from the sample to give a corrected sample. The filter works by calculating a running mean of a sample. this mean value is compared to the reference value, the difference between the two is the offset error. Not all samples are used to calculate the running mean. Only those samples that seem to indicate a stable (initial) situation are used for calculating the mean.
    Author:
    Aswin
    • Constructor Detail

      • OffsetCorrectionFilter

        public OffsetCorrectionFilter​(SampleProvider source)
        Constructor for the offset correction filter using default parameters.
        All samples are corrected to a reference value of zero using a window of 200 samples for calculating the mean
        Parameters:
        source - source for sample
      • OffsetCorrectionFilter

        public OffsetCorrectionFilter​(SampleProvider source,
                                      float[] reference)
        Constructor for the offset correction filter using default window of 200 samples.
        All samples are corrected to the specified reference values
        Parameters:
        source - source for sample
        reference - An array with reference values. The array length should match the sample size.
      • OffsetCorrectionFilter

        public OffsetCorrectionFilter​(SampleProvider source,
                                      float[] reference,
                                      int bufferSize)
        Constructor for the offset correction filter.
        Constructor
        Parameters:
        source - Source for sample
        reference - An array with reference values. The array length should match the sample size.
        bufferSize - Number of samples to use for calculating offset error
    • Method Detail

      • fetchSample

        public void fetchSample​(float[] sample,
                                int offset)
        Description copied from interface: SampleProvider
        Fetches a sample from a sensor or filter.
        Specified by:
        fetchSample in interface SampleProvider
        Overrides:
        fetchSample in class AbstractFilter
        Parameters:
        sample - The array to store the sample in.
        offset - The elements of the sample are stored in the array starting at the offset position.
      • reset

        public void reset()
        Resets the filter
      • getMean

        public float[] getMean()
        Returns the mean sample value
        Returns:
        the mean sample value
      • getStandardDeviation

        public float[] getStandardDeviation()
        Returns the standard deviation from the mean sample value
        Returns:
        the standard deviation from the mean sample value