Java API By Example, From Geeks To Geeks.

# Java > Open Source Codes > JSci > maths > wavelet > DiscreteFunction

 `1 package JSci.maths.wavelet;2 3 import JSci.maths.*;4 import JSci.maths.vectors.AbstractDoubleVector;5 import JSci.maths.vectors.DoubleVector;6 import JSci.util.*;7 import java.util.Arrays ;8 9 /**********************************************10 * This class is used to be able to mix the wavelet11 * and other type of functions such as given signals.12 * @author Daniel Lemire13 *************************************************/14 public class DiscreteFunction extends MultiscaleFunction implements Cloneable {15         protected AbstractDoubleVector data;16 17         public DiscreteFunction(double[] v) {18         setData(v);19     }20     public void setData (double[] v) {21         data = new DoubleVector(v);22     }23   /*******************************24   * Return a String representation25   * of the object26   ********************************/27   public String toString() {28     return(data.toString());29   }30   /**********************31   * Makes the L2 norm of the32   * internal array equal to 1.33   ***********************/34   public final void normalize() {35     data = data.normalize();36   }37 38     /************************************************39   * Return as an array the sampled values40   * of the function41     *************************************************/42     public final double[] evaluate() {43         return(VectorToolkit.toArray(data));44     }45 46   /*****************************************47   * Check if another object is equal to this48   * DiscreteFunction object49   ******************************************/50   public final boolean equals(Object a) {51     if((a!=null) && (a instanceof DiscreteFunction)) {52       DiscreteFunction iv=(DiscreteFunction)a;53         return data.equals(iv.data);54     }55     return false;56   }57     /************************************************58   * Return as an array the sampled values59   * of the function60   * @param j number of iterations (doesn't do anything)61     *************************************************/62     public double[] evaluate (int j) {63         return(evaluate());64     }65   /******************************************66   * Compute the mass (integral)67   * @param a left boundary of the interval68   * @param b right boundary of the interval69   * @param jfin number of iterations to consider70   * (precision)71   **********************************************/72     public double mass(double a, double b, int jfin) {73                 return data.mass()/(data.dimension()-1)*Math.abs(b-a);74     }75     /***************************76   * Compute the L2 norm of the77   * signal78     ****************************/79   public final double norm () {80     return(data.norm());81   }82     /***************************83   * Compute the L2 norm of the84   * function85   * @param j number of iterations86     ****************************/87   public double norm (int j) {88     return(data.norm());89   }90   /********************************************91   * Return a copy of this object92   *********************************************/93     public Object clone() {94     DiscreteFunction df=(DiscreteFunction) super.clone();95     df.setData(VectorToolkit.toArray(data));96     return(df);97     }98   /*****************************************99   * Tells you how many samples you'll get100   * from this function (will not depend101   * on the parameter)102   ******************************************/103     public int dimension(int jfin) {104         return(data.dimension());105     }106   /*****************************************107   * Tells you how many samples you'll get108   * from this function109   ******************************************/110     public final int dimension() {111         return(data.dimension());112     }113     /****************************************114   * This method is used to compute115   * how the number of scaling functions116   * changes from on scale to the other.117   * Basically, if you have k scaling118   * function and a Filter of type t, you'll119   * have 2*k+t scaling functions at the120   * next scale (dyadic case).121   * Notice that this method assumes122   * that one is working with the dyadic123   * grid while the method "previousDimension"124   * define in the interface "Filter" doesn't.125     ******************************************/126     public int getFilterType () {127         return(data.dimension());128     }129 }130 131 ` Popular Tags