Class UltrasoundDetector

java.lang.Object
  extended byUltrasoundDetector
All Implemented Interfaces:
Constants

public class UltrasoundDetector
extends java.lang.Object
implements Constants

The UltrasoundDetector class can be used to help analyze an ultrasound signal. UltrasoundDetector creates three Goertzel objects in order to determine whether or not the desired frequency is present in a set of data. One Goertzel object performs the Goertzel algorithm with the target frequency, obtaining a relative magnitude for this frequency, while the other two Goertzel objects perform the Goertzel algorithm with frequencies slightly above and slightly below the target frequency. The relative magnitude returned by the target frequency is compared to the relative magnitudes returned by the other two frequencies. If the magnitude of the target frequency is more than twice the average of the other two magnitudes, the UltrasoundDetector class decides that ultrasound has been detected.

After it is constructed with the desired parameters, an UltrasoundDetector must be initialized with the init method. After initialization, the analyze method can be called to determine whether the target frequency is present in a block of N data samples.

This class is based on a C program implemented by Kevin Banks of Embedded Systems Programming.


Field Summary
protected  boolean debug
           
protected  Goertzel g
           
protected  Goertzel gless
           
protected  Goertzel gmore
           
 
Fields inherited from interface Constants
AVG_DETECT_TIME, BIGEND, DEBOUNCE_VAL, GROUPADDR, HISTORY_SIZE, MAX_DETECT_TIME, MAXMSGSIZE, N, NUMTHREADS, PORTNUM, ROOM_MSG_BUF, SAMPLE_SIZE, SAMPLING_RATE, SEQUENCE, SIGN, TARGET_FREQUENCY, WEIGHT
 
Constructor Summary
UltrasoundDetector()
          Default Constructor
UltrasoundDetector(float sampleRate, float targetFreq, int inN, boolean inDebug)
          Constructor.
 
Method Summary
 boolean analyze(double[] block)
          This is the main method of the UltrasoundDetector class and it is used for testing N samples for the presence of the frequency specified by TARGET_FREQUENCY.
 int getN()
          Provide means to access the value of N that is used by the Goertzel algorithm to detect the presence of a specified frequency.
 void init()
          Method to initialize the Goertzel algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

protected boolean debug

g

protected Goertzel g

gless

protected Goertzel gless

gmore

protected Goertzel gmore
Constructor Detail

UltrasoundDetector

public UltrasoundDetector()
Default Constructor


UltrasoundDetector

public UltrasoundDetector(float sampleRate,
                          float targetFreq,
                          int inN,
                          boolean inDebug)
Constructor.

Parameters:
sampleRate - is the sampling rate of the signal to be analyzed
targetFreq - is the frequency that Goertzel will look for.
inN - is the block size to use with Goertzel
inDebug - indicates whether or not to turn debugging info on.
Method Detail

init

public void init()
Method to initialize the Goertzel algorithm. If this method is not called, the Goertzel algorithm will be initialized using the default values defined in Goertzel.java.


getN

public int getN()
Provide means to access the value of N that is used by the Goertzel algorithm to detect the presence of a specified frequency. N should be the number of samples that are given to this class to process since the Goertzel algorithm returns a result every N samples.

Returns:
The value of N used by the Goertzel algorithm.

analyze

public boolean analyze(double[] block)
This is the main method of the UltrasoundDetector class and it is used for testing N samples for the presence of the frequency specified by TARGET_FREQUENCY. An array of size N and type double is passed into this method and tested to see whether or not the desired frequency is present in the N samples.

Parameters:
block - An array of type double containing the N samples.
Returns:
Boolean indicating whether or not the frequency was present.