package jsci.maths.wavelet;

import jsci.maths.*;

/**********************************************
* This class is used to be able to mix the wavelet
* and cosine transforms. It is in fact a normalised
* cosine.
* @author Daniel Lemire
*************************************************/
public final class Cosine extends MultiscaleFunction implements NumericalConstants, Cloneable {
		private int n0; private int freq;private double normalisation;
		double tol=Double.MIN_VALUE;
  /*******************************
  * 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);
  }

  /*****************************************
  * Check if another object is equal to this
  * Cosine object
  ******************************************/
  public boolean equals(Object a) {
    if((a!=null) && (a instanceof Cosine))  {
      Cosine iv=(Cosine)a;
      return (this.dimension(0)==iv.dimension(0)) && (this.getFrequency()==iv.getFrequency());
    }
    return false;
  }

  public int getFrequency() {
    return(freq);
  }

		public Cosine (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);
			if((2*freq==n0)||(freq==0)) {
				normalisation*=SQRT2;
			}
		}
	/************************************************
  * Return as an array the sampled values
  * of the function
	*************************************************/
		public double[] evaluate() {
			return(ArrayMath.scalarMultiply(1/normalisation,evaluate(n0,freq)));
		}

	private static double[] evaluate(int N0,int FREQ) {
			double[] ans=new double[N0];
			for(int k=0;k 

Ads help maintain this website.