Package lejos.robotics.filter
Class OffsetCorrectionFilter
- java.lang.Object
-
- lejos.robotics.filter.AbstractFilter
-
- lejos.robotics.filter.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
-
-
Field Summary
-
Fields inherited from class lejos.robotics.filter.AbstractFilter
sampleSize, source
-
-
Constructor Summary
Constructors Constructor Description OffsetCorrectionFilter(SampleProvider source)Constructor for the offset correction filter using default parameters.OffsetCorrectionFilter(SampleProvider source, float[] reference)Constructor for the offset correction filter using default window of 200 samples.OffsetCorrectionFilter(SampleProvider source, float[] reference, int bufferSize)Constructor for the offset correction filter.
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfetchSample(float[] sample, int offset)Fetches a sample from a sensor or filter.float[]getMean()Returns the mean sample valuefloat[]getStandardDeviation()Returns the standard deviation from the mean sample valuevoidreset()Resets the filter-
Methods inherited from class lejos.robotics.filter.AbstractFilter
sampleSize
-
-
-
-
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 samplereference- 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 samplereference- 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:SampleProviderFetches a sample from a sensor or filter.- Specified by:
fetchSamplein interfaceSampleProvider- Overrides:
fetchSamplein classAbstractFilter- 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
-
-