hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_wav_3d_multi_fwd (c09fc)

Purpose

nag_wav_3d_multi_fwd (c09fc) computes the three-dimensional multi-level discrete wavelet transform (DWT). The initialization function nag_wav_3d_init (c09ac) must be called first to set up the DWT options.

Syntax

[c, dwtlvm, dwtlvn, dwtlvfr, icomm, ifail] = c09fc(n, fr, a, lenc, nwl, icomm, 'm', m)
[c, dwtlvm, dwtlvn, dwtlvfr, icomm, ifail] = nag_wav_3d_multi_fwd(n, fr, a, lenc, nwl, icomm, 'm', m)

Description

nag_wav_3d_multi_fwd (c09fc) computes the multi-level DWT of three-dimensional data. For a given wavelet and end extension method, nag_wav_3d_multi_fwd (c09fc) will compute a multi-level transform of a three-dimensional array AA, using a specified number, nlnl, of levels. The number of levels specified, nlnl, must be no more than the value lmaxlmax returned in nwl by the initialization function nag_wav_3d_init (c09ac) for the given problem. The transform is returned as a set of coefficients for the different levels (packed into a single array) and a representation of the multi-level structure.
The notation used here assigns level 00 to the input matrix, AA. Level 1 consists of the first set of coefficients computed: the seven sets of detail coefficients are stored at this level while the approximation coefficients are used as the input to a repeat of the wavelet transform at the next level. This process is continued until, at level nlnl, all eight types of coefficients are stored. All coefficients are packed into a single array.

References

None.

Parameters

Compulsory Input Parameters

1:     n – int64int32nag_int scalar
The second dimension of the input data: the number of columns of each two-dimensional frame.
Constraint: this must be the same as the value n passed to the initialization function nag_wav_3d_init (c09ac).
2:     fr – int64int32nag_int scalar
The third dimension of the input data: the number of two-dimensional frames.
Constraint: this must be the same as the value fr passed to the initialization function nag_wav_3d_init (c09ac).
3:     a(lda,sda,fr) – double array
lda, the first dimension of the array, must satisfy the constraint ldamldam.
The mm by nn by frfr input three-dimensional array AA.
4:     lenc – int64int32nag_int scalar
The dimension of the array c as declared in the (sub)program from which nag_wav_3d_multi_fwd (c09fc) is called.
Constraint: lencnctlencnct, where nctnct is the total number of wavelet coefficients that correspond to a transform with nwl levels.
5:     nwl – int64int32nag_int scalar
The number of levels, nlnl, in the multi-level resolution to be performed.
Constraint: 1nwllmax1nwllmax, where lmaxlmax is the value returned in nwl (the maximum number of levels) by the call to the initialization function nag_wav_3d_init (c09ac).
6:     icomm(260260) – int64int32nag_int array
Contains details of the discrete wavelet transform and the problem dimension as setup in the call to the initialization function nag_wav_3d_init (c09ac).

Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The first dimension of the array a.
The first dimension of the input data: the number of rows of each two-dimensional frame.
Constraint: this must be the same as the value m passed to the initialization function nag_wav_3d_init (c09ac).

Input Parameters Omitted from the MATLAB Interface

lda sda

Output Parameters

1:     c(lenc) – double array
The coefficients of the discrete wavelet transform.
Let q(i)q(i) denote the number of coefficients (of each type) at level ii, for i = 1,2,,nli=1,2,,nl, such that q(i) = dwtlvm(nli + 1) × dwtlvn(nli + 1) × dwtlvfr(nli + 1) q(i)= dwtlvmnl-i+1× dwtlvnnl-i+1× dwtlvfrnl-i+1 . Then, letting k1 = q(nl)k1=q(nl) and kj + 1 = kj + q(nlj / 7 + 1)kj+1=kj+q(nl-j/7+1), for j = 1,2,,7nlj=1,2,,7nl, the coefficients are stored in c as follows:
c(i)ci, for i = 1,2,,k1i=1,2,,k1
Contains the level nlnl approximation coefficients, anlanl. Note that for computational efficiency reasons these coefficients are stored as dwtlvm(1) × dwtlvn(1) × dwtlvfr(1) dwtlvm1× dwtlvn1× dwtlvfr1 in c.
c(i)ci, for i = kj + 1,,kj + 1i=kj+1,,kj+1
Contains the level nlj / 7 + 1nl-j/7+1 detail coefficients. These are:
  • LLH coefficients if j  mod  7 = 1j mod 7=1;
  • LHL coefficients if j  mod  7 = 2j mod 7=2;
  • LHH coefficients if j  mod  7 = 3j mod 7=3;
  • HLL coefficients if j  mod  7 = 4j mod 7=4;
  • HLH coefficients if j  mod  7 = 5j mod 7=5;
  • HHL coefficients if j  mod  7 = 6j mod 7=6;
  • HHH coefficients if j  mod  7 = 0j mod 7=0,
