org.mbari.siam.utils
Class StaLtaEventDetector

java.lang.Object
  extended by org.mbari.siam.utils.StaLtaEventDetector

public class StaLtaEventDetector
extends java.lang.Object

Detect events based on ratio of moving short-term average ("STA") to moving long-term average ("LTA") of some input data. Detector is in "triggered" state when STA/LTA exceeds specified "trigger ratio". Detector is in "de-triggered" state when STA/LTA is less than specified "de-trigger" ratio. Notify listeners when state transitions between triggered and de-triggered states. Based on seismology algorithm described in "Instrumentation in Earthquake Seismology" by Havskov and Alguacil, p 117 (available at http://www.terraip.co.jp/Seismometers.pdf)


Nested Class Summary
static interface StaLtaEventDetector.Listener
          Interface for event listeners
 
Field Summary
protected  float _deTriggerRatio
           
protected  java.util.Vector _listeners
          Event listeners
protected static org.apache.log4j.Logger _log4j
           
protected  double _lta
           
protected  java.util.LinkedList _ltaSamples
           
protected  int _ltaSampleWidth
           
protected  int _maxTriggeredSamples
          Maximum consecutive sample accumulated in un-triggered state
protected  int _nConsecTriggeredSamples
           
protected  long _nSample
           
protected  java.lang.String _parameterName
           
protected  boolean _ready
           
protected  double _sta
           
protected  java.util.LinkedList _staSamples
           
protected  int _staSampleWidth
           
protected  long _transitionEpochMsec
           
protected  boolean _triggeredState
           
protected  float _triggerRatio
           
 
Constructor Summary
StaLtaEventDetector(java.lang.String parameterName, int staSampleWidth, int ltaSampleWidth, float triggerRatio, float deTriggerRatio, int maxTriggeredSamples)
           
 
Method Summary
 void addListener(StaLtaEventDetector.Listener listener)
          Add event listener
 void addSample(java.lang.Number newSample, long epochMsecTimestamp)
          Add next sample, compute moving averages and evaluate state
protected  void checkParameters(int staSampleWidth, int ltaSampleWidth, float triggerRatio, float deTriggerRatio, int maxTriggeredSamples)
          Check that user-set parameters are valid.
protected  void deTrigger(long epochMsec)
          Transition to detriggered state
 double getLTA()
           
 long getNsamples()
           
protected  double getRunningAverage(java.util.LinkedList samples, java.lang.Number newSample, int width, double prevAverage)
          Return running average
 double getSTA()
           
 long getTransitionTime()
          Return time of last transition, in epoch millsec
protected  void notifyListeners(boolean triggeredState)
          Notify listeners of state transition
 void reset()
          Reset; set averages to zero, restart accumulation
 void setParameters(int staSampleWidth, int ltaSampleWidth, float triggerRatio, float deTriggerRatio, int maxTriggeredSamples)
          Set parameters.
 java.lang.String toString()
          Return String representation
protected  void trigger(long epochMsec)
          Transition to triggered state
 boolean triggeredState()
          Return true if detector is in 'triggered' state, else return false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_log4j

protected static org.apache.log4j.Logger _log4j

_parameterName

protected java.lang.String _parameterName

_staSampleWidth

protected int _staSampleWidth

_ltaSampleWidth

protected int _ltaSampleWidth

_nSample

protected long _nSample

_maxTriggeredSamples

protected int _maxTriggeredSamples
Maximum consecutive sample accumulated in un-triggered state


_triggerRatio

protected float _triggerRatio

_deTriggerRatio

protected float _deTriggerRatio

_sta

protected double _sta

_lta

protected double _lta

_staSamples

protected java.util.LinkedList _staSamples

_ltaSamples

protected java.util.LinkedList _ltaSamples

_nConsecTriggeredSamples

protected int _nConsecTriggeredSamples

_triggeredState

protected boolean _triggeredState

_ready

protected boolean _ready

_transitionEpochMsec

protected long _transitionEpochMsec

_listeners

protected java.util.Vector _listeners
Event listeners

Constructor Detail

StaLtaEventDetector

public StaLtaEventDetector(java.lang.String parameterName,
                           int staSampleWidth,
                           int ltaSampleWidth,
                           float triggerRatio,
                           float deTriggerRatio,
                           int maxTriggeredSamples)
                    throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

toString

public java.lang.String toString()
Return String representation

Overrides:
toString in class java.lang.Object

getLTA

public double getLTA()

getSTA

public double getSTA()

getTransitionTime

public long getTransitionTime()
Return time of last transition, in epoch millsec


getNsamples

public long getNsamples()

reset

public void reset()
Reset; set averages to zero, restart accumulation


triggeredState

public boolean triggeredState()
Return true if detector is in 'triggered' state, else return false.


setParameters

public void setParameters(int staSampleWidth,
                          int ltaSampleWidth,
                          float triggerRatio,
                          float deTriggerRatio,
                          int maxTriggeredSamples)
                   throws java.lang.Exception
Set parameters. If input parameters are invalid, throws Exception without changing current parameters.

Throws:
java.lang.Exception

checkParameters

protected void checkParameters(int staSampleWidth,
                               int ltaSampleWidth,
                               float triggerRatio,
                               float deTriggerRatio,
                               int maxTriggeredSamples)
                        throws java.lang.Exception
Check that user-set parameters are valid.

Throws:
java.lang.Exception

getRunningAverage

protected double getRunningAverage(java.util.LinkedList samples,
                                   java.lang.Number newSample,
                                   int width,
                                   double prevAverage)
Return running average


addSample

public void addSample(java.lang.Number newSample,
                      long epochMsecTimestamp)
               throws java.lang.Exception
Add next sample, compute moving averages and evaluate state

Throws:
java.lang.Exception

trigger

protected void trigger(long epochMsec)
Transition to triggered state


deTrigger

protected void deTrigger(long epochMsec)
Transition to detriggered state


notifyListeners

protected void notifyListeners(boolean triggeredState)
Notify listeners of state transition


addListener

public void addListener(StaLtaEventDetector.Listener listener)
Add event listener



Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.