C09 Chapter Contents
C09 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentC09FAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

C09FAF computes the three-dimensional discrete wavelet transform (DWT) at a single level. The initialization routine C09ACF must be called first to set up the DWT options.

## 2  Specification

 SUBROUTINE C09FAF ( M, N, FR, A, LDA, SDA, LENC, C, ICOMM, IFAIL)
 INTEGER M, N, FR, LDA, SDA, LENC, ICOMM(260), IFAIL REAL (KIND=nag_wp) A(LDA,SDA,FR), C(LENC)

## 3  Description

C09FAF computes the three-dimensional DWT of a given input three-dimensional data array, considered as a number of two-dimensional frames, 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$, first over columns, next over rows and finally across frames. The three-dimensional approximation coefficients are produced by the low pass filter over columns, rows and frames. In addition there are 7 sets of three-dimensional detail coefficients, each corresponding to a different order of low pass and high pass filters (see the C09 Chapter Introduction). All coefficients are packed into a single array. 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, ${n}_{\mathrm{ct}}$, of coefficients computed is returned by the initialization routine C09ACF.

## 4  References

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

## 5  Parameters

1:     M – INTEGERInput
On entry: 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 routine C09ACF.
2:     N – INTEGERInput
On entry: 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 routine C09ACF.
3:     FR – INTEGERInput
On entry: 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 routine C09ACF.
4:     A(LDA,SDA,FR) – REAL (KIND=nag_wp) arrayInput
On entry: the $m$ by $n$ by $\mathit{fr}$ input three-dimensional array $A$.
5:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which C09FAF is called.
Constraint: ${\mathbf{LDA}}\ge {\mathbf{M}}$.
6:     SDA – INTEGERInput
On entry: the second dimension of the array A as declared in the (sub)program from which C09FAF is called.
Constraint: ${\mathbf{SDA}}\ge {\mathbf{N}}$.
7:     LENC – INTEGERInput
On entry: the dimension of the array C as declared in the (sub)program from which C09FAF is called.
Constraint: ${\mathbf{LENC}}\ge {n}_{\mathrm{ct}}$, where ${n}_{\mathrm{ct}}$ is the total number of wavelet coefficients, as returned by C09ACF.
8:     C(LENC) – REAL (KIND=nag_wp) arrayOutput
On exit: the coefficients of the discrete wavelet transform. The $8$ sets of coefficients are stored in the following order: approximation coefficients (LLL) first, followed by $7$ sets of detail coefficients: LLH, LHL, LHH, HLL, HLH, HHL, HHH, where L indicates the low pass filter, and H the high pass filter being applied to, respectively, the columns of length M, the rows of length N and then the frames of length FR. Note that for computational efficiency reasons each set of coefficients is stored in the order ${n}_{\mathrm{cfr}}×{n}_{\mathrm{cm}}×{n}_{\mathrm{cn}}$ (see output parameters NWCFR, NWCT and NWCN in C09ACF). See Section 9 for details of how to access each set of coefficients in order to perform extraction from C following a call to this routine, or insertion into C before a call to the three-dimensional inverse routine C09FBF.
9:     ICOMM($260$) – INTEGER arrayCommunication Array
On entry: contains details of the discrete wavelet transform and the problem dimension as setup in the call to the initialization routine C09ACF.
On exit: contains additional information on the computed transform.
10:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{FR}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{FR}}=⟨\mathit{\text{value}}⟩$, the value of FR on initialization (see C09ACF).
On entry, ${\mathbf{M}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{M}}=⟨\mathit{\text{value}}⟩$, the value of M on initialization (see C09ACF).
On entry, ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$, the value of N on initialization (see C09ACF).
${\mathbf{IFAIL}}=2$
On entry, ${\mathbf{LDA}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{M}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LDA}}\ge {\mathbf{M}}$.
On entry, ${\mathbf{SDA}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{SDA}}\ge {\mathbf{N}}$.
${\mathbf{IFAIL}}=3$
On entry, ${\mathbf{LENC}}=⟨\mathit{\text{value}}⟩$ and ${n}_{\mathrm{ct}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LENC}}\ge {n}_{\mathrm{ct}}$, where ${n}_{\mathrm{ct}}$ is the number of DWT coefficients returned by C09ACF in parameter NWCT.
${\mathbf{IFAIL}}=6$
Either the initialization routine C09ACF has not been called first or the communication array ICOMM has been corrupted.
The initialization routine was called with ${\mathbf{WTRANS}}=\text{'M'}$.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.

## 7  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.

## 9  Example

This example computes the three-dimensional discrete wavelet decomposition for $5×4×3$ input data using the Haar wavelet, ${\mathbf{WAVNAM}}=\text{'HAAR'}$, with half point end extension, prints the wavelet coefficients and then reconstructs the original data using C09FBF. This example also demonstrates in general how to access any set of coefficients following a single level transform.

### 9.1  Program Text

Program Text (c09fafe.f90)

### 9.2  Program Data

Program Data (c09fafe.d)

### 9.3  Program Results

Program Results (c09fafe.r)