Giter Club home page Giter Club logo

graetz23 / jwave Goto Github PK

View Code? Open in Web Editor NEW
211.0 21.0 74.0 1.77 MB

A Discrete Fourier Transform (DFT), a Fast Wavelet Transform (FWT), and a Wavelet Packet Transform (WPT) algorithm in 1-D, 2-D, and 3-D using normalized orthogonal (orthonormal) Haar, Coiflet, Daubechie, Legendre and normalized biorthognal wavelets in Java.

Home Page: http://en.wikipedia.org/wiki/Wavelet

License: Other

Java 100.00%
wavelet wavelet-transform wavelet-transform-algorithm wavelet-decomposition wavelet-compression wavelet-packets wavelet-analysis wavelet-toolbox wavelet-tree orthogonal

jwave's People

Contributors

cscheiblich avatar dmcreyno avatar graetz23 avatar hbs avatar raineforest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jwave's Issues

question on example.

Hi, I saw an example on the wikipage. I'm wondering why the variable "arrHilb" is 1-dimensional. To my understanding, wavelet coefficients include both scale and translation, so that arrHilb must be 2-dimensional. Am I missing anything here? Thanks.

Transform t = new Transform( new WaveletPacketTransform( new Haar02( ) ) );

double[ ] arrTime = { 1., 1., 1., 1., 1., 1., 1., 1. };

double[ ] arrHilb = t.forward( arrTime ); // 1-D WPT Haar forward

Different with Matlab?

Dear Christian,

I am trying to use this library, and it gives me results. Basically, this is what my code do:

  1. load an image (I use the "woman" image in matlab).
  2. get the pixel values
  3. call forward method (FWT with Haar / Sym8)
    transform.forward(pixels, 1, 1) //apparently, dwt2 in Matlab only apply 1 level FWT)
  4. normalized the result to 0-255
  5. print the image

However, I also tried to use dwt in Matlab and it gives me a different result, most notably are:

  1. For each additional vanishing moment N, the result has more dimension (image size + N - 1)
  2. Image attached for both result in Matlab and Java
    matlabhaar
    normhaar
    matlabsym8
    normsym8

Additionally, I try to compare both library with 4x4 all-ones matrix using Haar Wavelet (again by calling forward(matrix, 1, 1)). The coefficients are basically the same with different signs in upper right and lower left elements.
Here is an example of the result:
-Matlab (I crop it to 4x4 from 18x18)
2 2 -2.97996696763114e-12 -2.97996696763114e-12
2 2 -2.97996696763114e-12 -2.97996696763114e-12
-2.97995268873730e-12 -2.97995268873730e-12 4.44003260755500e-24 4.44003260755500e-24
-2.97995268873730e-12 -2.97995268873730e-12 4.44003260755500e-24 4.44003260755500e-24

-Java
2.0 2.0 2.9799526887373042E-12 2.9799526887373042E-12
2.0 2.0 2.9799526887373042E-12 2.9799526887373042E-12
2.9799669676311424E-12 2.9799669676311424E-12 4.440032607554995E-24 4.440032607554995E-24
2.9799669676311424E-12 2.9799669676311424E-12 4.440032607554995E-24 4.440032607554995E-24

What exactly is happening here? Is there something I do wrong?

decompose() then recompose() giving incorrect results

From the documentation and the examples, I thought that putting a timeseries through a decompose operation, then putting the resulting matrix through a recompose operation, would give me back the original data (modulo some rounding error potentially).

However, the results I'm getting look completely wrong, even when using a very simple wavelet like Haar1 :-(

Have a look at this test and the output below it:

https://gist.github.com/andrewclegg/9e937b284a91a42f95ae

The result I'm getting back actually looks like the Haar wavelet itself (two constant values). That might be a red herring though...

Any idea what I'm doing wrong?

Cannot build

Buildfile: //JWave/build.xml

clean:
[delete] Deleting directory //JWave/build

doMac:

doWin:

