Implementing 1D Discrete Wavelet Transform in Matlab

1.3k Views Asked by At

I'm trying to write my own version of the Discrete Wavelet Transform using the bior4.4 filters.

I think my implementation is not properly working yet, because whenever I input a signal and a number of iterations to calculate, my result is always an array of 10 long.

Shouldn't the approximation coefficient (Ca) be a single number in the end?

This is my version:

function R=myDWT(sig, count)
 [Lo_D, Hi_D] = wfilter_bior44();
 input = sig;
 while(count ~= 0) % While count not equal to 0
     % Pass through filters by using convolution
     Ca = conv(input, Lo_D);
     Cd = conv(input, Hi_D);
     % Downsample by 2
     Ca = downsample(Ca, 2);
     Cd = downsample(Cd, 2);
     % TODO: Save Ca and Cd somewhere
     count = count - 1;
     input = Ca;
 end
 R = input;
end
1

There are 1 best solutions below

0
On BEST ANSWER

The problem lies with the convolution. Standard Matlab conv function will use full convolution. So the length will always be dependent on the longest of the 2 arguments. This can be resolved by using the same parameter for convolution.

'same': Central part of the convolution of the same size as u.

So the correct code is:

function R=myDWT(sig, count)
 [Lo_D, Hi_D] = wfilter_bior44();
 input = sig;
 while(count ~= 0) % While count not equal to 0
     % Pass through filters by using convolution
     Ca = conv(input, Lo_D, 'same');
     Cd = conv(input, Hi_D, 'same');
     % Downsample by 2
     Ca = downsample(Ca, 2);
     Cd = downsample(Cd, 2);
     % TODO: Save Ca and Cd somewhere
     count = count - 1;
     input = Ca;
 end
 R = input;
end