math
Class Mat1

java.lang.Object
  extended by math.Mat1

public abstract class Mat1
extends java.lang.Object

Mat1 is a class that uses 1-D arrays and contains static methods.

Author:
Douglas Lyon

Constructor Summary
Mat1()
           
 
Method Summary
static double add(double[] a)
           
static void add(double[] a, double[] b)
          Add two vectors.
static void add(double[] a, double[] b, double c)
          Add a vector times a scalar to a vector.
static double add(float[] a)
           
static void add(float[] a, float[] b)
          Add two vectors.
static void add(float[] a, float[] b, float[] c)
           
static double add(short[] a)
           
static double add16(float[] a)
           
static float add4(float[] a)
           
static float add8(float[] a)
           
static void add8(float[] a, float[] b, float[] c)
           
static double add8Depend(float[] a)
           
static double add8NoDepend(float[] a)
           
static float addFloat(float[] a)
          Sums up the numbers into a float.
static double[] arrayCopy(double[] in)
           
static float[] arrayCopy(float[] in)
           
static double coefficientOfVariation(int[] a)
           
static short[][] copy(short[][] r)
           
static short[] copyArray(short[] a)
           
static double dot(double[] a)
          Calculate the dot product of a vector with itself.
static double dot(double[] a, double[] b)
          Calculate the dot product of two vectors.
static double dot(double[] a, double[] b, int j)
          Calculate the dot product of two vectors.
static float getMax(float[] a)
           
static short getMax(short[] a)
           
static double getMaxValue(double[] in)
           
static double getMean(double[] values)
          Computes the mean value for the argument array.
static double[] getMean(double[] a, double[] b, double[] c)
           
static double getMean(double[] values, int offset, int number)
          Computes the mean value for some elements of the argument array.
static double getMean(float[] a)
          Compute the average.
static double getMean(int[] a)
           
static double getMean(short[] a)
          Compute the average.
static float getMin(float[] a)
           
static short getMin(short[] a)
           
static java.util.Vector getOverlappedWindows(double[] data)
          return a vector of arrays, each array is only 256 elements long, each array overlaps by 50% with each other array.
static double[] getRampData(int n)
          Generate an array of doubles that is n elements long and has numbers that range from 0 to n-1.
static float[] getRampDataFloat(int n)
           
static double getStandardDeviation(double[] values)
          Computes the standard deviation for the argument array of values.
static double getStandardDeviation(double[] values, double mean)
          Computes the standard deviation for the argument array of values.
static double getStandardDeviation(double[] values, int offset, int number)
          Computes the standard deviation for some of the argument array's values.
static double getStandardDeviation(double[] values, int offset, int number, double mean)
          Computes the standard deviation for some of the argument array's values.
static double getVariance(double[] values)
          Computes the variance for the argument array.
static double getVariance(double[] values, double mean)
          Computes the variance for some of the argument array's values.
static double getVariance(double[] values, int offset, int number)
          Computes the variance for some of the argument array's values.
static double getVariance(double[] values, int offset, int number, double mean)
          Computes the variance for some of the argument array's values.
static double getVariance(int[] a)
           
static void intQuickSort(int[] a)
           
static void logArray(double[] a)
           
static double magnitude(double[] a)
          Calculate the magnitude a vector.
static void main(java.lang.String[] args)
           
static double[] makeBartlett(int n)
           
static void makeHanning()
           
static double[] makeHanning(int n)
           
static void makeLyon()
           
static double[] makeLyon(int n)
           
static double mean(int[] a)
           
static double mean(short[][] a)
           
static void normalize(double[] a)
          Sum all the elements in an array, then divide by the total.
static void normalize(float[] a)
           
static float[] normalize(short[] a)
           
static int numberOfNonZeros(short[][] k)
           
static boolean outlierHere(int[] a)
           
static double[] padOutWithZeros(double[] b, int length)
          This method will pad out a new array of length length and return it.
static void print(double[] a)
           
static void print(double[] v, java.lang.String title)
           
static void print(float[] a)
           
static void print(int[] a)
           
static void print(java.lang.Object[] o)
           
static void printMedian(short[][] k, java.lang.String name)
           
static void printStats(float[] a)
           
static void printStats(java.lang.String title, float[] a)
           
static void quickSort(int[] a)
           
static void quickSort(int[] a, int lo0, int hi0)
           
static float[] ramp(float start, float end, int n)
           
static void removeTheDcComponent(float[] m)
           
static void scale(double[] a, double k)
           