doUnix:
[echo] OS is a Unix target
[echo] JUnit path: /JWave/lib/junit4.jar

init:
[mkdir] Created dir: //JWave/build
[echo] OS Name is: Linux
[echo] OS Arch. is: amd64
[echo] OS Vers. is: 6.1.12-x64v1-xanmod1
[echo] JUnit path: //JWave/lib/junit4.jar
[echo] hamcrest path: //JWave/lib/hamcrest-all.jar

compile:
[javac] Compiling 104 source files to //JWave/build
[javac] error: error reading /JWave/lib/junit4.jar; zip END header not found

BUILD FAILED
//JWave/build.xml:99: Compile failed; see the compiler error output for details.

Total time: 0 seconds

Question: Structure of the coefficients in the array returned from the forward transform

Hi,

I’m looking to implement the image fusion algorithm, which requires combining the coefficients of the wavelet transform of two images, then calculating the inverse one the combination.

The combining operation requires treating the “approximation” and “detail” coefficients differently. However, it wasn’t obvious to me how to determine what sections of the result for the forward transform correspond to the approximation and detail coefficients.

@graetz23 Can you provide some guidance on the layout? Once I understand this I’d be happy to submit a PR so that others don’t have the same trouble I’ve had.

reverse and forward functions

Hello,

I tried to test the forward and reverse functions, but I am not getting the original signal.

Transform t = new Transform( new FastWaveletTransform( new Haar02( ) ),10 );
double[ ] output =t.reverse(t.forward( buffer )) ;

I tried to make the array of length 2^n (32768), but still not getting the original signal.

Am I doing something wrong? or the problem still exists?

I attached the output. Blue is the original signal, red is what I get.

Thanks in advance for your cooperation.

Symlet

Hi,

I used Haar function before, and I was able to specify the number of steps. Now, I am using symlet, but I am not able to do the same.
May you please provide an example showing how to specify the steps for this function?

Thanks in advance for your help.

Regards,
Mamoun

Discrete Wavelet Transform

Hi, this library is super useful. I'm wondering whether you can add Discrete Wavelet Transform to it. Thanks.

Consider moving to Maven project layout?

Hi,

Would you consider moving this project to Maven, and publishing the jar on Maven Central? It would be really useful for people who want to use it in other projects.

Moving to the Maven directory layout is really simple:

andrewclegg@8cb33ed

(EDIT: sorry, prematurely submitted by accident)

I think publishing it on Maven Central is pretty straightforward too -- I haven't done so because I'm not the project maintainer, so it might cause confusion. In the pom.xml I wrote for my fork (see above) I just published it in a personal repo instead. That would be another option for you too.

Use of arbitrary length input array to Daubechies 4 FWT

Very good implementation of Wavelet Transforms, just what I required for my OU project here in the UK.

However, I have a problem implementing a Fast Wavelet Transform on an arbitrary length array of data (as per your examples).

It appears I am invoking the parent forward method rather than the overriden one in the AncientEgyptianDecomposition class.

My Java is:

       double[] arrFwd = null;
        //instance of Daubechies D4 DWT
        d4Transform = new Transform(
                        new AncientEgyptianDecomposition(
                            new FastWaveletTransform(
                                new Daubechies4())));

       double[] frame = new double [1280];

        //code to populate frame array

        // should use overriden forward method from AncientEgyptianDecomposition class
        arrFwd = d4Transform.forward(frame);

Could this be because AncientEgyptianDecomposition extends BasicTransform and not Transform?

Any help would be appreciated.

Regards,

Kevin

continuous wavelet transforms

Hey, looking through the function signatures, it looks like decompose maybe runs a CWT:

public double[][] decompose(double[] arrTime) { ... }

is this true? If not, do you have any plans on supporting CWTs in the future?

Amazing robust code, wish I understood this scientific domain more so I didn't have to ask such a potentially stupid question.

Example Usage doesn't work

Hi,

