JSci.maths.wavelet.Sine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsci Show documentation
Show all versions of jsci Show documentation
JSci is a set of open source Java packages. The aim is to encapsulate scientific methods/principles in the most natural way possible. As such they should greatly aid the development of scientific based software.
It offers: abstract math interfaces, linear algebra (support for various matrix and vector types), statistics (including probability distributions), wavelets, newtonian mechanics, chart/graph components (AWT and Swing), MathML DOM implementation, ...
Note: some packages, like javax.comm, for the astro and instruments package aren't listed as dependencies (not available).
The newest version!
package JSci.maths.wavelet;
import JSci.maths.wavelet.*;
import JSci.maths.*;
/**********************************************
* This class is used to be able to mix the wavelet
* and sine transforms. It is in fact a normalised
* sine.
* @author Daniel Lemire
*************************************************/
public final class Sine extends MultiscaleFunction implements NumericalConstants, Cloneable {
private int n0; private int freq;private double normalisation;
/*******************************
* Return a String representation
* of the object
********************************/
public String toString() {
String ans=new String("[n0=");
ans.concat(Integer.toString(n0));
ans.concat("][freq=");
ans.concat(Integer.toString(freq));
ans.concat("]");
return(ans);
}
public Sine (int N0,int FREQ) {
if(N0<0) {
throw new IllegalArgumentException("The length paramenter "+N0+" must be positive");
}
if((FREQ<0)||(FREQ>=N0)) {
throw new IllegalArgumentException("The frequency parameter "+FREQ+" must be between "+0+" and "+(N0-1));
}
n0=N0;freq=FREQ;
normalisation=Math.sqrt(n0/2d);
}
/*****************************************
* Check if another object is equal to this
* Sine object
******************************************/
public boolean equals(Object a) {
if((a!=null) && (a instanceof Sine)) {
Sine iv=(Sine)a;
return (this.dimension(0)==iv.dimension(0)) && (this.getFrequency()==iv.getFrequency());
}
return false;
}
public int getFrequency() {
return(freq);
}
/************************************************
* Return as an array the sampled values
* of the function
*************************************************/
public double[] evaluate() {
return(ArrayMath.scalarMultiply(1.0/normalisation,evaluate(n0,freq)));
}
private static double[] evaluate(int N0,int FREQ) {
double[] ans=new double[N0];
for(int k=0;k