static void scale(float[] a, double k)
           
static void scale(float[] a, float k)
           
static float[] scale(short[] a, float k)
           
static void scaleIntoRange(float[] im, float min, float max, int maxValueOutput)
           
static float[] shortToFloat(short[] a)
           
static float sumV(float[] a)
           
static void swap(int[] x, int a, int b)
           
static void synthesizeRamp(float[] realPart, float[] imaginaryPart)
          Destroy the input data with a linear ramp.
static void testAdd1()
           
static void testAdd1(float[] a)
          Show how loop unwinding can improve speed for a vector sum, but only to a point.
static void testAdd2()
           
static void testAddFloat()
           
static void testCoefficientOfVariation()
           
static void testCorrelate()
           
static void testGetOverlappedWindows()
           
static void testHanningOverlappedWindows()
           
static void testHanningOverlappedWindowsSpectrogram()
           
static void testOutlier()
           
static void testPadOutWithZeros()
           
static void testQuickSort()
           
static void testVariance()
           
static void threshold(short[] a)
           
static void threshold(short[] a, short thresh)
          For each element in a below the thresh, make the element 0, otherwise make the element 255.
static double variance(int[] a)
           
static double variance(short[][] a)
           
static void window(double[] r, double[] w)
           
static void windowArray(double[] window, double[] r_d)
           
static void windowArrays(double[] window, double[] r_d, double[] i_d)
          This will apply the windows to each of the arrays.
static double y5(double y0, double y1, double u)
           
static double[] zeroPadCorrelate(double[] a, double[] b)
          Zero pads a non-cyclic cross correlation between the signal and the template.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mat1

public Mat1()
Method Detail

main

public static void main(java.lang.String[] args)

add

public static void add(double[] a,
                       double[] b,
                       double c)
Add a vector times a scalar to a vector. The first vector contains the sum.

Parameters:
a - the first vector
b - the second vector
c - the scalar multiplier

add

public static void add(double[] a,
                       double[] b)
Add two vectors. The first vector contains the sum. This is not optimized for altivec

Parameters:
a - the first vector a = a + b;
b - the second vector

add

public static void add(float[] a,
                       float[] b)
Add two vectors. The first vector contains the sum.

Parameters:
a - the first vector a = a + b;
b - the second vector

testAddFloat

public static void testAddFloat()

testAdd2

public static void testAdd2()

dot

public static double dot(double[] a,
                         double[] b)
Calculate the dot product of two vectors.

Parameters:
a - the first vector
b - the second vector
Returns:
the dot product

dot

public static double dot(double[] a)
Calculate the dot product of a vector with itself.

Parameters:
a - the vector
Returns:
the dot product

magnitude

public static double magnitude(double[] a)
Calculate the magnitude a vector.

Parameters:
a - the vector
Returns:
the magnitude

print

public static void print(int[] a)

print

public static void print(double[] a)

printStats

public static void printStats(java.lang.String title,
                              float[] a)

printStats

public static void printStats(float[] a)

print

public static void print(float[] a)

addFloat

public static float addFloat(float[] a)
Sums up the numbers into a float. This can result in round-off error, since the addition of multiple floats can result in a double.

Parameters:
a -
Returns:
float

add

public static double add(double[] a)

ramp

public static float[] ramp(float start,
                           float end,
                           int n)

testAdd1

public static void testAdd1()

testAdd1

public static void testAdd1(float[] a)
Show how loop unwinding can improve speed for a vector sum, but only to a point.


add

public static void add(float[] a,
                       float[] b,
                       float[] c)

add8

public static void add8(float[] a,
                        float[] b,
                        float[] c)

add4

public static float add4(float[] a)

add8

public static float add8(float[] a)

add8Depend

public static double add8Depend(float[] a)

add8NoDepend

public static double add8NoDepend(float[] a)

add16

public static double add16(float[] a)

add

public static double add(float[] a)

add

public static double add(short[] a)

sumV

public static float sumV(float[] a)

normalize

public static void normalize(double[] a)
Sum all the elements in an array, then divide by the total. for example a[]={1,0,10}, sum is 11, now divide by the total and the array is 1/11,0,10/11 and the array sums to one.

Parameters:
a -

normalize

public static float[] normalize(short[] a)

normalize

public static void normalize(float[] a)

getMean

public static double getMean(float[] a)
Compute the average.

Parameters:
a - array of numbers to be averaged
Returns:
the sum divided by the number of elements

getMean

public static double getMean(short[] a)
Compute the average.