I'm trying to use your library and startetd with example "Example for 1-D, 2-D FWT" where you use a Haar02 Wavelet.

When I copy the code as described, the Wavelet Haar02 doesn't exist. So I tried with Haar1, which gave me no problems.
Also I had to surround 4 lines with try/catch block which throws JWaveExceptions.

So here are my questions:
Is Haar1 the same as Haar02 Wavelet?
Why do I need the try/catch blocks?

thanks for your help
Alex

Arbitrary length wavelet coefficients order

Hello,

I have tried to understand the working of Ancient Egyptian Decomposition transform for wavelet transforms, but when trying to address the coefficients corresponding to a particular frequency band I am having difficulty in finding a pattern.

When we have a wavelet transform, it divides the coefficients in each level by 2 from the Low frequency (Approximate coefficients) copying detailed coefficients as it is in next level
Here it is easy to find a pattern as we know every time the approximate coefficients were divided in index by 2

But what would be the case when we are working with arbitrary length signals?

`

Wavelet demy =  WaveletBuilder.create( "Discrete Mayer" );
Transform fwt = new Transform(new AncientEgyptianDecomposition ( new FastWaveletTransform( demy ) ) );

int level_decomposed = 4;
double [] arrTime = getTimeSeriesData(); // returns an array of arbitrary length every time @30Hz

// These values for de-noising the signal only works for 2^p length signals
// Denoising to 0 - 3.75Hz 
int dcValuesP = pulse.length / (int) Math.pow(2.0, (double) level_decomposed);
int value_denoise = dcValuesP * 2;

double [] arrHilb = fwt.forward(arrTime);

for (int dp = value_denoise; dp < arrHilb.length; dp++) {
    arrHilb[dp] = 0.0D;
}

for (int i = 0; i < dcValuesP; i++) {
    arrHilb[i] = 0.0D;
}

double [] arrReco = fwt.reverse(arrHilb);
`

Could you help me in finding the pattern which would help me achieve similar denoising effect (0-30Hz to 0-3.75Hz using dmey wavelet) for arbitrary length time series data?

PS. I was working the same in Matlab there we get an array of index book keeping for a particular range of coefficients, if there is something similar to it, that would be great!

Flipped signs in all high pass filter coefficients, error in _buildOrthonormalSpace

Hi!

I found an issue with jwave's wavelet decomposed coefficients having sign differences in detail coefficients when compared with
pywavelet coefficients.

