org.hermit.dsp
Class SignalPower

java.lang.Object
  extended by org.hermit.dsp.SignalPower

public final class SignalPower
extends java.lang.Object

A power metering algorithm.


Method Summary
static void biasAndRange(short[] sdata, int off, int samples, float[] out)
          Calculate the bias and range of the given input signal.
static double calculatePowerDb(short[] sdata, int off, int samples)
          Calculate the power of the given input signal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

biasAndRange

public static final void biasAndRange(short[] sdata,
                                      int off,
                                      int samples,
                                      float[] out)
Calculate the bias and range of the given input signal.

Parameters:
sdata - Buffer containing the input samples to process.
off - Offset in sdata of the data of interest.
samples - Number of data samples to process.
out - A float array in which the results will be placed Must have space for two entries, which will be set to:
  • The bias, i.e. the offset of the average signal value from zero.
  • The range, i.e. the absolute value of the largest departure from the bias level.
Throws:
java.lang.NullPointerException - Null output array reference.
java.lang.ArrayIndexOutOfBoundsException - Output array too small.

calculatePowerDb

public static final double calculatePowerDb(short[] sdata,
                                            int off,
                                            int samples)
Calculate the power of the given input signal.

Parameters:
sdata - Buffer containing the input samples to process.
off - Offset in sdata of the data of interest.
samples - Number of data samples to process.
Returns:
The calculated power in dB relative to the maximum input level; hence 0dB represents maximum power, and minimum power is about -95dB. Particular cases of interest:
  • A non-clipping full-range sine wave input is about -2.41dB.
  • Saturated input (heavily clipped) approaches 0dB.
  • A low-frequency fully saturated input can get above 0dB, but this would be pretty artificial.
  • A really tiny signal, which only occasionally deviates from zero, can get below -100dB.
  • A completely zero input will produce an output of -Infinity.
You must be prepared to handle this infinite result and results greater than zero, although clipping them off would be quite acceptable in most cases.