ESP OpenBCI - An EEG Signal Processing Library for OpenBCI Hardware

com.github.mrstampy.esp.dsp
Class EspSignalUtilities

java.lang.Object
  extended by com.github.mrstampy.esp.dsp.EspSignalUtilities
Direct Known Subclasses:
OpenBCISignalUtilities

public abstract class EspSignalUtilities
extends java.lang.Object

A collection of utility methods which may or may not be useful when analysing a raw signal.

Author:
burton

Constructor Summary
protected EspSignalUtilities(ddf.minim.analysis.WindowFunction window)
          Instantiates a new esp signal utilities.
 
Method Summary
 double[] absolute(double[] array)
          Returns the absolute (positive) values of the given array.
 de.dfki.lt.signalproc.filter.BandPassFilter createBandPassFilter(double lowerCutoffHz, double upperCutoffHz)
          Creates the band pass filter.
 de.dfki.lt.signalproc.filter.HighPassFilter createHighPassFilter(double cutoffHz)
          Creates the high pass filter.
 de.dfki.lt.signalproc.filter.LowPassFilter createLowPassFilter(double cutoffHz)
          Creates the low pass filter.
 double[] fftLogPowerSpectrum(double[] sample)
          Returns the log of the power spectrum of the given time domain sample.
 double[] fftRealSpectrum(double[] sample)
          Returns the real half of the fft transform of the given time domain sample.
abstract  AbstractDSPValues getDSPValues()
          Gets the DSP values.
 de.dfki.lt.signalproc.filter.LowPassFilter getEspLowPassFilter()
          Convenience method to create an esp - specific low pass filter, filtering out signals above getUpperMeasurableFrequency() - 0.1.
protected abstract  int getFFTSize()
          Return the size of the sample arrays.
 double getLogPower(double[] logFftd, double frequency)
          Linearly estimates the signal power at the specified frequency, between the surrounding two fft data points (non-integer value between 1 Hz and ( getUpperMeasurableFrequency() - 1) Hz exclusive).
 double getLogPower(double[] logFftd, int lowerFreqHz, int upperFreqHz)
          Attempts average the power over the specified range by providing more weight to values in between lower & upper frequencies ie:

For range i to i + 2, weights 1, 2, 1
For range i to i + 3, weights 1, 2, 2, 1
For range i to i + 4, weights 1, 2, 3, 2, 1
.
 java.util.Map<java.lang.Double,java.lang.Double> getLogPowersFor(double[] sample, double... frequencies)
          Returns a map of frequency / log power pairs from the given sample.
protected abstract  java.math.BigDecimal getRawSignalBreadth()
          Return the range of the raw signal values (max - min).
protected abstract  double getSampleRate()
          Return the sample rate.
protected  double getUpperMeasurableFrequency()
          Gets the upper measurable frequency.
 double[] normalize(double[] sample)
          Normalizes the raw signal to values between 0 and 1;.
 double[] normalize(double[] sample, double scale)
          Normalizes the raw signal to values between 0 and scale;.
 double[] normalize(double[] fftd, int lowerCutoffHz, int upperCutoffHz)
          Returns an array of size upperCutoffHz + 1, containing the normalized values in the specified array from index lower thru upperCutoffHz inclusive.
 double rms(int lowerFreqHz, int upperFreqHz, double... fftd)
          Returns the root mean square value of the given inputs over the given range.
 void setWindow(ddf.minim.analysis.WindowFunction window)
          Sets the windowing function within the FFT instance.
 double wma(double... powers)
          Returns the weighted moving average of the given inputs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EspSignalUtilities

protected EspSignalUtilities(ddf.minim.analysis.WindowFunction window)
Instantiates a new esp signal utilities.

Parameters:
window - the window
Method Detail

setWindow

public void setWindow(ddf.minim.analysis.WindowFunction window)
Sets the windowing function within the FFT instance.

Parameters:
window - the new window

getLogPowersFor

public java.util.Map<java.lang.Double,java.lang.Double> getLogPowersFor(double[] sample,
                                                                        double... frequencies)
Returns a map of frequency / log power pairs from the given sample. This method is not thread safe.

Parameters:
sample - the sample
frequencies - the frequencies
Returns:
the log powers for

fftRealSpectrum

public double[] fftRealSpectrum(double[] sample)
Returns the real half of the fft transform of the given time domain sample. This method is not thread safe.

Parameters:
sample - the sample
Returns:
the double[]

fftLogPowerSpectrum

public double[] fftLogPowerSpectrum(double[] sample)
Returns the log of the power spectrum of the given time domain sample. This method is not thread safe.

