-
-
Notifications
You must be signed in to change notification settings - Fork 43
Utilities
int start = 2;
int stop = 3;
int samples = 5;
boolean includeEnd = true;
double[] out1 = UtilMethods.linspace(start, stop, samples, includeEnd);
int start = 2;
int stop = 3;
int samples = 5;
int repeats = 2;
double[] out = UtilMethods.linspace(start, stop, samples, repeats);
double start = 3.0; //Can be int
double stop = 9.0; //Can be int
double step = 0.5; //Can be int
double[] out = UtilMethods.arange(start, stop, step);
double[] a = {1.22, -3.41, -0.22, 5.44, -9.28};
double[] out = UtilMethods.absoluteArray(a);
double[][] matrix = {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0}};
double[] out = UtilMethods.flattenMatrix(matrix);
double[] arr = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0}; //Can be int[]
double[] out = UtilMethods.reverse(arr);
double[] arr1 = {1.0, 2.0}; //Can be int[]
double[] arr2 = {3.0, 4.0, 5.0, 6.0}; //Can be int[]
double[] out = UtilMethods.concatenateArray(arr1, arr2);
double[] signal = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0}; //Can be int[]
int start = 2;
int stop = 4;
double[] out = UtilMethods.splitByIndex(signal, start, stop);
double[][] matrix = {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0}};
double[][] out = UtilMethods.pseudoInverse(matrix);
double[][] m1 = {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0}};
double[][] m2 = {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0}};
double[][] out = UtilMethods.matrixMultiply(m1, m2);
double[][] matrix = {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0}};
double[][] out = UtilMethods.transpose(matrix);
double[][] m1 = {{1.22, -3.41, -0.22}, {-0.89, 1.6, 7.65}};
double[][] out = UtilMethods.absoluteArray(m1);
Works in 5 modes:
- Reflect
- Constant
- Nearest
- Mirror
- Wrap
double[] signal = {2, 8, 0, 4, 1, 9, 9, 0};
double[] reflect = UtilMethods.padSignal(signal, "reflect");
double[] constant = UtilMethods.padSignal(signal, "constant");
double[] nearest = UtilMethods.padSignal(signal, "nearest");
double[] mirror = UtilMethods.padSignal(signal, "mirror");
double[] wrap = UtilMethods.padSignal(signal, "wrap");
Calculates the deltas between elements in an array.
double[] seq = {1, 2, 3, 4, 6, -4};
double[] out = UtilMethods.diff(seq);
(by changing deltas between values to 2*pi complement)
double[] seq = {0.0 , 0.78539816, 1.57079633, 5.49778714, 6.28318531};
double[] out = UtilMethods.unwrap(seq);
Helps in rounding a number to nth decimal place.
double val = 123.45667;
double out = UtilMethods.round(val, 1);
double divisor = -2;
double dividend = 4;
double out = UtilMethods.modulo(divisor, dividend);
Scales the input array between the new limits provided in the arguments
double[] arr1 = {12, 14, 15, 15, 16};
double[] out1 = UtilMethods.rescale(arr1, 10, 20);
Standardizes the input array between the range 0 and 1
double[] arr1 = {12, 14, 15, 15, 16};
double[] out1 = UtilMethods.standardize(arr1);
Normalizes the input array with the mean and standard deviation
double[] arr1 = {12, 14, 15, 15, 16};
double[] out1 = UtilMethods.normalize(arr1);
Zero-Centres the input array
double[] arr1 = {12, 14, 15, 15, 16};
double[] out1 = UtilMethods.zeroCenter(arr1);
Check if 2 double[] arrays are almost equals
double[] test1 = {1.23320, 1.23321};
double[] test2 = {1.23310, 1.23320};
boolean test = UtilMethods.almostEquals(test1[0], test1[1], 0.0001);
Converts ArrayList in or to double[] or int[] respectively
ArrayList<Integer> integers = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5));
ArrayList<Double> numbers = new ArrayList<Double>(Arrays.asList(1.1, 2.22, 3.3, 4.4, 5.55));
int[] out1 = UtilMethods.convertToPrimitiveInt(integers);
double[] out2 = UtilMethods.convertToPrimitiveDouble(numbers);
Provides functions like argmin(), argmax() and argsort().
double[] arr = {1, 2, 5, 3, 4, 6, 1, 6};
int min1 = UtilMethods.argmin(arr, false); //Returns the last occurrence index if more than 1 min value
int min2 = UtilMethods.argmin(arr, true); //Returns the first occurrence index if more than 1 min value
int max1 = UtilMethods.argmax(arr, false); //Returns the last occurrence index if more than 1 max value
int max2 = UtilMethods.argmax(arr, true); //Returns the first occurrence index if more than 1 max value
double[] test1 = {1.23, 4.55, -1.33, 2.45, 6.78, 1.29};
int[] sortedIndices = UtilMethods.argsort(test1, true);
Allows scalar operations of a single value to an array
double[] signal = {1.23, 6.54, 4.56, 9.04, 2.88};
double[] addArr = UtilMethods.scalarArithmetic(signal, 1.02, "add");
double[] subArr = UtilMethods.scalarArithmetic(signal, 1.02, "sub");
double[] mulArr = UtilMethods.scalarArithmetic(signal, 1.02, "mul");
double[] divArr = UtilMethods.scalarArithmetic(signal, 1.02, "div");
Allows trigonometric operations on an array element-wise
double[] arr1 = {1.23, 6.54, 4.56, 9.04, 2.88};
double[] sinArr = UtilMethods.trigonometricArithmetic(arr1, "sin");
double[] cosArr = UtilMethods.trigonometricArithmetic(arr1, "cos");
double[] tanArr = UtilMethods.trigonometricArithmetic(arr1, "tan");
double[] arr2 = {-0.92, -0.38, 0.25, 0.55, 0.98};
double[] asinArr = UtilMethods.trigonometricArithmetic(arr2, "asin");
double[] acosArr = UtilMethods.trigonometricArithmetic(arr2, "acos");
double[] atanArr = UtilMethods.trigonometricArithmetic(arr2, "atan");
Returns an electrocardiogram as an example for a 1-D signal.
double[] data = UtilMethods.electrocardiogram();
Computes the log and antilog of a value using the base.
int base = 2;
int input_val = 256;
double out = UtilMethods.log(input_val, base);
int base = 10;
int input_val = 122.0;
double out = UtilMethods.log(input_val, base);
These functions are used to construct a Toeplitz and Hankel matrix from the input vector. For Hankel, the last row can also be defined.
double[] c = {1,2,3,4};
double[][] output = UtilMethods.toeplitz(c);
double[] c = {1, 2, 3, 4};
double[] r = {4, 7, 7, 8, 9};
double[][] output = UtilMethods.hankel(c, r);
Computes the normalised sinc function for the input value.
double x_num = 0.23;
double out_num = UtilMethods.sinc(x_num);
double[] x_arr = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
double[] out_arr = UtilMethods.sinc(x_arr);
Evaluate a Chebyshev series at point(s) x
double[] arr = {1000.0, 2.0, 3.4, 17.0, 50.0};
double x_val = 2.0;
double out_val = UtilMethods.chebyEval(x_val, arr);
double[] x_arr = {1.0, 2.0, 3.0, 4.0, 5.0};
double[] out_arr = UtilMethods.chebyEval(x_arr, arr);
These set of function allows operating on a RealMatrix at the element level. The operations are: multiplication, addition, subtraction and division. It operates in 3 modes: EBE (element-by-element) in which both matrices must have the same shape, Row-wise in which both matrices must have same number of columns and, Column-wise in which both matrices must have the same number of rows.
double[][] m1 = {{1.0, 2.0}, {2.0, 0.5}, {3.0, 4.0}};
double[][] m2 = {{1.0, 2.0}, {2.0, 0.5}, {3.0, 4.0}};
RealMatrix out = UtilMethods.ebeMultiply(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2));
double[][] m2_row = {{0.5, 1.0}};
RealMatrix out_row = UtilMethods.ebeMultiply(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2_row), "row");
double[][] m2_col = {{0.5}, {1.0}, {2.0}};
RealMatrix out_col = UtilMethods.ebeMultiply(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2_col), "column");
double[][] m1 = {{1.0, 2.0}, {2.0, 0.5}, {3.0, 4.0}};
double[][] m2 = {{1.0, 2.0}, {2.0, 0.5}, {3.0, 4.0}};
RealMatrix out = UtilMethods.ebeAdd(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2));
double[][] m2_row = {{0.5, 1.0}};
RealMatrix out_row = UtilMethods.ebeAdd(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2_row), "row");
double[][] m2_col = {{0.5}, {1.0}, {2.0}};
RealMatrix out_col = UtilMethods.ebeAdd(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2_col), "column");
double[][] m1 = {{1.0, 2.0}, {2.0, 0.5}, {3.0, 4.0}};
double[][] m2 = {{1.0, 2.0}, {2.0, 0.5}, {3.0, 4.0}};
RealMatrix out = UtilMethods.ebeSubtract(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2));
double[][] m2_row = {{0.5, 1.0}};
RealMatrix out_row = UtilMethods.ebeSubtract(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2_row), "row");
double[][] m2_col = {{0.5}, {1.0}, {2.0}};
RealMatrix out_col = UtilMethods.ebeSubtract(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2_col), "column");
double[][] m1 = {{1.0, 2.0}, {2.0, 0.5}, {3.0, 4.0}};
double[][] m2 = {{1.0, 2.0}, {2.0, 0.5}, {3.0, 4.0}};
RealMatrix out = UtilMethods.ebeDivide(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2));
double[][] m2_row = {{0.5, 1.0}};
RealMatrix out_row = UtilMethods.ebeDivide(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2_row), "row");
double[][] m2_col = {{0.5}, {1.0}, {2.0}};
RealMatrix out_col = UtilMethods.ebeDivide(MatrixUtils.createRealMatrix(m1), MatrixUtils.createRealMatrix(m2_col), "column");
Wiki
-
Filters
- IIR Filters
- FIR Filters
- Kernel-Based Filter
- Adaptive Filters
-
Signals
-
Peak Detection
-
Transformations
-
Speech
-
Windowing