So, I digged through your code, and figured that you are using pywavelets mother wavelet decomposition function as low pass filter coefficients from this page (http://wavelets.pybytes.com/wavelet/db10/) and building the rest using _buildOrthonormalSpace here
(https://github.com/cscheiblich/JWave/blob/master/src/jwave/transforms/wavelets/Wavelet.java#L104)

The high pass filter coefficients you have build using this function do not turn out to be the same as the high pass filter coefficients for the mother wavelet scaling function as given in pywavelets documentation (http://wavelets.pybytes.com/wavelet/db10/)

Here is a demonstration of error in coefficients output from Daubechies10 as compared to python

Python

In [16]: arr = np.zeros(4)

In [17]: arr[1] = 1

In [18]: coeffs = [0] * 3
...: for i in range(3):
...: arr, coeffs[i] = pywt.dwt(arr, "db10", "periodization")
...: print(arr, coeffs[i])
...:
...:
[ 0.30328632 0.40382046] [-0.14391341 0.85102019]
[ 0.5] [ 0.07108838]
[ 0.70710678] [ -5.07923307e-17]

// Java

/**

  • Performs a Forward FastWaveletTransform
  • @param mat
  • @return mat
    */
    public static double[][] forwardDaubechy(double[] mat) {
    Wavelet wavelet = new Daubechies10();
    Transform t = new Transform(new FastWaveletTransform(wavelet));
    double[][] forward = t.decompose(mat);
    return forward;
    }

level 0 [0.3032863181493727, 0.4038204630371676, 0.14391341375270209, -0.8510201949392565]
level 1 [0.49999999999999406, -0.07108837559095565, 0.14391341375270209, -0.8510201949392565]

Error in high pass filter coefficient

In [51]: _scalingDeCom = [-1.3264203002354869e-005, 9.3588670001089845e-005, -0.0001164668549943862, -0.00068585669500468248, 0.0019924052949908499, 0.00139535174699407
...: 98, -0.010733175482979604, 0.0036065535669883944, 0.033212674058933238, -0.029457536821945671, -0.071394147165860775, 0.093057364603806592, 0.12736934033574265
...: , -0.19594627437659665, -0.24984642432648865, 0.28117234366042648, 0.68845903945259213, 0.52720118893091983, 0.18817680007762133, 0.026670057900950818]
...: _motherWavelength = len(_scalingDeCom)
...: _waveletDeCom = [0] * _motherWavelength;
...: for i in range(0, _motherWavelength):
...: if( i % 2 == 0 ):
...: _waveletDeCom[ i ] = _scalingDeCom[ ( _motherWavelength - 1 ) - i ];
...: else:
...: _waveletDeCom[ i ] = -_scalingDeCom[ ( _motherWavelength - 1 ) - i ];
...:

In [52]: _waveletDeCom
Out[52]:
[0.026670057900950818,
-0.18817680007762133,
0.5272011889309198,
-0.6884590394525921,
0.2811723436604265,
0.24984642432648865,
-0.19594627437659665,
-0.12736934033574265,
0.09305736460380659,
0.07139414716586077,
-0.02945753682194567,
-0.03321267405893324,
0.0036065535669883944,
0.010733175482979604,
0.0013953517469940798,
-0.00199240529499085,
-0.0006858566950046825,
0.0001164668549943862,
9.358867000108985e-05,
1.326420300235487e-05]

expected = [-0.026670057900950818
0.18817680007762133
-0.5272011889309198
0.6884590394525921
-0.2811723436604265
-0.24984642432648865
0.19594627437659665
0.12736934033574265
-0.09305736460380659
-0.07139414716586077
0.02945753682194567
0.03321267405893324
-0.0036065535669883944
-0.010733175482979604
-0.0013953517469940798
0.00199240529499085
0.0006858566950046825
-0.0001164668549943862
-9.358867000108985e-05
-1.326420300235487e-05]

Hence the output detail coefficients are differing in signal, since you have used the same flipped high pass filter for building the rest of the coefficients for reconstruction, your inverse transform did not make any difference, but this is an error.

Fix - basically line 112 and 114 signs should be flipped in function _buildOrthonormalSpace, since the first coefficient in high pass filter should have a negative sign -(https://github.com/cscheiblich/JWave/blob/master/src/jwave/transforms/wavelets/Wavelet.java#L104)

protected void _buildOrthonormalSpace( ) {
// building wavelet as orthogonal (orthonormal) space from
// scaling coefficients (low pass filter). Have a look into
// Alfred Haar's wavelet or the Daubechies Wavelet with 2
// vanishing moments for understanding what is done here. ;-)
_waveletDeCom = new double[ _motherWavelength ];
for( int i = 0; i < _motherWavelength; i++ )
if( i % 2 == 0 )
_waveletDeCom[ i ] = -_scalingDeCom[ ( _motherWavelength - 1 ) - i ];
else
_waveletDeCom[ i ] = _scalingDeCom[ ( _motherWavelength - 1 ) - i ];
// Copy to reconstruction filters due to orthogonality (orthonormality)!
_scalingReCon = new double[ _motherWavelength ];
_waveletReCon = new double[ _motherWavelength ];
for( int i = 0; i < _motherWavelength; i++ ) {
_scalingReCon[ i ] = _scalingDeCom[ i ];
_waveletReCon[ i ] = _waveletDeCom[ i ];
} // i
} // _buildOrthonormalSpace

Maven repo

Hi! Could you add your library to the Central Maven repo, to make it available in the maven projects?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.