This page is available in English only

Haar DWT POC Lab

Haar wavelet decomposition (DWT) proof-of-concept lab

(5 Votes)
Blok Dak
0.0.4 (Updated 6 years ago)
483.0kB
May 05, 2016
Reaktor 6
Other Test Area

DESCRIPTION

For real-time stuff, check out the Fast Wavelet Transform project: http://www.native-instruments.com/en/reaktor-community/reaktor-user-library/entry/show/10025/

* check the bottom for edits/updates *

THIS IS ABSOLUTELY USELESS EXCEPT AS A DEMONSTRATION. Moreover, it is badly coded. However, if you would like to see an implementation of the Discrete Wavelet Transform using Haar wavelets in Reaktor, then this is the (only?) place to go - at least for now.

THIS IS A DEMONSTRATION ONLY. The ensemble is setup as a walk-through lab where each step demonstrates a step of the decomposition/graphing/recomposition process. It is not designed to be used with other instruments/macros/ensembles/whatever. Its sole purpose is to walk through 6 or 7 steps to show that the DWT is possible in Reaktor (well, duh).

THESE PROBABLY AREN'T THE WAVELETS YOU'RE LOOKING FOR. These are the wrong kind of wavelets (and probably the wrong transform, too) to use for serious audio analysis, by which I mean editing audio via a frequency/time/magnitude plot. The Haar wavelet is the simplest to implement, and I chose it because, well, this is a proof-of-concept (and I'm not very good at Reaktor, yet).

THIS IS HARD TO MAKE WORK PROPERLY. Even though I tried to document it extensively (via the Ensemble's Info Property), you still have to know how to import audio files into Event Tables, and you have to use audio files that have a number of SAMPLES equal to a power-of-two (up to 65536). Well, you don't HAVE to - it's actually an exercise to see what happens when you don't. I've included two WAV files (that probably won't play in WMP) for demonstration purposes: "sound_65536.wav" (a frequency sweep at 44.1khz) and "cup_zpd.wav" (a spoken sentence at 11,025Hz).

THE CODE IS AWFUL. Please feel free to scoff at my abominable code, but know that such activity provides absolutely zero value - at least to me. I already know it's terrible, and very buggy too. The actual Haar code is in Core and it's not too terrible, but it's also the easiest bit in the whole thing. Do not expect to be able to use the code as a reference for your own project - I can barely reference it myself for this project.

So... why did I post something so poorly-executed? Because as of May 4, 2016 (in the US) there are zero projects in the User Library utilizing wavelet technology (they've been around since at least the '90s) and I thought that if I posted a particularly bad project (the kind I'm capable of) then lots of other people would think to themselves, "Surely I can do better than THAT!" - and then they would!

Ok, I think that's enough disclaiming. Try it out and make a pretty graph. In a future release I am going to put a Mouse Area over the graph and make the coefficients adjustable by clicking/dragging or whatever. But for now you have to just draw on the "COEFFICIENTS" table which, if you don't know about DWT decomposition, is going to be somewhat counter-intuitive.

For more info about wavelets in general check out this horrible website (with very good info): http://users.rowan.edu/~polikar/WAVELETS/WTpart1.html

To read up specifically on the Discrete Wavelet Transform, check out: http://users.rowan.edu/~polikar/WAVELETS/WTpart4.html

EDIT: there was a bug where the magnitude of the "Y" min and max of the "COEFFICIENTS" table was not large enough to hold the lowest frequency data for the frequency sweep WAV, thus causing the lowest frequencies to be chopped off. I fixed this now in ver. 0.0.1 so now there's only the mysterious "click" about 2/3rds of the way through the reconstructed WAV to figure out.

EDIT: I found several indexing errors that are now corrected. Currently there is/are bug(s) which cause the 40,239th and 63,292nd values out of 65,536 to be off by more than 1e-8 (they're off by more than 1, actually) using the freq. sweep sound file provided. These are detectable as audible "clicks" while playing back the reconstructed signal. Why those two? No idea, yet. Otherwise reconstruction errors are typically on the order of 1e-8, which isn't too bad.

EDIT: cleaned up the code a bit and made sure there's a file properly loaded when you first load the ensemble.

EDIT: seems like I fixed the recomposition errors indicated above. I don't know why, exactly (I just did some housecleaning on the thing), but the clicks are gone.

COMMENTS  (17)

andrew aronson
6 years ago
so a dc filter would just ensure it returns to 0 after playback. i created a thread it is here https://www.native-instruments.com/forum/threads/discrete-wavelet-transform-in-reaktor.270332/
andrew aronson
6 years ago
the pops i was talking about are only caused by last sample value hanging after playback stops, which i think isn't to big of a problem because most interfaces aren't dc coupled, but it makes it pop when it has to jump back to 0
Blok Dak
6 years ago
Actually, I think it would be cool to use a wavelet filter to remove the cracks and pops in the vocal example. But you shouldn't be experiencing any cracks/pops in the reconstructed signal that weren't in the original, too... As far as live input goes, I'm sure you're right but I'd actually have to sit down and think about how to implement that instead of shooting from the hip. But I think there's lots of fun to be had with static samples (like editing them from their spectrogram) - I just wish Reaktor had a more user-friendly way to load files. Finally, someone should really start a forum thread - it'd be great to discuss in more detail.
andrew aronson
6 years ago
it should be possible to use for live input by constantly updating blocks of 65536 samples maybe running a block or two behind, no? and if i am not mistaken thats when the fun can begin? (sorry to blow up the comments here, but in my experience the likelihood of getting a response here is much higher than in the forums)
andrew aronson
6 years ago
seems to work like a charm. i just recorded the output of the source and reconstruction, looking for differences now, it looks bang on!. also this could do with a dc filter, there is a pretty good one floating around either in the UL or forums,that would help with some of the popping
andrew aronson
6 years ago
oh nvm it was a host problem my audio device was disabled LOL
Blok Dak
6 years ago
andrew: I just downloaded what I uploaded and, for me, as soon as I open it it's as if all the buttons have been pushed... So, eg, it plays back the sound immediately. All the windows have been filled with their respective content, and my CPU is idling at 3.8%. I haven't been using Reaktor long enough to help troubleshoot it very well, I'm afraid.
andrew aronson
6 years ago
one thing i noticed in the sonic visualizer wavelet transform (if i remember correctly) is that the sample values all seemed to be the same just in different arrangement and i wonder if that could be utilized as a new technique maybe even avoiding all the filtering/subsampling
andrew aronson
6 years ago
so the update comes with embedded audio - nice, but clicking around i am not able to get playback. the ensemble is running at 0% cpu. is this right?
Blok Dak
6 years ago
I think a forum post is a great idea, and I'd gladly participate, for whatever that's worth. I'd also be happy to look over your reconstruction problem if you think that might help. You can email me at blokdak at gmail. I'd like to implement the CWT eventually to make something like this: http://stevehanov.ca/wavelet/. Of course there's all sorts of de-noising/de-clicking to be done with the DWT, not to mention compression (I'd really like to make a couple macros that, when placed around an event table, compress and decompress the stored data).
salamanderanagram
6 years ago
it would be nice to have a conversation in the forums about the math behind this. i would be happy to help make a usable demonstration of the wavelet transform, with the eventual goal being to create a complex dual tree transform, which is where all the high-quality pitchshifting algorithms are at. i have a haar wavelet made that you can play live sound thru, and does perfect reconstruction, but only for the first 'layer' of filter pairs. after that it begins to degrade. i think maybe i've misunderstood the process to build the reconstruction filters, not sure.
Blok Dak
6 years ago
Post it wherever you like! What I really want to know is: were you able to walk through the steps like the instructions said? Did it work for you? As in, did you end up with playable audio in the bottom right audio table and did it sound anything like the original? Were you able to load the other provided file and process that one, too?
andrew aronson
6 years ago
that's me! i'm looking at it now. i'm sure i will have plenty of questions once i get my bearings. hope you don't mind i posted a link to this in the ni reaktor builders facebook page
Blok Dak
6 years ago
Are you ANDREW221231? Because this post: https://www.native-instruments.com/forum/threads/how-hard-would-it-be-to-build-wavelet-transform.267739/ made me decide to do this project. All else being equal, you should be able to completely reconstruct a discrete signal with 100% accuracy. This project isn't there quite yet, as you can tell if you listen to the very beginning of the reconstructed frequency sweep. I haven't looked for the bug, but I'm sure I dropped a 0 somewhere or something.
Blok Dak
6 years ago
I'm glad you're interested! Feel free to email me if you have questions. I'm blokdak at gmail.
andrew aronson
6 years ago
sonic visualizer has a wavelet transform that helped me get an intuitive understanding of how wavelets work, looking at the sample values and how the data is rearranged. sadly, sonic visualizer lacks a few features that would have let me really 'hack it' and do what i wanted to do
andrew aronson
6 years ago
OMG THIS!!! even though i'm retarded in core, and even though according to you this ensemble is worthless, i cannot wait to go picking around inside this. i have been waiting for something like this to come around for a long time
now