for j = 1,,7nlj=1,,7nl.
Note that for computational efficiency reasons these coefficients are stored as dwtlvfr (j / 7) × dwtlvm (j / 7) × dwtlvn (j / 7) dwtlvfr ( j/7 ) × dwtlvm ( j/7 ) × dwtlvn ( j/7 ) in c.
See Section [Example] for details of how to access each set of coefficients in order to perform extraction from C following a call to this function, or insertion into c before a call to the three-dimensional multi-level inverse function nag_wav_3d_mxolap_multi_inv (c09fd).
2:     dwtlvm(nwl) – int64int32nag_int array
The number of coefficients in the first dimension for each coefficient type at each level. dwtlvm(i)dwtlvmi contains the number of coefficients in the first dimension (for each coefficient type computed) at the (nli + 1nl-i+1)th level of resolution, for i = 1,2,,nli=1,2,,nl.
3:     dwtlvn(nwl) – int64int32nag_int array
The number of coefficients in the second dimension for each coefficient type at each level. dwtlvn(i)dwtlvni contains the number of coefficients in the second dimension (for each coefficient type computed) at the (nli + 1nl-i+1)th level of resolution, for i = 1,2,,nli=1,2,,nl.
4:     dwtlvfr(nwl) – int64int32nag_int array
The number of coefficients in the third dimension for each coefficient type at each level. dwtlvfr(i)dwtlvfri contains the number of coefficients in the third dimension (for each coefficient type computed) at the (nli + 1nl-i+1)th level of resolution, for i = 1,2,,nli=1,2,,nl.
5:     icomm(260260) – int64int32nag_int array
Contains additional information on the computed transform.
6:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
Constraint: fr = frfr=fr, the value of fr on initialization (see nag_wav_3d_init (c09ac)).
Constraint: m = mm=m, the value of m on initialization (see nag_wav_3d_init (c09ac)).
Constraint: n = nn=n, the value of n on initialization (see nag_wav_3d_init (c09ac)).
  ifail = 2ifail=2
Constraint: ldamldam.
Constraint: sdansdan.
  ifail = 3ifail=3
lenc is too small, the total number of coefficents to be generated.
  ifail = 5ifail=5
Constraint: nwlnwlnwlnwl in nag_wav_3d_init (c09ac).
Constraint: nwl1nwl1.
  ifail = 6ifail=6
Either the initialization function has not been called first or the communication array icomm has been corrupted.
The initialization function was called with wtrans = 'S'wtrans='S'.
  ifail = 999ifail=-999
Dynamic memory allocation failed.

Accuracy

The accuracy of the wavelet transform depends only on the floating point operations used in the convolution and downsampling and should thus be close to machine precision.

Further Comments

