Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_wav_2d_sngl_fwd (c09ea)

## Purpose

nag_wav_2d_sngl_fwd (c09ea) computes the two-dimensional discrete wavelet transform (DWT) at a single level. The initialization function nag_wav_2d_init (c09ab) must be called first to set up the DWT options.

## Syntax

[ca, ch, cv, cd, ifail] = c09ea(a, icomm, 'm', m, 'n', n)
[ca, ch, cv, cd, ifail] = nag_wav_2d_sngl_fwd(a, icomm, 'm', m, 'n', n)

## Description

nag_wav_2d_sngl_fwd (c09ea) computes the two-dimensional DWT of a given input data array, considered as a matrix A$A$, at a single level. For a chosen wavelet filter pair, the output coefficients are obtained by applying convolution and downsampling by two to the input, A$A$, first over columns and then to the result over rows. The matrix of approximation (or smooth) coefficients, Ca${C}_{a}$, is produced by the low pass filter over columns and rows; the matrix of horizontal coefficients, Ch${C}_{h}$, is produced by the high pass filter over columns and the low pass filter over rows; the matrix of vertical coefficients, Cv${C}_{v}$, is produced by the low pass filter over columns and the high pass filter over rows; and the matrix of diagonal coefficients, Cd${C}_{d}$, is produced by the high pass filter over columns and rows. To reduce distortion effects at the ends of the data array, several end extension methods are commonly used. Those provided are: periodic or circular convolution end extension, half-point symmetric end extension, whole-point symmetric end extension and zero end extension. The total number, nct${n}_{\mathrm{ct}}$, of coefficients computed for Ca${C}_{a}$, Ch${C}_{h}$, Cv${C}_{v}$, and Cd${C}_{d}$ together and the number of columns of each coefficients matrix, ncn${n}_{\mathrm{cn}}$, are returned by the initialization function nag_wav_2d_init (c09ab). These values can be used to calculate the number of rows of each coefficients matrix, ncm${n}_{\mathrm{cm}}$, using the formula ncm = nct / (4ncn)${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$.

## References

Daubechies I (1992) Ten Lectures on Wavelets SIAM, Philadelphia

## Parameters

### Compulsory Input Parameters

1:     a(lda,n) – double array
lda, the first dimension of the array, must satisfy the constraint ldam$\mathit{lda}\ge {\mathbf{m}}$.
The m$m$ by n$n$ data matrix A$A$.
2:     icomm(180$180$) – 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_2d_init (c09ab).

### Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The first dimension of the array a.
Number of rows, m$m$, of data matrix A$A$.
Constraint: this must be the same as the value m passed to the initialization function nag_wav_2d_init (c09ab).
2:     n – int64int32nag_int scalar
Default: The second dimension of the array a.
Number of columns, n$n$, of data matrix A$A$.
Constraint: this must be the same as the value n passed to the initialization function nag_wav_2d_init (c09ab).

### Input Parameters Omitted from the MATLAB Interface

lda ldca ldch ldcv ldcd

### Output Parameters

1:     ca(ldca, : $:$) – double array
The first dimension of the array ca will be ncm${n}_{\mathrm{cm}}$ where ncm = nct / (4ncn)${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ncn${n}_{\mathrm{cn}}$, nct${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wav_2d_init (c09ab)
The second dimension of the array will be ncn$\mathit{ncn}$ where ncn${n}_{\mathrm{cn}}$ is the parameter nwcn returned by function nag_wav_2d_init (c09ab)
ldcancm$\mathit{ldca}\ge {n}_{\mathrm{cm}}$ where ncm = nct / (4ncn)${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ncn${n}_{\mathrm{cn}}$, nct${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wav_2d_init (c09ab).
Contains the ncm${n}_{\mathrm{cm}}$ by ncn${n}_{\mathrm{cn}}$ matrix of approximation coefficients, Ca${C}_{a}$.
2:     ch(ldch, : $:$) – double array
The first dimension of the array ch will be ncm${n}_{\mathrm{cm}}$ where ncm = nct / (4ncn)${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ncn${n}_{\mathrm{cn}}$, nct${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wav_2d_init (c09ab)
The second dimension of the array will be ncn$\mathit{ncn}$ where ncn${n}_{\mathrm{cn}}$ is the parameter nwcn returned by function nag_wav_2d_init (c09ab)
ldchncm$\mathit{ldch}\ge {n}_{\mathrm{cm}}$ where ncm = nct / (4ncn)${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ncn${n}_{\mathrm{cn}}$, nct${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wav_2d_init (c09ab).
Contains the ncm${n}_{\mathrm{cm}}$ by ncn${n}_{\mathrm{cn}}$ matrix of horizontal coefficients, Ch${C}_{h}$.
3:     cv(ldcv, : $:$) – double array
The first dimension of the array cv will be ncm${n}_{\mathrm{cm}}$ where ncm = nct / (4ncn)${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ncn${n}_{\mathrm{cn}}$, nct${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wav_2d_init (c09ab)
The second dimension of the array will be ncn$\mathit{ncn}$ where ncn${n}_{\mathrm{cn}}$ is the parameter nwcn returned by function nag_wav_2d_init (c09ab)
ldcvncm$\mathit{ldcv}\ge {n}_{\mathrm{cm}}$ where ncm = nct / (4ncn)${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ncn${n}_{\mathrm{cn}}$, nct${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wav_2d_init (c09ab).
Contains the ncm${n}_{\mathrm{cm}}$ by ncn${n}_{\mathrm{cn}}$ matrix of vertical coefficients, Cv${C}_{v}$.
4:     cd(ldcd, : $:$) – double array
The first dimension of the array cd will be ncm${n}_{\mathrm{cm}}$ where ncm = nct / (4ncn)${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ncn${n}_{\mathrm{cn}}$, nct${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wav_2d_init (c09ab)
The second dimension of the array will be ncn$\mathit{ncn}$ where ncn${n}_{\mathrm{cn}}$ is the parameter nwcn returned by function nag_wav_2d_init (c09ab)
ldcdncm$\mathit{ldcd}\ge {n}_{\mathrm{cm}}$ where ncm = nct / (4ncn)${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ncn${n}_{\mathrm{cn}}$, nct${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wav_2d_init (c09ab).
Contains the ncm${n}_{\mathrm{cm}}$ by ncn${n}_{\mathrm{cn}}$ matrix of diagonal coefficients, Cd${C}_{d}$.
5:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
Constraint: m = m${\mathbf{m}}=m$, the value of m on initialization (see nag_wav_2d_init (c09ab)).
Constraint: n = n${\mathbf{n}}=n$, the value of n on initialization (see nag_wav_2d_init (c09ab)).
ifail = 2${\mathbf{ifail}}=2$
Constraint: ldam$\mathit{lda}\ge {\mathbf{m}}$.
ifail = 3${\mathbf{ifail}}=3$
ldca is too small, the number of wavelet coefficients in the first dimension.
ldcd is too small, the number of wavelet coefficients in the first dimension.
ldch is too small, the number of wavelet coefficients in the first dimension.
ldcv is too small, the number of wavelet coefficients in the first dimension.
ifail = 6${\mathbf{ifail}}=6$
Either the initialization function has not been called first or icomm has been corrupted.
Either the initialization function was called with wtrans = 'M'${\mathbf{wtrans}}=\text{'M'}$ or icomm has been corrupted.
ifail = 999${\mathbf{ifail}}=-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.

None.

## Example

function nag_wav_2d_sngl_fwd_example
m = int64(6);
n = int64(6);
wavnam = 'DB4';
mode = 'Half';
wtrans = 'Single level';
a = [8, 7, 3, 3, 1, 1;
4, 6, 1, 5, 2, 9;
8, 1, 4, 9, 3, 7;
9, 3, 8, 2, 4, 3;
1, 3, 7, 1, 5, 2;
4, 3, 7, 7, 6, 1];

fprintf('\nInput data a:\n');
disp(a);
[nwl, nf, nwct, nwcn, icomm, ifail] = nag_wav_2d_init(wavnam, wtrans, mode, m, n);

nwcm = double(nwct)/(4*double(nwcn));

% Perform Discrete Wavelet transform
[ca, ch, cv, cd, ifail] = nag_wav_2d_sngl_fwd(a, icomm);

fprintf('Approximation coefficients    CA:\n');
disp(ca);
fprintf('Diagonal coefficients         CD:\n');
disp(cd);
fprintf('Horizontal coefficients       CH:\n');
disp(ch);
fprintf('Vertical coefficients         CV:\n');
disp(cv);

% Reconstruct original data
[b, ifail] = nag_wav_2d_sngl_inv(m, n, ca, ch, cv, cd, icomm);
fprintf('Reconstruction       b:\n');
disp(b);

Input data a:
8     7     3     3     1     1
4     6     1     5     2     9
8     1     4     9     3     7
9     3     8     2     4     3
1     3     7     1     5     2
4     3     7     7     6     1

Approximation coefficients    CA:
6.3591   10.3477    8.0995   10.3210    8.7587    3.5783
11.5754    6.3762   12.1704    7.4521    8.6977   14.8535
2.0630    8.4499   15.4726   12.1764    3.8920    2.7112
10.2143    6.2445   13.8571    8.1060    7.7701   13.2127
6.3353    8.7805   10.2727   10.0472    6.8614    7.5814
11.7141   11.1018    5.2923    8.1272   14.5540    2.5729

Diagonal coefficients         CD:
0.4777    1.0230   -0.3147    0.0625    0.0831   -1.3316
1.0689    1.5671   -2.1422    0.5565    1.7593   -2.8097
-0.9555   -1.9276    0.9195   -0.2228   -0.5125    2.6989
0.2899    0.4453   -0.5695    0.1541    0.4749   -0.7946
0.4944    1.4145    0.3488   -0.1187   -0.6212   -1.5177
-1.3753   -2.5224    1.7581   -0.4316   -1.1835    3.7547

Horizontal coefficients       CH:
0.4100   -0.1827    1.5354    0.0784    0.8101   -1.3594
2.3496   -0.9422    2.3780   -1.0540    2.7743   -2.2648
-1.2690    0.0152   -6.9338   -1.7435   -1.6917    1.2388
0.6317   -0.0969    2.3300    0.4637    0.6365   -0.1162
-0.2343    0.3923    5.5457    2.1818    0.2103   -0.8573
-1.8880    0.8142   -4.8552    0.0736   -2.7395    3.3590

Vertical coefficients         CV:
1.5365    5.9678    3.4309   -1.0585   -5.0275   -4.8492
0.6779   -0.0294   -5.3274    1.6483    4.8689   -1.8383
-1.1065   -2.8791    0.1535    0.0982    0.8417    2.8923
-0.1359   -2.6633   -5.8549    1.8440    6.2403    0.5697
1.4244    5.2140    1.6410   -0.4669   -3.2369   -4.5757
1.0288    2.2521    0.0574   -0.1359   -0.5170   -2.6854

Reconstruction       b:
8.0000    7.0000    3.0000    3.0000    1.0000    1.0000
4.0000    6.0000    1.0000    5.0000    2.0000    9.0000
8.0000    1.0000    4.0000    9.0000    3.0000    7.0000
9.0000    3.0000    8.0000    2.0000    4.0000    3.0000
1.0000    3.0000    7.0000    1.0000    5.0000    2.0000
4.0000    3.0000    7.0000    7.0000    6.0000    1.0000

function c09ea_example
m = int64(6);
n = int64(6);
wavnam = 'DB4';
mode = 'Half';
wtrans = 'Single level';
a = [8, 7, 3, 3, 1, 1;
4, 6, 1, 5, 2, 9;
8, 1, 4, 9, 3, 7;
9, 3, 8, 2, 4, 3;
1, 3, 7, 1, 5, 2;
4, 3, 7, 7, 6, 1];

fprintf('\nInput data a:\n');
disp(a);
[nwl, nf, nwct, nwcn, icomm, ifail] = c09ab(wavnam, wtrans, mode, m, n);

nwcm = double(nwct)/(4*double(nwcn));

% Perform Discrete Wavelet transform
[ca, ch, cv, cd, ifail] = c09ea(a, icomm);

fprintf('Approximation coefficients    CA:\n');
disp(ca);
fprintf('Diagonal coefficients         CD:\n');
disp(cd);
fprintf('Horizontal coefficients       CH:\n');
disp(ch);
fprintf('Vertical coefficients         CV:\n');
disp(cv);

% Reconstruct original data
[b, ifail] = c09eb(m, n, ca, ch, cv, cd, icomm);
fprintf('Reconstruction       b:\n');
disp(b);

Input data a:
8     7     3     3     1     1
4     6     1     5     2     9
8     1     4     9     3     7
9     3     8     2     4     3
1     3     7     1     5     2
4     3     7     7     6     1

Approximation coefficients    CA:
6.3591   10.3477    8.0995   10.3210    8.7587    3.5783
11.5754    6.3762   12.1704    7.4521    8.6977   14.8535
2.0630    8.4499   15.4726   12.1764    3.8920    2.7112
10.2143    6.2445   13.8571    8.1060    7.7701   13.2127
6.3353    8.7805   10.2727   10.0472    6.8614    7.5814
11.7141   11.1018    5.2923    8.1272   14.5540    2.5729

Diagonal coefficients         CD:
0.4777    1.0230   -0.3147    0.0625    0.0831   -1.3316
1.0689    1.5671   -2.1422    0.5565    1.7593   -2.8097
-0.9555   -1.9276    0.9195   -0.2228   -0.5125    2.6989
0.2899    0.4453   -0.5695    0.1541    0.4749   -0.7946
0.4944    1.4145    0.3488   -0.1187   -0.6212   -1.5177
-1.3753   -2.5224    1.7581   -0.4316   -1.1835    3.7547

Horizontal coefficients       CH:
0.4100   -0.1827    1.5354    0.0784    0.8101   -1.3594
2.3496   -0.9422    2.3780   -1.0540    2.7743   -2.2648
-1.2690    0.0152   -6.9338   -1.7435   -1.6917    1.2388
0.6317   -0.0969    2.3300    0.4637    0.6365   -0.1162
-0.2343    0.3923    5.5457    2.1818    0.2103   -0.8573
-1.8880    0.8142   -4.8552    0.0736   -2.7395    3.3590

Vertical coefficients         CV:
1.5365    5.9678    3.4309   -1.0585   -5.0275   -4.8492
0.6779   -0.0294   -5.3274    1.6483    4.8689   -1.8383
-1.1065   -2.8791    0.1535    0.0982    0.8417    2.8923
-0.1359   -2.6633   -5.8549    1.8440    6.2403    0.5697
1.4244    5.2140    1.6410   -0.4669   -3.2369   -4.5757
1.0288    2.2521    0.0574   -0.1359   -0.5170   -2.6854

Reconstruction       b:
8.0000    7.0000    3.0000    3.0000    1.0000    1.0000
4.0000    6.0000    1.0000    5.0000    2.0000    9.0000
8.0000    1.0000    4.0000    9.0000    3.0000    7.0000
9.0000    3.0000    8.0000    2.0000    4.0000    3.0000
1.0000    3.0000    7.0000    1.0000    5.0000    2.0000
4.0000    3.0000    7.0000    7.0000    6.0000    1.0000