## DWT frequency division graphing

This code illustrates the frequency division between branches in a Discrete Wavelet Transform. Please refer to the following blog post for more details:

http://www.dsprelated.com/showarticle/115.php

http://www.dsprelated.com/showarticle/116.php

You need these other code snippets in order to run this program:

http://www.dsprelated.com/showcode/10.php

http://www.dsprelated.com/showcode/12.php

```
% ----------------------------------------------------------
% Title: Discrete Wavelet Transform
% Author: David Valencia
% UPIITA IPN 2010
%
% For DSPRelated.com
% in: http://www.dsprelated.com/showcode/13.php
%
% Computes the Discrete Wavelet Transform
% equivalent filters
%
% Dependencies:
% formfilter.m - http://www.dsprelated.com/showcode/12.php
% upsample2.m - http://www.dsprelated.com/showcode/10.php
%
% Revisions:
% v1.0a Commented and translated in English
%
% More information at:
% http://www.dsprelated.com/showarticle/115.php
% -----------------------------------------------------------
close all; clear all; clc;
disp('== GENERALIZED DWT FILTERS ==')
%% STEP 1 - Base Filters
% Select type of base filters
typeofbasis = 'o';
typbior = 'bior2.2';
typor = 'db6';
% Obtain base filters
if(typeofbasis == 'b')
[Rf,Df] = biorwavf(typbior);
[h0,h1,g0,g1] = biorfilt(Df,Rf);
elseif (typeofbasis == 'o')
[h0,h1,g0,g1] = wfilters(typor);
end;
%% STEP 2 - Parameter configuration
% One can declare or recover an input vector from another
% program, but here an example vector is built for testing.
L = length(h0); %Base filter lenght
n_stages = 2; %Of the low-pass stage
n_branches = 2^n_stages; %Number of branches
% L = Basic filters length (h0 รณ h1)
% N = Input vector length
% n_stages = stage quantity, it generates (2^n_stages) branches
figure;
[H1,Wg]=freqz(h1,1,512);
plot(Wg,abs(H1),'r','linewidth',2); hold on;
for i = 0:(n_branches/2)-1
if n_stages < 3
hx = formfilter(n_stages, (n_branches/2) - i, h0, h1);
else
hx = formfilter(n_stages, (n_branches/2) - i - 1, h0, h1);
end
Lhx = length(hx);
% Graphing code
[H0,Wg]=freqz(hx,1,512);
plot(Wg,abs(H0),'b','linewidth',2); hold on;
pause; % Used to see how each filter appears
end
```

## Comments:

lalit_vagabond

Said:

Hey that explains a lot!Thank you!
Can u also explain how do i change certain coefficients and reconstruct the signal?

9 years ago

0

Sorry, you need javascript enabled to post any comments.

David VP

Said:

Hello lalit_vagabond,
You can change them directly by editing the vectors that get convoluted, being "hx" in each branch.
To reconstruct the signal, you can check the other code snippet in:
http://www.dsprelated.com/showcode/11.php
Which illustrates how to transform and reconstruct the signal using a convolution matrix, but soon I will post the chain-processing version.

Sorry, you need javascript enabled to post any comments.

Sorry, you need javascript enabled to post any comments.