org.android.activityminer.logic.filter
Class AdaptiveLowPassFilter

Package class diagram package AdaptiveLowPassFilter
java.lang.Object
  extended by org.android.activityminer.logic.filter.AdaptiveLowPassFilter
All Implemented Interfaces:
LowPassFilter

public final class AdaptiveLowPassFilter
extends Object
implements LowPassFilter

An adaptive low pass filter implementation based on the 1 Euro Filter algorithm.


Field Summary
private  double beta
          The cutoff slope
private  double[] currentVariation
          The current signal variation in time (signal changes over time as signal derivative).
private  double[] cutOffFreq
          The dynamically calculated cutoff frequency for the signal.
static double DEFAULT_BETA
          The default cut-off slope for the signal used by the adaptive filter.
static double DEFAULT_DERIVATIVE_CUTOFF_FREQ
          The default minimum cutoff frequency for the signal derivative.
static double DEFAULT_MIN_CUTOFF_FREQ
          The default minimum cutoff frequency for the signal used by the adaptive filter.
private  double frequency
          The current frequency in Hz.
private  long lastTs
          The last time stamp.
private  double[] lastVariation
          The last signal variation in time.
private  double[] lastX
          The last input signal.
private  double minCutOffFreq
          The minimum cutoff frequency.
private  String msgInvalidBeta
          The message for invalid beta values.
private  String msgInvalidCutOff
          The message for invalid minimum cut-off frequency values.
private  double variationCutOffFreq
          The cutoff frequency for the signal variation in time (the derivative cut-off frequency).
 
Constructor Summary
AdaptiveLowPassFilter(Context context, double minCutOffFreq, double beta)
          Constructor with a variation cutoff of 1.0.
AdaptiveLowPassFilter(Context context, double rate, double minCutOffFreq, double beta, double variationCutOffFreq)
          Constructor
 
Method Summary
 void apply(List<Double> x, List<Double> y, List<Double> z, List<Long> ts)
          Does apply this filter to an accelerometer time series stream.
private  double[] calculateCurrentVariation(double[] x, double[] y)
          Method to calculate the current signal variation in time.
 double getAlpha(double cutOffFreq)
          Getter for the smoothing factor alpha using a single cutoff frequencies for all dimension.
private  double[] getAlpha(double[] cutOffFreq)
          Getter for the smoothing factor alpha using a different cutoff frequencies for each signal dimension.
 double getBeta()
          Getter for the beta value ( cutoff scope )
 double getMinCutOffFreq()
          Getter for the the minimum cutoff frequency
 double[] lowPass(double[] x, double[] y, long currentTs)
          The filter function.
 void reset()
          Does reset the filter
 void setBeta(double beta)
          Setter for the beta value ( cutoff scope )
 void setCutOffFrequency(double cf)
          Setter for the cut-off frequency
protected  void setFrequency(double frequency)
          Setter for the frequency
 void setMinCutOffFreq(double minCutOffFreq)
          Setter for the minimum cutoff frequency
 void updateConfiguration(RuntimeConfiguration config)
          Does update the filter settings by the given configuration.
private  double[] updateCutOffFrequency(double[] estimatedVariation)
          Method to update the cutOffFrequency based in the estimated signal variation in time.
static boolean validateBeta(double beta)
          Test method for valid beta values.
static boolean validateMinCutOffFreq(double minCutOffFreq)
          Test method for minimum cutoff frequency values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

msgInvalidCutOff

private final String msgInvalidCutOff
The message for invalid minimum cut-off frequency values.


msgInvalidBeta

private final String msgInvalidBeta
The message for invalid beta values.


DEFAULT_MIN_CUTOFF_FREQ

public static final double DEFAULT_MIN_CUTOFF_FREQ
The default minimum cutoff frequency for the signal used by the adaptive filter.

See Also:
Constant Field Values

DEFAULT_DERIVATIVE_CUTOFF_FREQ

public static final double DEFAULT_DERIVATIVE_CUTOFF_FREQ
The default minimum cutoff frequency for the signal derivative.

See Also:
Constant Field Values

DEFAULT_BETA

public static final double DEFAULT_BETA
The default cut-off slope for the signal used by the adaptive filter.

See Also:
Constant Field Values

lastTs

private long lastTs
The last time stamp.


currentVariation

private double[] currentVariation
The current signal variation in time (signal changes over time as signal derivative).


lastVariation

private double[] lastVariation
The last signal variation in time.


lastX

private double[] lastX
The last input signal.


cutOffFreq

private double[] cutOffFreq
The dynamically calculated cutoff frequency for the signal.


frequency

