Class Goertzel

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

public class Goertzel
extends java.lang.Object
implements Constants

The Goertzel class can be used to perform the Goertzel algorithm. In order to use this class, four primary steps should be executed: initialize the Goertzel class and all its variables (initGoertzel), process one sample of data at a time (processSample), get the relative magnitude returned by the Goertzle algorithm after N samples have been processed (getMagnitudeSquared, getRealImag), and reset the Goertzel class and all its variables (resetGoertzel).

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


Field Summary
 boolean debug
           
 
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
Goertzel()
          Default Constructor.
Goertzel(float sampleRate, float targetFreq, int inN, boolean inDebug)
          Constructor
 
Method Summary
 double getMagnitudeSquared()
          Optimized Goertzel.
 double[] getRealImag(double[] parts)
          Basic Goertzel.
 void initGoertzel()
          Call this once, to precompute the constants.
static void main(java.lang.String[] args)
          The main function used for testing.
 void processSample(double sample)
          Call this routine for every sample.
 void resetGoertzel()
          Call this method after every block of N samples has been processed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public boolean debug
Constructor Detail

Goertzel

public Goertzel()
Default Constructor. This constructor assumes that the smapling rate 44.1kHz, and the frequency to search for is 21kHz


Goertzel

public Goertzel(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

resetGoertzel

public void resetGoertzel()
Call this method after every block of N samples has been processed.

Returns:
void

initGoertzel

public void initGoertzel()
Call this once, to precompute the constants.

Returns:
void

processSample

public void processSample(double sample)
Call this routine for every sample.

Parameters:
sample - is a double
Returns:
void

getRealImag

public double[] getRealImag(double[] parts)
Basic Goertzel. Call this routine after every block to get the complex result.

Parameters:
parts - has length two where the first item is the real part and the second item is the complex part.
Returns:
double[] stores the values in the param

getMagnitudeSquared

public double getMagnitudeSquared()
Optimized Goertzel. Call this after every block to get the RELATIVE magnitude squared.

Returns:
double is the value of the relative mag squared.

main

public static void main(java.lang.String[] args)
The main function used for testing.

Returns: