JSci.maths.EngineerMath Maven / Gradle / Ivy
package JSci.maths;
/**
* This class is dedicated to engineering methods applied to arrays including
* signal processing.
* All methods here are safe, that is, they create copies of arrays whenever
* necessary.
* This makes for slower methods, but the programmer can always
* define his own methods optimized for performance.
* @author Daniel Lemire
*/
public final class EngineerMath extends AbstractMath {
private EngineerMath() {}
/**
* Return a running average over the data.
* The returned array has the same size as the input array.
* It is often used in signal processing to estimate the baseline.
* @param v the data.
* @param width width of the average.
* @exception IllegalArgumentException if v.length < width
* @exception IllegalArgumentException if width is even
* @exception IllegalArgumentException if v.length = 0
*/
public static double[] runningAverage(double[] v, int width) {
if(v.length> 1;
double[] ans=new double[v.length];
ans[0]=ArrayMath.mean(ArrayMath.extract(0,width-1,v));
for(int k=1;k> 1;
double[] ans=new double[v.length];
ans[0]=ArrayMath.median(ArrayMath.extract(0,width-1,v));
for(int k=1;k