--- a/wavelets/wavfun.m
+++ b/wavelets/wavfun.m
@@ -1,14 +1,41 @@
 function [w,s,xvals] = wavfun(g,N)
+% WAVFUN  Wavelet Function
+%    Usage: [w,s,xvals] = wavfun(g,N) 
+%
+%   Input parameters:
+%         g     :  Wavelet filterbank
+%         N     :  Number of iterations
+%   Output parameters:
+%         w     : J+1 cell array of analysing filters impulse reponses
+%
+% Iteratively generate a discrete approximation of wavelet and scaling functions 
+%
+
+if(isstruct(g))
+    g=g.g;
+end
+
+gLen = length(g);
 
 lo = g{1}(:);
-hi = g{2}(:);
 s = lo;
-w = hi;
+wtemp = cell(gLen-1,1);
+for ii=1:gLen-1
+    wtemp{ii} = g{ii+1}(:);
+end
 
 for n=1:N
-    w = conv(ups(w,2,1),lo);
-    s = conv(ups(s,2,1),lo);
+    for ii=1:gLen-1 
+       wtemp{ii} = convolve(ups(wtemp{ii},2,1),lo);
+    end
+    s = convolve(ups(s,2,1),lo);
 end
+
+w = zeros(length(wtemp{1}),gLen-1);
+for ii=1:gLen-1 
+   w(:,ii) = wtemp{ii};
+end
+
 
 if(nargout>2)
     xvals=linspace(0,length(lo),length(s));