private double frequency
The current frequency in Hz.


beta

private double beta
The cutoff slope


minCutOffFreq

private double minCutOffFreq
The minimum cutoff frequency.


variationCutOffFreq

private final double variationCutOffFreq
The cutoff frequency for the signal variation in time (the derivative cut-off frequency).

Constructor Detail

AdaptiveLowPassFilter

public AdaptiveLowPassFilter(Context context,
                             double minCutOffFreq,
                             double beta)
Constructor with a variation cutoff of 1.0.

Parameters:
context - the context
minCutOffFreq - the minimum cutoff frequency for the signal
beta - the cutoff slope for the signal

AdaptiveLowPassFilter

public AdaptiveLowPassFilter(Context context,
                             double rate,
                             double minCutOffFreq,
                             double beta,
                             double variationCutOffFreq)
Constructor

Parameters:
context - the context
rate - the estimated initial sample rate in milliseconds
minCutOffFreq - the minimum cutoff frequency for the signal
beta - the cutoff slope for the signal
variationCutOffFreq - the cutoff frequency for the signal variation in time
Method Detail

setFrequency

protected final void setFrequency(double frequency)
Setter for the frequency

Parameters:
frequency - the frequency to set

setMinCutOffFreq

public final void setMinCutOffFreq(double minCutOffFreq)
Setter for the minimum cutoff frequency

Parameters:
minCutOffFreq - the minimum cutoff frequency to set

validateMinCutOffFreq

public static final boolean validateMinCutOffFreq(double minCutOffFreq)
Test method for minimum cutoff frequency values.

Parameters:
minCutOffFreq - the minimum cutoff frequency to test
Returns:
true if valid, false otherwise

setBeta

public final void setBeta(double beta)
Setter for the beta value ( cutoff scope )

Parameters:
beta - the beta to set

validateBeta

public static final boolean validateBeta(double beta)
Test method for valid beta values.

Parameters:
beta - the beta value to test
Returns:
true if valid, false otherwise

getBeta

public final double getBeta()
Getter for the beta value ( cutoff scope )

Returns:
the beta value

getMinCutOffFreq

public final double getMinCutOffFreq()
Getter for the the minimum cutoff frequency

Returns:
the the minimum cutoff frequency

getAlpha

public final double getAlpha(double cutOffFreq)
Getter for the smoothing factor alpha using a single cutoff frequencies for all dimension.

Parameters:
cutOffFreq - the cut of frequency in Hz
Returns:
the smoothing actor

getAlpha

private final double[] getAlpha(double[] cutOffFreq)
Getter for the smoothing factor alpha using a different cutoff frequencies for each signal dimension.

Parameters:
cutOffFreq - the cut of frequencies per signal dimension in Hz
Returns:
the smoothing actor

calculateCurrentVariation

private final double[] calculateCurrentVariation(double[] x,
                                                 double[] y)
Method to calculate the current signal variation in time.

Parameters:
x - the actual input signal
y - the last output signal
Returns:
the variation

updateCutOffFrequency

private final double[] updateCutOffFrequency(double[] estimatedVariation)
Method to update the cutOffFrequency based in the estimated signal variation in time.

Parameters:
estimatedVariation - the estimated variation
Returns:
the updated cutoff frequency

lowPass

public final double[] lowPass(double[] x,
                              double[] y,
                              long currentTs)
Description copied from interface: LowPassFilter
The filter function.

Specified by:
lowPass in interface LowPassFilter
Parameters:
x - the actual input signal
y - the last output signal
currentTs - the current time stamp
Returns:
the current output signal

apply

public final void apply(List<Double> x,
                        List<Double> y,
                        List<Double> z,
                        List<Long> ts)
Description copied from interface: LowPassFilter
Does apply this filter to an accelerometer time series stream.

Specified by:
apply in interface LowPassFilter
Parameters:
x - the x axis signal stream
y - the y axis signal stream
z - the z axis signal stream
ts - the time stamps

updateConfiguration

public final void updateConfiguration(RuntimeConfiguration config)
Description copied from interface: LowPassFilter
Does update the filter settings by the given configuration.

Specified by:
updateConfiguration in interface LowPassFilter
Parameters:
config - the configuration to update from.

reset

public void reset()
Description copied from interface: LowPassFilter
Does reset the filter

Specified by:
reset in interface LowPassFilter

setCutOffFrequency

public void setCutOffFrequency(double cf)
Description copied from interface: LowPassFilter
Setter for the cut-off frequency

Specified by:
setCutOffFrequency in interface LowPassFilter
Parameters:
cf - the cut-off frequencyy