Parameters:
a - array of shorts
Returns:
the sum divided by the number of elements

threshold

public static void threshold(short[] a,
                             short thresh)
For each element in a below the thresh, make the element 0, otherwise make the element 255.

Parameters:
a - an array whose values are altered.
thresh - a point that is used to floor or ceiling a

threshold

public static void threshold(short[] a)

scale

public static float[] scale(short[] a,
                            float k)

scale

public static void scale(double[] a,
                         double k)

scale

public static void scale(float[] a,
                         float k)

scale

public static void scale(float[] a,
                         double k)

shortToFloat

public static float[] shortToFloat(short[] a)

copyArray

public static short[] copyArray(short[] a)

variance

public static double variance(int[] a)

mean

public static double mean(int[] a)

coefficientOfVariation

public static double coefficientOfVariation(int[] a)

testVariance

public static void testVariance()

testCoefficientOfVariation

public static void testCoefficientOfVariation()

outlierHere

public static boolean outlierHere(int[] a)

testOutlier

public static void testOutlier()

quickSort

public static void quickSort(int[] a,
                             int lo0,
                             int hi0)

swap

public static void swap(int[] x,
                        int a,
                        int b)

quickSort

public static void quickSort(int[] a)

mean

public static double mean(short[][] a)

variance

public static double variance(short[][] a)

getMean

public static double[] getMean(double[] a,
                               double[] b,
                               double[] c)

copy

public static short[][] copy(short[][] r)

getMin

public static float getMin(float[] a)

getMin

public static short getMin(short[] a)

getMax

public static short getMax(short[] a)

getMax

public static float getMax(float[] a)

testQuickSort

public static void testQuickSort()

numberOfNonZeros

public static int numberOfNonZeros(short[][] k)

printMedian

public static void printMedian(short[][] k,
                               java.lang.String name)

arrayCopy

public static float[] arrayCopy(float[] in)

arrayCopy

public static double[] arrayCopy(double[] in)

getRampData

public static double[] getRampData(int n)
Generate an array of doubles that is n elements long and has numbers that range from 0 to n-1.

For example:
double x1[] = getRampData(N);>

Parameters:
n - a positive integer
Returns:
the ramp data.

getRampDataFloat

public static float[] getRampDataFloat(int n)

getMaxValue

public static double getMaxValue(double[] in)

print

public static void print(double[] v,
                         java.lang.String title)

window

public static void window(double[] r,
                          double[] w)

print

public static void print(java.lang.Object[] o)

synthesizeRamp

public static void synthesizeRamp(float[] realPart,
                                  float[] imaginaryPart)
Destroy the input data with a linear ramp.

Parameters:
realPart - input datas real component
imaginaryPart - input datas' imaginary component.

getMean

public static double getMean(double[] values)
Computes the mean value for the argument array. Adds all values and divides them by the number of array elements.

Parameters:
values - double array on which the mean is to be determined
Returns:
computed mean value
Throws:
java.lang.IllegalArgumentException - if the array has not affineTransform least one element

getMean

public static double getMean(double[] values,
                             int offset,
                             int number)
Computes the mean value for some elements of the argument array. Adds all values and divides them by the number of array elements.

Parameters:
values - array from which elements are read
offset - index of the first element to be used
number - number of elements to be used
Returns:
computed mean value
Throws:
java.lang.IllegalArgumentException - if the array has not affineTransform least one element

getStandardDeviation

public static double getStandardDeviation(double[] values)
Computes the standard deviation for the argument array of values.

Parameters:
values - array from which elements are read
Returns:
computed standard deviation
Throws:
java.lang.IllegalArgumentException - if the array has not affineTransform least two elements

getStandardDeviation

public static double getStandardDeviation(double[] values,
                                          double mean)
Computes the standard deviation for the argument array of values. Reuses the mean value for that argument which must have been computed before.

Parameters:
values - array from which elements are read
mean - the mean value for the array, possibly computed with a call to getMean(double[]).
Returns:
computed standard deviation
Throws:
java.lang.IllegalArgumentException - if the array has not affineTransform least two elements

getStandardDeviation

public static double getStandardDeviation(double[] values,
                                          int offset,
                                          int number)
Computes the standard deviation for some of the argument array's values. If you already have computed a mean value using getMean(double[],int,int), better call getStandardDeviation(double[],int,int,double). Otherwise, this method has to compute mean again.

Parameters:
values - array from which elements are read
offset - first element to be used
number - number of elements used starting affineTransform values[offset]
Returns:
computed standard deviation
Throws:
java.lang.IllegalArgumentException - if the array has not affineTransform least two elements

