https://en.wikipedia.org/wiki/Haar_wavelet

https://pbs.twimg.com/media/DS7mmaLWAAE6-US.jpg

   Haar=: _2&(-/\ , Haar^:(1<#)@(+/\))
   Haar 3 2 3 2 2 2 1 1
1 1 0 0 0 2 4 16

Like the fast fourier transform, this is only defined on arguments
whose length is a power of 2 (which might be enforced by requiring an
array whose dimensions are all 2 and then raveling it).

Unlike the FFT, however, the Haar transform is not self inverting.
Still, since every non-lossey transform deserves an inverse transform:

   iHaar=: -:@(+/,@,.-~/)@(,:$:^:(1<#))/@($~ 2,-:@#)
   iHaar 1 1 0 0 0 2 4 16
3 2 3 2 2 2 1 1

As an aside, though: I found the wikipedia article nearly useless for
this implementation - I used the example contained in the image to
write this code and only briefly skimmed the wikipedia text for rough
agreement. (And since I've encountered plenty of errors in wikipedia
in the past, that's all I'm inclined to do with that page at the
moment.) Still, if someone with more familiarity with wavelets than I
could tell me if I've screwed up royally (and, if so, how and where),
please let me know.

Thanks,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to