001: package JSci.maths.wavelet.daubechies2;
002:
003: import JSci.maths.wavelet.*;
004: import JSci.maths.*;
005:
006: /******************************************
007: * Daubechies wavelets adapted to the
008: * interval by Meyer. Thanks to Pierre Vial
009: * for the filters.
010: * @author Daniel Lemire
011: *****************************************/
012: public final class Daubechies2 extends Multiresolution implements
013: Filter, NumericalConstants {
014: protected final static int filtretype = 2;
015: protected final static int minlength = 4;
016:
017: /****************************************
018: * This method is used to compute
019: * how the number of scaling functions
020: * changes from on scale to the other.
021: * Basically, if you have k scaling
022: * function and a Filter of type t, you'll
023: * have 2*k+t scaling functions at the
024: * next scale (dyadic case).
025: * Notice that this method assumes
026: * that one is working with the dyadic
027: * grid while the method "previousDimension"
028: * define in the interface "Filter" doesn't.
029: ******************************************/
030: public int getFilterType() {
031: return (filtretype);
032: }
033:
034: public MultiscaleFunction primaryScaling(int n0, int k) {
035: return (new Scaling2(n0, k));
036: }
037:
038: public MultiscaleFunction dualScaling(int n0, int k) {
039: return (new Scaling2(n0, k));
040: }
041:
042: public MultiscaleFunction primaryWavelet(int n0, int k) {
043: return (new Wavelet2(n0, k));
044: }
045:
046: public MultiscaleFunction dualWavelet(int n0, int k) {
047: return (new Wavelet2(n0, k));
048: }
049:
050: final static double[] vgtemp = { 0.482962913145, 0.836516303738,
051: 0.224143868042, -0.129409522551 };
052: final static double[] v0temp = { 0.848528137424, -0.529150262213 };
053: final static double[] v1temp = { 0.132287565553, 0.212132034356,
054: 0.838525491562, -0.484122918276 };
055:
056: final static double[] vd0temp = { 0.848528137424, 0.529150262213 };
057:
058: final static double[] vd1temp = { -0.132287565553, 0.212132034356,
059: 0.838525491562, 0.484122918276 };
060:
061: final static double[] vg = ArrayMath.scalarMultiply(SQRT2, vgtemp);
062: final static double[] vd0 = ArrayMath.scalarMultiply(SQRT2,
063: ArrayMath.invert(vd0temp));
064: final static double[] vd1 = ArrayMath.scalarMultiply(SQRT2,
065: ArrayMath.invert(vd1temp));
066: final static double[] v0 = ArrayMath.scalarMultiply(SQRT2, v0temp);
067: final static double[] v1 = ArrayMath.scalarMultiply(SQRT2, v1temp);
068:
069: /********************************************
070: * On définit ici le filtre comme tel par le
071: * vecteur phvg (filtre passe-haut).
072: *********************************************/
073: final static double[] phvg = WaveletMath.lowToHigh(vgtemp);
074: final static double[] phv0 = { -0.512347538298, -0.821583836258,
075: 0.216506350947, -0.125 };
076:
077: final static double[] phvd0temp = { 0.512347538298,
078: -0.821583836258, 0.216506350946, 0.125 };
079: final static double[] phvd0 = ArrayMath.invert(phvd0temp);
080:
081: /****************************************
082: * This method return the number of "scaling"
083: * functions at the previous scale given a
084: * number of scaling functions. The answer
085: * is always smaller than the provided value
086: * (about half since this is a dyadic
087: * implementation). This relates to the same idea
088: * as the "Filter type". It is used by
089: * the interface "Filter".
090: *****************************************/
091: public int previousDimension(int k) {
092: return (Cascades.previousDimension(filtretype, k));
093: }
094:
095: public Daubechies2() {
096: }
097:
098: /****************************************
099: * This is the implementation of the lowpass
100: * Filter. It is used by the interface
101: * "Filter". Lowpass filters are normalized
102: * so that they preserve constants away from
103: * the boundaries.
104: *****************************************/
105: public double[] lowpass(double[] v, double[] param) {
106: return (lowpass(v));
107: }
108:
109: /****************************************
110: * This is the implementation of the highpass
111: * Filter. It is used by the interface
112: * "Filter". Highpass filters are normalized
113: * in order to get L2 orthonormality of the
114: * resulting wavelets (when it applies).
115: * See the class DiscreteHilbertSpace for
116: * an implementation of the L2 integration.
117: *****************************************/
118: public double[] highpass(double[] v, double[] param) {
119: return (highpass(v));
120: }
121:
122: /****************************************
123: * This is the implementation of the lowpass
124: * Filter. It is used by the interface
125: * "Filter". Lowpass filters are normalized
126: * so that they preserve constants away from
127: * the boundaries.
128: *****************************************/
129: public double[] lowpass(double[] gete) {
130: if (gete.length < minlength) {
131: throw new IllegalScalingException(
132: "The array is not long enough: " + gete.length
133: + " < " + minlength);
134: }
135: double[] sortie = new double[2 * gete.length - 2];
136: int dl0 = gete.length - 1;
137: for (int k = 2; k <= dl0 - 2; k++) {
138: for (int L = -2; L < 2; L++) {
139: sortie[2 * k + L] += vg[L + 2] * gete[k];
140: }
141: }
142: sortie = ArrayMath.add(sortie, gete[0], v0, 0);
143: sortie = ArrayMath.add(sortie, gete[1], v1, 0);
144: int p0 = sortie.length - vd0.length;
145: int p1 = sortie.length - vd1.length;
146: sortie = ArrayMath.add(sortie, gete[dl0], vd0, p0);
147: sortie = ArrayMath.add(sortie, gete[dl0 - 1], vd1, p1);
148: return (sortie);
149: }
150:
151: /****************************************
152: * This is the implementation of the highpass
153: * Filter. It is used by the interface
154: * "Filter". Highpass filters are normalized
155: * in order to get L2 orthonormality of the
156: * resulting wavelets (when it applies).
157: * See the class DiscreteHilbertSpace for
158: * an implementation of the L2 integration.
159: *****************************************/
160: public double[] highpass(double[] gete) {
161: double[] sortie = new double[2 * gete.length + 2];
162: int dl0 = gete.length - 1;
163: for (int k = 1; k <= dl0 - 1; k++) {
164: for (int L = -2; L < 2; L++) {
165: sortie[2 * k + L + 2] += phvg[L + 2] * gete[k];
166: }
167: }
168: sortie = ArrayMath.add(sortie, gete[0], phv0, 0);
169: int p0 = sortie.length - phvd0.length;
170: sortie = ArrayMath.add(sortie, gete[dl0], phvd0, p0);
171: return (sortie);
172: }
173:
174: public double[] evalScaling(int n0, int k, int j1) {
175: return (Cascades.evalScaling(this , n0, j1, k));
176: }
177:
178: public double[] evalWavelet(int n0, int k, int j1) {
179: return (Cascades.evalWavelet(this , filtretype, n0, j1, k));
180: //return(Cascades.evalWavelet(this,n0,j1,k));
181: }
182:
183: }
|