c09 Chapter Contents
c09 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_dwt_2d (c09eac)

## 1  Purpose

nag_dwt_2d (c09eac) computes the two-dimensional discrete wavelet transform (DWT) at a single level. The initialization function nag_wfilt_2d (c09abc) must be called first to set up the DWT options.

## 2  Specification

 #include #include
 void nag_dwt_2d (Integer m, Integer n, const double a[], Integer lda, double ca[], Integer ldca, double ch[], Integer ldch, double cv[], Integer ldcv, double cd[], Integer ldcd, const Integer icomm[], NagError *fail)

## 3  Description

nag_dwt_2d (c09eac) computes the two-dimensional DWT of a given input data array, considered as a matrix $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$, first over columns and then to the result over rows. The matrix of approximation (or smooth) coefficients, ${C}_{a}$, is produced by the low pass filter over columns and rows; the matrix of horizontal coefficients, ${C}_{h}$, is produced by the low pass filter over columns and the high pass filter over rows; the matrix of vertical coefficients, ${C}_{v}$, is produced by the high pass filter over columns and the low pass filter over rows; and the matrix of diagonal coefficients, ${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, ${n}_{\mathrm{ct}}$, of coefficients computed for ${C}_{a}$, ${C}_{h}$, ${C}_{v}$, and ${C}_{d}$ together and the number of columns of each coefficients matrix, ${n}_{\mathrm{cn}}$, are returned by the initialization function nag_wfilt_2d (c09abc). These values can be used to calculate the number of rows of each coefficients matrix, ${n}_{\mathrm{cm}}$, using the formula ${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$.

## 4  References

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

## 5  Arguments

1:     mIntegerInput
On entry: number of rows, $m$, of data matrix $A$.
Constraint: this must be the same as the value m passed to the initialization function nag_wfilt_2d (c09abc).
2:     nIntegerInput
On entry: number of columns, $n$, of data matrix $A$.
Constraint: this must be the same as the value n passed to the initialization function nag_wfilt_2d (c09abc).
3:     a[${\mathbf{lda}}×{\mathbf{n}}$]const doubleInput
Note: the $\left(i,j\right)$th element of the matrix $A$ is stored in ${\mathbf{a}}\left[\left(j-1\right)×{\mathbf{lda}}+i-1\right]$.
On entry: the $m$ by $n$ data matrix $A$.
4:     ldaIntegerInput
On entry: the stride separating matrix row elements in the array a.
Constraint: ${\mathbf{lda}}\ge {\mathbf{m}}$.
5:     ca[$\mathit{dim}$]doubleOutput
Note: the dimension, dim, of the array ca must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ldca}}×{n}_{\mathrm{cn}}\right)$ where ${n}_{\mathrm{cn}}$ is the argument nwcn returned by function nag_wfilt_2d (c09abc).
The $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{ca}}\left[\left(j-1\right)×{\mathbf{ldca}}+i-1\right]$.
On exit: contains the ${n}_{\mathrm{cm}}$ by ${n}_{\mathrm{cn}}$ matrix of approximation coefficients, ${C}_{a}$.
6:     ldcaIntegerInput
On entry: the stride separating matrix row elements in the array ca.
Constraint: ${\mathbf{ldca}}\ge {n}_{\mathrm{cm}}$ where ${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ${n}_{\mathrm{cn}}$, ${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wfilt_2d (c09abc).
7:     ch[$\mathit{dim}$]doubleOutput
Note: the dimension, dim, of the array ch must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ldch}}×{n}_{\mathrm{cn}}\right)$ where ${n}_{\mathrm{cn}}$ is the argument nwcn returned by function nag_wfilt_2d (c09abc).
The $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{ch}}\left[\left(j-1\right)×{\mathbf{ldch}}+i-1\right]$.
On exit: contains the ${n}_{\mathrm{cm}}$ by ${n}_{\mathrm{cn}}$ matrix of horizontal coefficients, ${C}_{h}$.
8:     ldchIntegerInput
On entry: the stride separating matrix row elements in the array ch.
Constraint: ${\mathbf{ldch}}\ge {n}_{\mathrm{cm}}$ where ${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ${n}_{\mathrm{cn}}$, ${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wfilt_2d (c09abc).
9:     cv[$\mathit{dim}$]doubleOutput
Note: the dimension, dim, of the array cv must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ldcv}}×{n}_{\mathrm{cn}}\right)$ where ${n}_{\mathrm{cn}}$ is the argument nwcn returned by function nag_wfilt_2d (c09abc).
The $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{cv}}\left[\left(j-1\right)×{\mathbf{ldcv}}+i-1\right]$.
On exit: contains the ${n}_{\mathrm{cm}}$ by ${n}_{\mathrm{cn}}$ matrix of vertical coefficients, ${C}_{v}$.
10:   ldcvIntegerInput
On entry: the stride separating matrix row elements in the array cv.
Constraint: ${\mathbf{ldcv}}\ge {n}_{\mathrm{cm}}$ where ${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ${n}_{\mathrm{cn}}$, ${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wfilt_2d (c09abc).
11:   cd[$\mathit{dim}$]doubleOutput
Note: the dimension, dim, of the array cd must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{ldcd}}×{n}_{\mathrm{cn}}\right)$ where ${n}_{\mathrm{cn}}$ is the argument nwcn returned by function nag_wfilt_2d (c09abc).
The $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{cd}}\left[\left(j-1\right)×{\mathbf{ldcd}}+i-1\right]$.
On exit: contains the ${n}_{\mathrm{cm}}$ by ${n}_{\mathrm{cn}}$ matrix of diagonal coefficients, ${C}_{d}$.
12:   ldcdIntegerInput
On entry: the stride separating matrix row elements in the array cd.
Constraint: ${\mathbf{ldcd}}\ge {n}_{\mathrm{cm}}$ where ${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ${n}_{\mathrm{cn}}$, ${n}_{\mathrm{ct}}$ are returned by the initialization function nag_wfilt_2d (c09abc).
13:   icomm[$180$]const IntegerCommunication Array
On entry: contains details of the discrete wavelet transform and the problem dimension as setup in the call to the initialization function nag_wfilt_2d (c09abc).
14:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INITIALIZATION
Either the initialization function has not been called first or icomm has been corrupted.
Either the initialization function was called with ${\mathbf{wtrans}}=\mathrm{Nag_MultiLevel}$ or icomm has been corrupted.
NE_INT
On entry, ${\mathbf{ldca}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldca}}\ge 〈\mathit{\text{value}}〉$, the number of wavelet coefficients in the first dimension.
On entry, ${\mathbf{ldcd}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldcd}}\ge 〈\mathit{\text{value}}〉$, the number of wavelet coefficients in the first dimension.
On entry, ${\mathbf{ldch}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldch}}\ge 〈\mathit{\text{value}}〉$, the number of wavelet coefficients in the first dimension.
On entry, ${\mathbf{ldcv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldcv}}\ge 〈\mathit{\text{value}}〉$, the number of wavelet coefficients in the first dimension.
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}=〈\mathit{\text{value}}〉$, the value of m on initialization (see nag_wfilt_2d (c09abc)).
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}=〈\mathit{\text{value}}〉$, the value of n on initialization (see nag_wfilt_2d (c09abc)).
NE_INT_2
On entry, ${\mathbf{lda}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lda}}\ge {\mathbf{m}}$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.

## 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 two-dimensional discrete wavelet decomposition for a $6×6$ input matrix using the Daubechies wavelet, ${\mathbf{wavnam}}=\mathrm{Nag_Daubechies4}$, with half point symmetric end extension.

### 9.1  Program Text

Program Text (c09eace.c)

### 9.2  Program Data

Program Data (c09eace.d)

### 9.3  Program Results

Program Results (c09eace.r)