be.hogent.tarsos.sampled.pitch
Class PitchFunctions

java.lang.Object
  extended by be.hogent.tarsos.sampled.pitch.PitchFunctions

public final class PitchFunctions
extends java.lang.Object

Utility class for pitch conversions See pitch-representatio for some background.

Author:
Joren Six

Nested Class Summary
static class PitchFunctions.EportType
           
 
Method Summary
static void bandwithFilter(java.util.List<java.lang.Double> pitchValuesInHertz, double minValueInHertz, double maxValueInHertz)
          Removes all frequencies that are not in the specified band.
static java.util.List<java.lang.Double> convertHertzTo(PitchUnit unit, java.util.List<java.lang.Double> pitchValuesInHertz)
          Converts pitches in Hertz to the requested unit.
static Histogram createFrequencyTable(java.util.List<java.lang.Double> values, double classWidth, double start, double stop)
          Creates a frequency table.
static void exportFrequencyTable(Histogram histogram, java.lang.String fileName)
           
static void exportFrequencyTable(Histogram histogram, java.lang.String fileName, double start, double stop)
           
static java.util.List<java.lang.Double> gaussianFilter(java.util.List<java.lang.Double> listToFilter)
          Applies a Gaussian filter to the list to filter.
static java.util.List<java.lang.Double> gaussianFilter(java.util.List<java.lang.Double> listToFilter, double parameter)
          Applies a Gaussian filter to the list to filter.
static java.util.List<java.lang.Double> getGaussianSmoothed(java.util.List<java.lang.Double> listToSmooth, double standardDeviation)
          Smooths a list of doubles using a gaussian.
static java.lang.Double median(java.util.List<java.lang.Double> list)
          Calculates the median for a list of doubles.
static java.util.List<java.lang.Double> medianFilter(java.util.List<java.lang.Double> listToFilter, int n)
           Applies an order n one-dimensional median filter to the list to filter.
static Histogram readFrequencyTable(java.lang.String fileName)
          Reads a frequency table (histogram) from disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

convertHertzTo

public static java.util.List<java.lang.Double> convertHertzTo(PitchUnit unit,
                                                              java.util.List<java.lang.Double> pitchValuesInHertz)
Converts pitches in Hertz to the requested unit.

Parameters:
unit - The unit to convert from.
pitchValuesInHertz - The list of values to convert.
Returns:
The values converted to the requested unit. The original list remains unchanged.

bandwithFilter

public static void bandwithFilter(java.util.List<java.lang.Double> pitchValuesInHertz,
                                  double minValueInHertz,
                                  double maxValueInHertz)
Removes all frequencies that are not in the specified band. The remaining band consists only of frequencies between minValueInHertz and maxValueInHertz (inclusive).

Parameters:
pitchValuesInHertz - the values to filter.
minValueInHertz - the minimum frequency in Hertz.
maxValueInHertz - the maximum frequency in Hertz.

median

public static java.lang.Double median(java.util.List<java.lang.Double> list)
Calculates the median for a list of doubles. The list is sorted in-place.

Parameters:
list - The list.
Returns:
The median.
Throws:
If - the list is null or empty the median is undefined and an error is thrown.

medianFilter

public static java.util.List<java.lang.Double> medianFilter(java.util.List<java.lang.Double> listToFilter,
                                                            int n)

Applies an order n one-dimensional median filter to the list to filter. The function considers the signal to be 0 beyond the end points. The output has the same length as the list to filter.

Returns a new list.

n must be odd! The function is defined as:
f(bufferCount) = median( list(bufferCount-n/2) .. list(bufferCount+n/2) )

  So for n = 3 and list to filter:
    [3 7 4]
  0 [3 7 4] 0
    [3 4 7]
 

Parameters:
listToFilter - The list to filter.
n - An odd number. The order n of the one-dimensional median filter. An IllegalArgumentException is thrown when n is even.
Returns:
An order n one-dimensional median filtered list. The original list remains untouched. A new list is created.

getGaussianSmoothed

public static java.util.List<java.lang.Double> getGaussianSmoothed(java.util.List<java.lang.Double> listToSmooth,
                                                                   double standardDeviation)
Smooths a list of doubles using a gaussian.

Parameters:
listToSmooth - the list to smooth
standardDeviation - the standard deviation, 0 means return the original list, below zero is invalid.
Returns:
a list of Gaussian smoothed values.

gaussianFilter

public static java.util.List<java.lang.Double> gaussianFilter(java.util.List<java.lang.Double> listToFilter,
                                                              double parameter)
Applies a Gaussian filter to the list to filter. The parameter is arbitrary and can be 1/(2*standard deviation^2).

Parameters:
listToFilter - the list to filter
parameter - the parameter defining the impulse response of the filter.
Returns:
a Gaussian filtered list

gaussianFilter

public static java.util.List<java.lang.Double> gaussianFilter(java.util.List<java.lang.Double> listToFilter)
Applies a Gaussian filter to the list to filter. The parameter is 1/(2*standard deviation^2).

Parameters:
listToFilter - the list to filter
Returns:
An order n one-dimensional median filtered list.

createFrequencyTable

public static Histogram createFrequencyTable(java.util.List<java.lang.Double> values,
                                             double classWidth,
                                             double start,
                                             double stop)
Creates a frequency table. The number of items in each class is returned. Classes are defined by the limit and resolution. E.g. for a limit of 1200 with a resolution of 400 there are 3 classes: [0-400[, [400-800[ and [800-1200[.

Parameters:
values - the data to distribute over the bins/classes.
classWidth - the resolution or the with of the classes
start - the starting value
stop - the stopping value
Returns:
The number of items in each class

exportFrequencyTable

public static void exportFrequencyTable(Histogram histogram,
                                        java.lang.String fileName,
                                        double start,
                                        double stop)

exportFrequencyTable

public static void exportFrequencyTable(Histogram histogram,
                                        java.lang.String fileName)

readFrequencyTable

public static Histogram readFrequencyTable(java.lang.String fileName)
Reads a frequency table (histogram) from disk. The source file is expected to be a CSV-file in the format: value;frequency[;other data; is discarded;...] The lowest value is on the first row, the highest on the last!

Parameters:
fileName -
Returns:
a histogram.