<< Chapter < Page | Chapter >> Page > |
function z = merge(x,y)
% z = merge(x,y) interleaves the two vectors x and y.% Example [1 2 3 4 5] = merge([1 3 5],[2 4]).% csb 3/1/93.
%z = [x;y,0];z = z(:);
z = z(1:length(z)-1).';
function w = wave(p,h)
% w = wave(p,h) calculates and plots the wavelet psi(t)% from the scaling function p and the scaling function
% coefficient vector h.% It uses the definition of the wavelet. csb. 5/19/93.
%h2 = h*2/sum(h);
NN = length(h2); LL = length(p); KK = round((LL)/(NN-1));h1u = upsam(h2(NN:-1:1).*cos(pi*[0:NN-1]),KK);w = dnsample(conv(h1u,p)); w = w(1:LL);
xx = [0:LL-1]*(NN-1)/(LL-1);
axis([1 2 3 4]); axis;
plot(xx,w);
function g = dwt(f,h,NJ)
% function g = dwt(f,h,NJ); Calculates the DWT of periodic g% with scaling filter h and NJ scales. rag&csb 3/17/94.
%N = length(h); L = length(f);
c = f; t = [];
if nargin==2, NJ = round(log10(L)/log10(2)); end; % Number of scalesh0 = fliplr(h); % Scaling filter
h1 = h; h1(1:2:N) = -h1(1:2:N); % Wavelet filterfor j = 1:NJ % Mallat's algorithm
L = length(c);c = [c(mod((-(N-1):-1),L)+1) c]; % Make periodicd = conv(c,h1); d = d(N:2:(N+L-2)); % Convolve&d-sample
c = conv(c,h0); c = c(N:2:(N+L-2)); % Convolve&d-sample
t = [d,t]; % Concatenate wlet coeffs.
end;g = [c,t]; % The DWT
function f = idwt(g,h,NJ)
% function f = idwt(g,h,NJ); Calculates the IDWT of periodic g% with scaling filter h and NJ scales. rag&csb 3/17/94.
%L = length(g); N = length(h);
if nargin==2, NJ = round(log10(L)/log10(2)); end; % Number of scalesh0 = h; % Scaling filter
h1 = fliplr(h); h1(2:2:N) = -h1(2:2:N); % Wavelet filterLJ = L/(2^NJ); % Number of SF coeffs.
c = g(1:LJ); % Scaling coeffs.for j = 1:NJ % Mallat's algorithm
w = mod(0:N/2-1,LJ)+1; % Make periodicd = g(LJ+1:2*LJ); % Wavelet coeffs.
cu(1:2:2*LJ+N) = [c c(1,w)]; % Up-sample&periodic
du(1:2:2*LJ+N) = [d d(1,w)]; % Up-sample&periodic
c = conv(cu,h0) + conv(du,h1); % Convolve&combine
c = c(N:N+2*LJ-1); % Periodic partLJ = 2*LJ;
end;f = c; % The inverse DWT
function r = mod(m,n)
% r = mod(m,n) calculates r = m modulo n%
r = m - n*floor(m/n); % Matrix modulo n
function g = dwt5(f,h,NJ)
% function g = dwt5(f,h,NJ)% Program to calculate the DWT from the L samples of f(t) in
% the vector f using the scaling filter h(n).% csb 3/20/94
%N = length(h);
c = f; t = [];
if nargin==2NJ = round(log10(L)/log10(2)); % Number of scales
end;h1 = h; h1(1:2:N) = -h1(1:2:N); % Wavelet filter
h0 = fliplr(h); % Scaling filterfor j = 1:NJ % Mallat's algorithm
L = length(c);d = conv(c,h1); % Convolve
c = conv(c,h0); % ConvolveLc = length(c);
while Lc>2*L % Multi-wrap?
d = [(d(1:L) + d(L+1:2*L)), d(2*L+1:Lc)]; % Wrap output
c = [(c(1:L) + c(L+1:2*L)), c(2*L+1:Lc)]; % Wrap output
Lc = length(c);end
d = [(d(1:N-1) + d(L+1:Lc)), d(N:L)]; % Wrap output
d = d(1:2:L); % Down-sample wlets coeffs.c = [(c(1:N-1) + c(L+1:Lc)), c(N:L)]; % Wrap outputc = c(1:2:L); % Down-sample scaling fn c.
t = [d,t]; % Concatenate wlet coeffs.
end % Finish wavelet partg = [c,t]; % Add scaling fn coeff.
function a = choose(n,k)
% a = choose(n,k)% BINOMIAL COEFFICIENTS
% allowable inputs:% n : integer, k : integer
% n : integer vector, k : integer% n : integer, k : integer vector
% n : integer vector, k : integer vector (of equal dimension)nv = n;
kv = k;if (length(nv) == 1)&(length(kv)>1)
nv = nv * ones(size(kv));elseif (length(nv)>1)&(length(kv) == 1)
kv = kv * ones(size(nv));end
a = nv;for i = 1:length(nv)
n = nv(i);k = kv(i);
if n>= 0
if k>= 0
if n>= k
c = prod(1:n)/(prod(1:k)*prod(1:n-k));else
c = 0;end
elsec = 0;
endelse
if k>= 0
c = (-1)^k * prod(1:k-n-1)/(prod(1:k)*prod(1:-n-1));else
if n>= k
c = (-1)^(n-k)*prod(1:-k-1)/(prod(1:n-k)*prod(1:-n-1));else
c = 0;end
endend
a(i) = c;end
Notification Switch
Would you like to follow the 'Wavelets and wavelet transforms' conversation and receive update notifications?