1

I have a dataset Sig of size 65536 x 192 in Matlab. If I want to take the one-dimensional fft along the second dimension, I could either do a for loop:

%pre-allocate ect..
for i=1:65536
   F(i,:) = fft(Sig(i,:));
end

or I could specify the dimension and do it without the for loop:

F = fft(Sig,[],2);

which is about 20 times faster for my dataset.

I have looked for something similar for the discrete wavelet transform (dwt), but been unable to find it. So I was wondering if anyone knows a way to do dwt across a specified dimension in Matlab? Or do I have to use for loops?

Ghaul
  • 3,340
  • 1
  • 19
  • 24

3 Answers3

2

In your loop FFT example, it seems you operate on lines. Matlab use a Column-major order. It may explain the difference of performance. Is the performance the same if you operate on columns ? If this is the right explanation, you could use dwt in a loop.

Clement J.
  • 3,012
  • 26
  • 29
  • Operating on columns did give me a 6x speed up, but the *for* loop is still (unsurprisingly) much slower than the direct code. So a *dwt* across specified dimensions would still be preferable. Thanks for the tip about the column-major order of Matlab though, did not know that! – Ghaul Oct 12 '11 at 13:46
  • Did you also change the result to be stored in column ? – Clement J. Oct 12 '11 at 14:09
  • 2
    See http://www.mathworks.co.uk/company/newsletters/news_notes/june07/patterns.html for more information on MATLAB memory access – Nzbuu Oct 12 '11 at 14:13
  • Yeah. The *for* loop now takes about 1.4 sec, while the direct method takes about 0.2 for the *fft*. The problem is that the *dwt* is much slower than the *fft*.. – Ghaul Oct 12 '11 at 14:23
1

A solution if you really need performance is to do your own MEX calling a C discrete wavelet transform library the way you want.

Clement J.
  • 3,012
  • 26
  • 29
0

I presume you're using the function from the Wavelet Toolbox: http://www.mathworks.co.uk/help/toolbox/wavelet/ref/dwt.html

The documentation doesn't seem to describe acting on an array, so it's probably not supported. If it does allow you to input an array, then it will operate on the first non-singleton dimension or it will ignore the shape and treat it as a vector.

Nzbuu
  • 5,241
  • 1
  • 29
  • 51
  • I guess this is the correct answer, so I'll accept it, but it wasn't very useful/helpful, so you don't get an upvote :p (Only a couple of more 0 vote accepted answers and you get a gold badge! ;) ) – Ghaul Oct 12 '11 at 14:34
  • :) Sorry. Wish I had something better to say. I suppose that the Wavelet Toolbox expects that you would only use `dwt` with 1D data and `dwt2` with 2D data. I had exactly the same problem with the `gpuArray` version of `fft` in R2010b, although I haven't had a chance to try again. – Nzbuu Oct 12 '11 at 19:31