org.openuat.features
Class Coherence

java.lang.Object
  extended by org.openuat.features.Coherence

public class Coherence
extends java.lang.Object

This class implements computation of the coherence function. It is modelled after the Matlab/Octave "coher" function, but en explanation can e.g. be found at http://ccrma.stanford.edu/~jos/mdft/Coherence_Function_Matlab.html It uses the FFT class. The coherence is estimated as the power spectrum correlation between two signals split into overlapping slices. For each slice, the Fourier coefficients are computed and the magnitudes of these slices are averaged to compute the power spectra. Note: This class does not yet implement estimation of confidence intervals or de-trending like the Matlab/Octave implementations do. It is not necessary in the current use cases and has thus been omitted.

Version:
1.0
Author:
Rene Mayrhofer

Constructor Summary
Coherence()
           
 
Method Summary
static double[] cohere(double[] s1, double[] s2, int windowsize, int overlap)
          Compute the coherence between two signals.
static int getNumSlices(int signalLength, int windowsize, int overlap)
          This is a small helper function to compute how many slices will be used.
static double[] hann(int windowsize)
          This function just generates a von-Hann window of specified size, as defined at http://www.mathworks.com/access/helpdesk/help/toolbox/signal/hann.html
static double l2Norm(double[] vector)
          Helper function: calculates the L2-norm of a vector.
static double mean(double[] vector, int max_ind)
          Helper function: calculates the mean of the vector elements, up to a maximum index (or the whole vector if max_ind is set to -1 or larger than the vector length).
static double weightedCoherenceMean(double[] s1, double[] s2, int windowsize, int overlap, int max_ind)
          This is a helper function that computes the average over the coherence values, weighted by the number of slices that were used to compute the coherence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Coherence

public Coherence()
Method Detail

getNumSlices

public static int getNumSlices(int signalLength,
                               int windowsize,
                               int overlap)
This is a small helper function to compute how many slices will be used.


cohere

public static double[] cohere(double[] s1,
                              double[] s2,
                              int windowsize,
                              int overlap)
Compute the coherence between two signals. Overlapping windows are created with a length of exactly the number of FFT coefficients. The windows are then dot-multiplied with a von-Hann (sometimes called hanning) window and averaged.

Parameters:
s1 - Signal 1. Both signals must have equal length.
s2 - Signal 2. Both signals must have equal length.
windowsize - The window size to use, i.e. the number of FFT coefficients to compute. Defaults to min(256, s1.length) if set to <= 0.
overlap - The overlap of the windows to compute. Defaults to windowsize/2 when set to < 0.
Returns:
The coherence coefficients.

hann

public static double[] hann(int windowsize)
This function just generates a von-Hann window of specified size, as defined at http://www.mathworks.com/access/helpdesk/help/toolbox/signal/hann.html

Parameters:
windowsize - The size of the von-Hann window to generate.
Returns:
The von-Hann window.

l2Norm

public static double l2Norm(double[] vector)
Helper function: calculates the L2-norm of a vector.


mean

public static double mean(double[] vector,
                          int max_ind)
Helper function: calculates the mean of the vector elements, up to a maximum index (or the whole vector if max_ind is set to -1 or larger than the vector length).


weightedCoherenceMean

public static double weightedCoherenceMean(double[] s1,
                                           double[] s2,
                                           int windowsize,
                                           int overlap,
                                           int max_ind)
This is a helper function that computes the average over the coherence values, weighted by the number of slices that were used to compute the coherence. This weighting is necessary.

Parameters:
s1 - Signal 1. Both signals must have equal length.
s2 - Signal 2. Both signals must have equal length.
windowsize - The window size to use, i.e. the number of FFT coefficients to compute. Defaults to min(256, s1.length) if set to <= 0.
overlap - The overlap of the windows to compute. Defaults to windowsize/2 when set to <= 0.
max_ind - The maximum index of the FFT coefficient vectors to compare to. This can be used to only compare up to a specifiv frequency, and ignore higher frequencies. Set to -1 to use all coefficients.
Returns:
The coherence coefficients.


2005-2006, Rene Mayrhofer.