Parameters:
sample - the sample
Returns:
the double[]
See Also:
getLogPower(double[], double), getLogPower(double[], int, int)

getLogPower

public double getLogPower(double[] logFftd,
                          int lowerFreqHz,
                          int upperFreqHz)
Attempts average the power over the specified range by providing more weight to values in between lower & upper frequencies ie:

For range i to i + 2, weights 1, 2, 1
For range i to i + 3, weights 1, 2, 2, 1
For range i to i + 4, weights 1, 2, 3, 2, 1
.

Parameters:
logFftd - the frequency-domain shifted sample
lowerFreqHz - > 0 Hz
upperFreqHz - < getUpperMeasurableFrequency() Hz
Returns:
the log power
See Also:
fftLogPowerSpectrum(double[]), createBandPassFilter(double, double)

getLogPower

public double getLogPower(double[] logFftd,
                          double frequency)
Linearly estimates the signal power at the specified frequency, between the surrounding two fft data points (non-integer value between 1 Hz and ( getUpperMeasurableFrequency() - 1) Hz exclusive).

Parameters:
logFftd - the frequency-domain shifted sample
frequency - non-integer, > 1 && < (getUpperMeasurableFrequency() - 1)
Returns:
the log power
See Also:
fftLogPowerSpectrum(double[])

normalize

public double[] normalize(double[] fftd,
                          int lowerCutoffHz,
                          int upperCutoffHz)
Returns an array of size upperCutoffHz + 1, containing the normalized values in the specified array from index lower thru upperCutoffHz inclusive. Indexes outside of the range will have a zero value.

Parameters:
fftd - the specified array of frequency domain values
lowerCutoffHz - the minimum index to use for normalization, >= 1
upperCutoffHz - the maximum index to use for normalization, < getUpperMeasurableFrequency()
Returns:
the double[]

normalize

public double[] normalize(double[] sample)
Normalizes the raw signal to values between 0 and 1;.

Parameters:
sample - the sample
Returns:
the double[]

normalize

public double[] normalize(double[] sample,
                          double scale)
Normalizes the raw signal to values between 0 and scale;.

Parameters:
sample - the sample
scale - the scale amount
Returns:
the double[]

rms

public double rms(int lowerFreqHz,
                  int upperFreqHz,
                  double... fftd)
Returns the root mean square value of the given inputs over the given range.

Parameters:
lowerFreqHz - >= 1
upperFreqHz - < getUpperMeasurableFrequency()
fftd - powers
Returns:
the rms value

wma

public double wma(double... powers)
Returns the weighted moving average of the given inputs. The first element is considered to be the least weight (or oldest value).

Parameters:
powers - the powers
Returns:
the double

createBandPassFilter

public de.dfki.lt.signalproc.filter.BandPassFilter createBandPassFilter(double lowerCutoffHz,
                                                                        double upperCutoffHz)
Creates the band pass filter.

Parameters:
lowerCutoffHz - the lower cutoff hz
upperCutoffHz - the upper cutoff hz
Returns:
the band pass filter

createHighPassFilter

public de.dfki.lt.signalproc.filter.HighPassFilter createHighPassFilter(double cutoffHz)
Creates the high pass filter.

Parameters:
cutoffHz - the cutoff hz
Returns:
the high pass filter

createLowPassFilter

public de.dfki.lt.signalproc.filter.LowPassFilter createLowPassFilter(double cutoffHz)
Creates the low pass filter.

Parameters:
cutoffHz - the cutoff hz
Returns:
the low pass filter

getEspLowPassFilter

public de.dfki.lt.signalproc.filter.LowPassFilter getEspLowPassFilter()
Convenience method to create an esp - specific low pass filter, filtering out signals above getUpperMeasurableFrequency() - 0.1.

Returns:
the esp low pass filter

absolute

public double[] absolute(double[] array)
Returns the absolute (positive) values of the given array.

Parameters:
array - the array
Returns:
the double[]

getDSPValues

public abstract AbstractDSPValues getDSPValues()
Gets the DSP values.

Returns:
the DSP values

getUpperMeasurableFrequency

protected double getUpperMeasurableFrequency()
Gets the upper measurable frequency.

Returns:
the upper measurable frequency

getFFTSize

protected abstract int getFFTSize()
Return the size of the sample arrays. Must be a power of 2;

Returns:
the FFT size

getSampleRate

protected abstract double getSampleRate()
Return the sample rate.

Returns:
the sample rate

getRawSignalBreadth

protected abstract java.math.BigDecimal getRawSignalBreadth()
Return the range of the raw signal values (max - min).

Returns:
the raw signal breadth

brought to you by Mr. Stampy