The example program shows how the wavelet coefficients at each level can be extracted from the output array c. Denoising can be carried out by applying a thresholding operation to the detail coefficients at every level. If cijcij is a detail coefficient then ij = cij + σεijc^ij=cij+σεij and σεijσεij is the transformed noise term. If some threshold parameter αα is chosen, a simple hard thresholding rule can be applied as
cij =
{ 0, if ​ |ĉij| ≤ α ĉij , if ​ |ĉij| > α,
c- ij = { 0, if ​ |c^ij| α c^ij , if ​ |c^ij| > α,
taking cijc-ij to be an approximation to the required detail coefficient without noise, cijcij. The resulting coefficients can then be used as input to nag_wav_3d_mxolap_multi_inv (c09fd) in order to reconstruct the denoised signal.
See the references given in the introduction to this chapter for a more complete account of wavelet denoising and other applications.

Example

function nag_wav_3d_multi_fwd_example
m  = int64(7);
n  = int64(6);
fr = int64(5);
wavnam = 'Bior1.1';
mode = 'period';
wtrans = 'Multilevel';
a = zeros(m, n, fr);
a(:, :, 1) = [3, 2, 2, 2, 1, 1;
              2, 9, 1, 2, 1, 3;
              2, 5, 1, 2, 1, 1;
              1, 6, 2, 2, 7, 2;
              5, 3, 2, 2, 4, 7;
              2, 2, 1, 1, 2, 1;
              6, 2, 1, 3, 6, 9];
a(:, :, 2) = [2, 1, 5, 1, 2, 3;
              2, 9, 5, 2, 1, 2;
              2, 3, 2, 7, 1, 1;
              2, 1, 1, 2, 3, 1;
              2, 1, 2, 8, 3, 3;
              1, 4, 5, 1, 2, 7;
              8, 1, 3, 9, 1, 2];
a(:, :, 3) = [3, 1, 4, 1, 1, 1;
              1, 1, 2, 1, 2, 6;
              4, 1, 7, 2, 5, 6;
              3, 2, 1, 5, 9, 5;
              1, 1, 2, 2, 2, 1;
              2, 6, 3, 9, 5, 1;
              1, 1, 8, 2, 1, 3];
a(:, :, 4) = [5, 8, 1, 2, 2, 1;
              1, 2, 2, 9, 2, 9;
              2, 2, 2, 1, 1, 3;
              1, 1, 1, 5, 1, 2;
              3, 2, 8, 1, 9, 2;
              2, 1, 9, 1, 2, 2;
              3, 6, 5, 3, 2, 2];
a(:, :, 5) = [5, 2, 1, 2, 1, 1;
              3, 1, 9, 1, 2, 1;
              2, 3, 1, 1, 7, 2;
              7, 2, 2, 6, 1, 1;
              5, 1, 7, 2, 1, 1;
              2, 1, 3, 2, 2, 1;
              5, 3, 9, 1, 4, 1];


% Query wavelet filter dimensions
[nwl, nf, nwct, nwcn, nwcfr, icomm, ifail] = ...
      nag_wav_3d_init(wavnam, wtrans, mode, m, n, fr);

% Perform Discrete Wavelet transform
[c, dwtlvm, dwtlvn, dwtlvfr, icomm, ifail] = ...
      nag_wav_3d_multi_fwd(n, fr, a, nwct, nwl, icomm);

fprintf(' Number of Levels : %d\n\n', nwl);
fprintf(' Number of coefficients in 1st dimension for each level:\n');
fprintf(' %8d', dwtlvm(1:nwl));
fprintf('\n');
fprintf(' Number of coefficients in 2nd dimension for each level:\n');
fprintf(' %8d', dwtlvn(1:nwl));
fprintf('\n');
fprintf(' Number of coefficients in 3rd dimension for each level:\n');
fprintf(' %8d', dwtlvfr(1:nwl));
fprintf('\n');

% Print the first level HLL coefficients
want_level = 1;

% Select the approximation coefficients.
want_coeffs = 4;

% Identify each set of coefficients in c
for ilevel = nwl:-1:1

  if ilevel ~= want_level
    continue
  end

  nwcm = dwtlvm(nwl-ilevel+1);
  nwcn = dwtlvn(nwl-ilevel+1);
  nwcfr = dwtlvfr(nwl-ilevel+1);

  fprintf('\n--------------------------------\n');
  fprintf(' Level %d output is %d by %d by %d.\n', ilevel, nwcm, nwcn, nwcfr);
  fprintf('--------------------------------\n\n');

  for itype_coeffs = 0:7

    if itype_coeffs ~= want_coeffs
      continue
    end

    % Unless we're looking at the deepest level of nesting, which contains
    % approximation coefficients, advance the pointer on past the preceding
    % levels
    if ilevel == nwl
      locc = 0;
    else
      locc = 8*dwtlvm(1)*dwtlvn(1)*dwtlvfr(1);
      for i = ilevel + 1 : nwl - 1
        locc = locc + 7*dwtlvm(nwl-i+1)*dwtlvn(nwl-i+1)*dwtlvfr(nwl-i+1);
      end
    end

    % Now decide which coefficient type we are considering
    switch (itype_coeffs)
      case {0}
        if (ilevel==nwl)
          fprintf('Approximation coefficients (LLL)\n');
          locc = locc + 1;
        end
      case {1}
        fprintf('Detail coefficients (LLH)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients
          locc = locc + nwcm*nwcn*nwcfr + 1;
        else
          locc = locc + 1;
        end
      case {2}
        fprintf('Detail coefficients (LHL)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 1 set of
          % detail coefficients
          locc = locc + 2*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 1 set of detail coefficients
          locc = locc + nwcm*nwcn*nwcfr + 1;
        end
      case {3}
        fprintf('Detail coefficients (LHH)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 2 sets of
          % detail coefficients
          locc = locc + 3*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 2 sets of detail coefficients
          locc = locc + 2*nwcm*nwcn*nwcfr + 1;
        end
      case {4}
        fprintf('Detail coefficients (HLL)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 3 sets of
          % detail coefficients
          locc = locc + 4*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 3 sets of detail coefficients
          locc = locc + 3*nwcm*nwcn*nwcfr + 1;
        end
      case {5}
        fprintf('Detail coefficients (HLH)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 4 sets of
          % detail coefficients
          locc = locc + 5*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 4 sets of detail coefficients
          locc = locc + 4*nwcm*nwcn*nwcfr + 1;
        end
      case {6}
        fprintf('Detail coefficients (HHL)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 5 sets of
          % detail coefficients
          locc = locc + 6*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 4 sets of detail coefficients
          locc = locc + 5*nwcm*nwcn*nwcfr + 1;
        end
      case {7}
        fprintf('Detail coefficients (HHH)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 6 sets of
          % detail coefficients
          locc = locc + 7*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 5 sets of detail coefficients
          locc = locc + 6*nwcm*nwcn*nwcfr + 1;
        end
      end

  if itype_coeffs > 0 || ilevel == nwl

    if (itype_coeffs==0)
      % For a multi level transform approx coeffs stored as
      % nwcm x nwcn x nwcfr
      i1 = locc;
      for k = 1:nwcfr
        for j = 1:nwcn
          for i = 1:nwcm
            d(i,j,k) = c(i1);
            i1 = i1 + 1;
          end
        end
      end
    else
      % ... but detail coefficients are stored as ncwfr x nwcm x nwcn
      for k = 1:nwcfr
        for j = 1:nwcn
          for i = 1:nwcm
            i1 = locc - 1 + (j-1)*nwcfr*nwcm + (i-1)*nwcfr + k;
            d(i,j,k) = c(i1);
          end
        end
      end
    end

    % Print out the selected set of coefficients
    fprintf('Level %d, Coefficients %d:\n', ilevel, itype_coeffs);
    for k = 1:nwcfr
      fprintf('Frame %d:\n', k);
      for i = 1:nwcm
        for j=1:nwcn
          fprintf('%8.4f ', d(i, j, k));
        end
        fprintf('\n');
      end
    end

  end

  end
end

% Reconstruct original data
[b, ifail] = nag_wav_3d_mxolap_multi_inv(nwl, c, m, n, fr, icomm);

% Check reconstruction matches original
eps = 10*double(m*n*fr)*nag_machine_precision;
err = a-b;
frob = 0;
for i=1:fr
  fnew = sqrt(sum(sum(err(:,:,i).^2)));
  frob = max(frob,fnew);
end

if frob < eps
  fprintf('\nSuccess: the reconstruction matches the original.\n');
else
  fprintf('\nFail: Frobenius norm of b-a is too large.\n');
end
 
 Number of Levels : 2

 Number of coefficients in 1st dimension for each level:
        2        4
 Number of coefficients in 2nd dimension for each level:
        2        3
 Number of coefficients in 3rd dimension for each level:
        2        3

--------------------------------
 Level 1 output is 4 by 3 by 3.
--------------------------------

Detail coefficients (HLL)
Level 1, Coefficients 4:
Frame 1:
 -4.9497   0.0000   0.0000 
  0.7071   1.7678  -3.1820 
  0.7071   2.1213   1.7678 
  0.0000   0.0000   0.0000 
Frame 2:
  4.2426  -2.1213  -4.9497 
  0.7071  -0.0000  -0.7071 
 -1.4142  -3.1820   1.4142 
  0.0000   0.0000   0.0000 
Frame 3:
  2.1213  -4.9497  -0.7071 
 -2.8284  -4.2426   4.9497 
  2.1213   2.8284  -0.7071 
  0.0000   0.0000   0.0000 

Success: the reconstruction matches the original.

function c09fc_example
m  = int64(7);
n  = int64(6);
fr = int64(5);
wavnam = 'Bior1.1';
mode = 'period';
wtrans = 'Multilevel';
a = zeros(m, n, fr);
a(:, :, 1) = [3, 2, 2, 2, 1, 1;
              2, 9, 1, 2, 1, 3;
              2, 5, 1, 2, 1, 1;
              1, 6, 2, 2, 7, 2;
              5, 3, 2, 2, 4, 7;
              2, 2, 1, 1, 2, 1;
              6, 2, 1, 3, 6, 9];
a(:, :, 2) = [2, 1, 5, 1, 2, 3;
              2, 9, 5, 2, 1, 2;
              2, 3, 2, 7, 1, 1;
              2, 1, 1, 2, 3, 1;
              2, 1, 2, 8, 3, 3;
              1, 4, 5, 1, 2, 7;
              8, 1, 3, 9, 1, 2];
a(:, :, 3) = [3, 1, 4, 1, 1, 1;
              1, 1, 2, 1, 2, 6;
              4, 1, 7, 2, 5, 6;
              3, 2, 1, 5, 9, 5;
              1, 1, 2, 2, 2, 1;
              2, 6, 3, 9, 5, 1;
              1, 1, 8, 2, 1, 3];
a(:, :, 4) = [5, 8, 1, 2, 2, 1;
              1, 2, 2, 9, 2, 9;
              2, 2, 2, 1, 1, 3;
              1, 1, 1, 5, 1, 2;
              3, 2, 8, 1, 9, 2;
              2, 1, 9, 1, 2, 2;
              3, 6, 5, 3, 2, 2];
a(:, :, 5) = [5, 2, 1, 2, 1, 1;
              3, 1, 9, 1, 2, 1;
              2, 3, 1, 1, 7, 2;
              7, 2, 2, 6, 1, 1;
              5, 1, 7, 2, 1, 1;
              2, 1, 3, 2, 2, 1;
              5, 3, 9, 1, 4, 1];


% Query wavelet filter dimensions
[nwl, nf, nwct, nwcn, nwcfr, icomm, ifail] = ...
      c09ac(wavnam, wtrans, mode, m, n, fr);

% Perform Discrete Wavelet transform
[c, dwtlvm, dwtlvn, dwtlvfr, icomm, ifail] = c09fc(n, fr, a, nwct, nwl, icomm);

fprintf(' Number of Levels : %d\n\n', nwl);
fprintf(' Number of coefficients in 1st dimension for each level:\n');
fprintf(' %8d', dwtlvm(1:nwl));
fprintf('\n');
fprintf(' Number of coefficients in 2nd dimension for each level:\n');
fprintf(' %8d', dwtlvn(1:nwl));
fprintf('\n');
fprintf(' Number of coefficients in 3rd dimension for each level:\n');
fprintf(' %8d', dwtlvfr(1:nwl));
fprintf('\n');

% Print the first level HLL coefficients
want_level = 1;

% Select the approximation coefficients.
want_coeffs = 4;

% Identify each set of coefficients in c
for ilevel = nwl:-1:1

  if ilevel ~= want_level
    continue
  end

  nwcm = dwtlvm(nwl-ilevel+1);
  nwcn = dwtlvn(nwl-ilevel+1);
  nwcfr = dwtlvfr(nwl-ilevel+1);

  fprintf('\n--------------------------------\n');
  fprintf(' Level %d output is %d by %d by %d.\n', ilevel, nwcm, nwcn, nwcfr);
  fprintf('--------------------------------\n\n');

  for itype_coeffs = 0:7

    if itype_coeffs ~= want_coeffs
      continue
    end

    % Unless we're looking at the deepest level of nesting, which contains
    % approximation coefficients, advance the pointer on past the preceding
    % levels
    if ilevel == nwl
      locc = 0;
    else
      locc = 8*dwtlvm(1)*dwtlvn(1)*dwtlvfr(1);
      for i = ilevel + 1 : nwl - 1
        locc = locc + 7*dwtlvm(nwl-i+1)*dwtlvn(nwl-i+1)*dwtlvfr(nwl-i+1);
      end
    end

    % Now decide which coefficient type we are considering
    switch (itype_coeffs)
      case {0}
        if (ilevel==nwl)
          fprintf('Approximation coefficients (LLL)\n');
          locc = locc + 1;
        end
      case {1}
        fprintf('Detail coefficients (LLH)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients
          locc = locc + nwcm*nwcn*nwcfr + 1;
        else
          locc = locc + 1;
        end
      case {2}
        fprintf('Detail coefficients (LHL)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 1 set of
          % detail coefficients
          locc = locc + 2*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 1 set of detail coefficients
          locc = locc + nwcm*nwcn*nwcfr + 1;
        end
      case {3}
        fprintf('Detail coefficients (LHH)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 2 sets of
          % detail coefficients
          locc = locc + 3*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 2 sets of detail coefficients
          locc = locc + 2*nwcm*nwcn*nwcfr + 1;
        end
      case {4}
        fprintf('Detail coefficients (HLL)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 3 sets of
          % detail coefficients
          locc = locc + 4*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 3 sets of detail coefficients
          locc = locc + 3*nwcm*nwcn*nwcfr + 1;
        end
      case {5}
        fprintf('Detail coefficients (HLH)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 4 sets of
          % detail coefficients
          locc = locc + 5*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 4 sets of detail coefficients
          locc = locc + 4*nwcm*nwcn*nwcfr + 1;
        end
      case {6}
        fprintf('Detail coefficients (HHL)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 5 sets of
          % detail coefficients
          locc = locc + 6*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 4 sets of detail coefficients
          locc = locc + 5*nwcm*nwcn*nwcfr + 1;
        end
      case {7}
        fprintf('Detail coefficients (HHH)\n');
        if (ilevel==nwl)
          % Advance pointer past approximation coefficients and 6 sets of
          % detail coefficients
          locc = locc + 7*nwcm*nwcn*nwcfr + 1;
        else
          % Advance pointer past 5 sets of detail coefficients
          locc = locc + 6*nwcm*nwcn*nwcfr + 1;
        end
      end

  if itype_coeffs > 0 || ilevel == nwl

    if (itype_coeffs==0)
      % For a multi level transform approx coeffs stored as
      % nwcm x nwcn x nwcfr
      i1 = locc;
      for k = 1:nwcfr
        for j = 1:nwcn
          for i = 1:nwcm
            d(i,j,k) = c(i1);
            i1 = i1 + 1;
          end
        end
      end
    else
      % ... but detail coefficients are stored as ncwfr x nwcm x nwcn
      for k = 1:nwcfr
        for j = 1:nwcn
          for i = 1:nwcm
            i1 = locc - 1 + (j-1)*nwcfr*nwcm + (i-1)*nwcfr + k;
            d(i,j,k) = c(i1);
          end
        end
      end
    end

    % Print out the selected set of coefficients
    fprintf('Level %d, Coefficients %d:\n', ilevel, itype_coeffs);
    for k = 1:nwcfr
      fprintf('Frame %d:\n', k);
      for i = 1:nwcm
        for j=1:nwcn
          fprintf('%8.4f ', d(i, j, k));
        end
        fprintf('\n');
      end
    end

  end

  end
end

% Reconstruct original data
[b, ifail] = c09fd(nwl, c, m, n, fr, icomm);

% Check reconstruction matches original
eps = 10*double(m*n*fr)*x02aj;
err = a-b;
frob = 0;
for i=1:fr
  fnew = sqrt(sum(sum(err(:,:,i).^2)));
  frob = max(frob,fnew);
end

if frob < eps
  fprintf('\nSuccess: the reconstruction matches the original.\n');
else
  fprintf('\nFail: Frobenius norm of b-a is too large.\n');
end
 
 Number of Levels : 2

 Number of coefficients in 1st dimension for each level:
        2        4
 Number of coefficients in 2nd dimension for each level:
        2        3
 Number of coefficients in 3rd dimension for each level:
        2        3

--------------------------------
 Level 1 output is 4 by 3 by 3.
--------------------------------

Detail coefficients (HLL)
Level 1, Coefficients 4:
Frame 1:
 -4.9497   0.0000   0.0000 
  0.7071   1.7678  -3.1820 
  0.7071   2.1213   1.7678 
  0.0000   0.0000   0.0000 
Frame 2:
  4.2426  -2.1213  -4.9497 
  0.7071  -0.0000  -0.7071 
 -1.4142  -3.1820   1.4142 
  0.0000   0.0000   0.0000 
Frame 3:
  2.1213  -4.9497  -0.7071 
 -2.8284  -4.2426   4.9497 
  2.1213   2.8284  -0.7071 
  0.0000   0.0000   0.0000 

Success: the reconstruction matches the original.


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013