getStandardDeviation

public static double getStandardDeviation(double[] values,
                                          int offset,
                                          int number,
                                          double mean)
Computes the standard deviation for some of the argument array's values. Use this version of the method if you already have a mean value, otherwise this method must be computed again.

Parameters:
values - array from which elements are read
offset - first element to be used
number - number of elements used starting affineTransform values[offset]
mean - value of the elements
Returns:
computed standard deviation
Throws:
java.lang.IllegalArgumentException - if the array has not affineTransform least two elements

getVariance

public static double getVariance(double[] values)
Computes the variance for the argument array.

Parameters:
values - array from which elements are read
Returns:
variance for the array elements
Throws:
java.lang.IllegalArgumentException - if the array has not affineTransform least two elements

getVariance

public static double getVariance(double[] values,
                                 double mean)
Computes the variance for some of the argument array's values.

Parameters:
values - array from which elements are read
mean - the mean for the array elements
Returns:
variance for the array elements
Throws:
java.lang.IllegalArgumentException - if the array has not affineTransform least two elements

getVariance

public static double getVariance(double[] values,
                                 int offset,
                                 int number)
Computes the variance for some of the argument array's values. If you already have computed a mean value using getMean(double[],int,int), better call getVariance(double[],int,int,double). Otherwise, this method has to compute mean again.

Parameters:
values - array from which elements are read
offset - first element to be used
number - number of elements used starting affineTransform values[offset]
Returns:
computed variance
Throws:
java.lang.IllegalArgumentException - if the array has not affineTransform least two elements

getVariance

public static double getVariance(double[] values,
                                 int offset,
                                 int number,
                                 double mean)
Computes the variance for some of the argument array's values. Use this version of the method in case mean has already been computed.

Parameters:
values - array from which elements are read
offset - first element to be used
number - number of elements used starting affineTransform values[offset]
mean - the mean for the array elements
Returns:
computed variance
Throws:
java.lang.IllegalArgumentException - if the array has not affineTransform least two elements

removeTheDcComponent

public static void removeTheDcComponent(float[] m)

scaleIntoRange

public static void scaleIntoRange(float[] im,
                                  float min,
                                  float max,
                                  int maxValueOutput)

getMean

public static double getMean(int[] a)

getVariance

public static double getVariance(int[] a)

intQuickSort

public static void intQuickSort(int[] a)

testCorrelate

public static void testCorrelate()

zeroPadCorrelate

public static double[] zeroPadCorrelate(double[] a,
                                        double[] b)
Zero pads a non-cyclic cross correlation between the signal and the template.

Parameters:
a - vector signal for the cross correlation
b - template vector for the cross correlation
Returns:
non-normalized cross correlation

testPadOutWithZeros

public static void testPadOutWithZeros()

padOutWithZeros

public static double[] padOutWithZeros(double[] b,
                                       int length)
This method will pad out a new array of length length and return it.

Parameters:
b - prepended to the output array
length - of the new array
Returns:
new array with b at the beginning and zeros on the tail.

dot

public static double dot(double[] a,
                         double[] b,
                         int j)
Calculate the dot product of two vectors. //todo better document this better.

Parameters:
a - the first vector
b - the second vector
Returns:
the dot product

makeHanning

public static double[] makeHanning(int n)

makeLyon

public static double[] makeLyon(int n)

logArray

public static void logArray(double[] a)

testHanningOverlappedWindowsSpectrogram

public static void testHanningOverlappedWindowsSpectrogram()

testHanningOverlappedWindows

public static void testHanningOverlappedWindows()

testGetOverlappedWindows

public static void testGetOverlappedWindows()

makeHanning

public static void makeHanning()

getOverlappedWindows

public static java.util.Vector getOverlappedWindows(double[] data)
return a vector of arrays, each array is only 256 elements long, each array overlaps by 50% with each other array. This is done before windowing is performed

Parameters:
data -
Returns:
The Vector of double arrays of data

windowArray

public static void windowArray(double[] window,
                               double[] r_d)

y5

public static double y5(double y0,
                        double y1,
                        double u)

windowArrays

public static void windowArrays(double[] window,
                                double[] r_d,
                                double[] i_d)
This will apply the windows to each of the arrays. The length of all the arrays must be the same.

Parameters:
window -
r_d -
i_d -

makeLyon

public static void makeLyon()

makeBartlett

public static double[] makeBartlett(int n)