# NAG C Library Function Document

## 1Purpose

nag_wfilt_2d (c09abc) returns the details of the chosen two-dimensional discrete wavelet filter. For a chosen mother wavelet, discrete wavelet transform type (single-level or multi-level DWT) and end extension method, this function returns the maximum number of levels of resolution (appropriate to a multi-level transform), the filter length, the total number of approximation, horizontal, vertical and diagonal coefficients and the number of coefficients in the second dimension for the single-level case. This function must be called before any of the two-dimensional transform functions in this chapter.

## 2Specification

 #include #include
 void nag_wfilt_2d (Nag_Wavelet wavnam, Nag_WaveletTransform wtrans, Nag_WaveletMode mode, Integer m, Integer n, Integer *nwlmax, Integer *nf, Integer *nwct, Integer *nwcn, Integer icomm[], NagError *fail)

## 3Description

Two-dimensional discrete wavelet transforms (DWT) are characterised by the mother wavelet, the end extension method and whether multiresolution analysis is to be performed. For the selected combination of choices for these three characteristics, and for given dimensions ($m×n$) of data matrix $A$, nag_wfilt_2d (c09abc) returns the dimension details for the transform determined by this combination. The dimension details are: ${l}_{\mathrm{max}}$, the maximum number of levels of resolution that would be computed were a multi-level DWT applied; ${n}_{f}$, the filter length; ${n}_{\mathrm{ct}}$ the total number of approximation, horizontal, vertical and diagonal coefficients (over all levels in the multi-level DWT case); and ${n}_{\mathrm{cn}}$, the number of coefficients in the second dimension for a single-level DWT. These values are also stored in the communication array icomm, as are the input choices, so that they may be conveniently communicated to the two-dimensional transform functions in this chapter.

None.

## 5Arguments

1:    $\mathbf{wavnam}$Nag_WaveletInput
On entry: the name of the mother wavelet. See the c09 Chapter Introduction for details.
${\mathbf{wavnam}}=\mathrm{Nag_Haar}$
Haar wavelet.
${\mathbf{wavnam}}=\mathrm{Nag_Daubechies}\mathbit{n}$, where $\mathbit{n}=2,3,\dots ,38$
Daubechies wavelet with $\mathbit{n}$ vanishing moments ($2\mathbit{n}$ coefficients). For example, ${\mathbf{wavnam}}=\mathrm{Nag_Daubechies4}$ is the name for the Daubechies wavelet with $4$ vanishing moments ($8$ coefficients).
${\mathbf{wavnam}}=\mathrm{Nag_Coiflet}\mathbit{n}$, where $\mathbit{n}=1,2,\dots ,17$
Coiflet wavelet of order $\mathbit{n}$.
${\mathbf{wavnam}}=\mathrm{Nag_Beylkin}$
Beylkin wavelet.
${\mathbf{wavnam}}=\mathrm{Nag_Vaidyanathan}$
Vaidyanathan wavelet.
${\mathbf{wavnam}}=\mathrm{Nag_Symlet}\mathbit{n}$, where $\mathbit{n}=2,3,\dots ,20$
Symlet wavelet of order $\mathbit{n}$.
${\mathbf{wavnam}}=\mathrm{Nag_Biorthogonal}\mathbit{x}_\mathbit{y}$, where $\mathbit{x}_\mathbit{y}$ can be one of 1_1, 1_3, 1_5, 2_2, 2_4, 2_6, 2_8, 3_1, 3_3, 3_5, 3_7, 3_9, 4_4, 5_5 or 6_8
Biorthogonal wavelet of order $\mathbit{x}.\mathbit{y}$. For example ${\mathbf{wavnam}}=\mathrm{Nag_Biorthogonal1_1}$ is the name for the Biorthogonal wavelet of order $1.1$.
${\mathbf{wavnam}}=\mathrm{Nag_Reverse_Biorthogonal}\mathbit{x}_\mathbit{y}$, where $\mathbit{x}_\mathbit{y}$ can be one of 1_1, 1_3, 1_5, 2_2, 2_4, 2_6, 2_8, 3_1, 3_3, 3_5, 3_7, 3_9, 4_4, 5_5 or 6_8
Reverse biorthogonal wavelet of order $\mathbit{x}.\mathbit{y}$. For example ${\mathbf{wavnam}}=\mathrm{Nag_Reverse_Biorthogonal1_1}$ is the name for the reverse biorthogonal wavelet of order $1.1$.
Constraint: ${\mathbf{wavnam}}=\mathrm{Nag_Haar}$, $\mathrm{Nag_Daubechies2}$, $\mathrm{Nag_Daubechies3}$, $\mathrm{Nag_Daubechies4}$, $\mathrm{Nag_Daubechies5}$, $\mathrm{Nag_Daubechies6}$, $\mathrm{Nag_Daubechies7}$, $\mathrm{Nag_Daubechies8}$, $\mathrm{Nag_Daubechies9}$, $\mathrm{Nag_Daubechies10}$, $\mathrm{Nag_Daubechies11}$, $\mathrm{Nag_Daubechies12}$, $\mathrm{Nag_Daubechies13}$, $\mathrm{Nag_Daubechies14}$, $\mathrm{Nag_Daubechies15}$, $\mathrm{Nag_Daubechies16}$, $\mathrm{Nag_Daubechies17}$, $\mathrm{Nag_Daubechies18}$, $\mathrm{Nag_Daubechies19}$, $\mathrm{Nag_Daubechies20}$, $\mathrm{Nag_Daubechies21}$, $\mathrm{Nag_Daubechies22}$, $\mathrm{Nag_Daubechies23}$, $\mathrm{Nag_Daubechies24}$, $\mathrm{Nag_Daubechies25}$, $\mathrm{Nag_Daubechies26}$, $\mathrm{Nag_Daubechies27}$, $\mathrm{Nag_Daubechies28}$, $\mathrm{Nag_Daubechies29}$, $\mathrm{Nag_Daubechies30}$, $\mathrm{Nag_Daubechies31}$, $\mathrm{Nag_Daubechies32}$, $\mathrm{Nag_Daubechies33}$, $\mathrm{Nag_Daubechies34}$, $\mathrm{Nag_Daubechies35}$, $\mathrm{Nag_Daubechies36}$, $\mathrm{Nag_Daubechies37}$, $\mathrm{Nag_Daubechies38}$, $\mathrm{Nag_Coiflet1}$, $\mathrm{Nag_Coiflet2}$, $\mathrm{Nag_Coiflet3}$, $\mathrm{Nag_Coiflet4}$, $\mathrm{Nag_Coiflet5}$, $\mathrm{Nag_Coiflet6}$, $\mathrm{Nag_Coiflet7}$, $\mathrm{Nag_Coiflet8}$, $\mathrm{Nag_Coiflet9}$, $\mathrm{Nag_Coiflet10}$, $\mathrm{Nag_Coiflet11}$, $\mathrm{Nag_Coiflet12}$, $\mathrm{Nag_Coiflet13}$, $\mathrm{Nag_Coiflet14}$, $\mathrm{Nag_Coiflet15}$, $\mathrm{Nag_Coiflet16}$, $\mathrm{Nag_Coiflet17}$, $\mathrm{Nag_Beylkin}$, $\mathrm{Nag_Vaidyanathan}$, $\mathrm{Nag_Symlet2}$, $\mathrm{Nag_Symlet3}$, $\mathrm{Nag_Symlet4}$, $\mathrm{Nag_Symlet5}$, $\mathrm{Nag_Symlet6}$, $\mathrm{Nag_Symlet7}$, $\mathrm{Nag_Symlet8}$, $\mathrm{Nag_Symlet9}$, $\mathrm{Nag_Symlet10}$, $\mathrm{Nag_Symlet11}$, $\mathrm{Nag_Symlet12}$, $\mathrm{Nag_Symlet13}$, $\mathrm{Nag_Symlet14}$, $\mathrm{Nag_Symlet15}$, $\mathrm{Nag_Symlet16}$, $\mathrm{Nag_Symlet17}$, $\mathrm{Nag_Symlet18}$, $\mathrm{Nag_Symlet19}$, $\mathrm{Nag_Symlet20}$, $\mathrm{Nag_Biorthogonal1_1}$, $\mathrm{Nag_Biorthogonal1_3}$, $\mathrm{Nag_Biorthogonal1_5}$, $\mathrm{Nag_Biorthogonal2_2}$, $\mathrm{Nag_Biorthogonal2_4}$, $\mathrm{Nag_Biorthogonal2_6}$, $\mathrm{Nag_Biorthogonal2_8}$, $\mathrm{Nag_Biorthogonal3_1}$, $\mathrm{Nag_Biorthogonal3_3}$, $\mathrm{Nag_Biorthogonal3_5}$, $\mathrm{Nag_Biorthogonal3_7}$, $\mathrm{Nag_Biorthogonal3_9}$, $\mathrm{Nag_Biorthogonal4_4}$, $\mathrm{Nag_Biorthogonal5_5}$, $\mathrm{Nag_Biorthogonal6_8}$, $\mathrm{Nag_Reverse_Biorthogonal1_1}$, $\mathrm{Nag_Reverse_Biorthogonal1_3}$, $\mathrm{Nag_Reverse_Biorthogonal1_5}$, $\mathrm{Nag_Reverse_Biorthogonal2_2}$, $\mathrm{Nag_Reverse_Biorthogonal2_4}$, $\mathrm{Nag_Reverse_Biorthogonal2_6}$, $\mathrm{Nag_Reverse_Biorthogonal2_8}$, $\mathrm{Nag_Reverse_Biorthogonal3_1}$, $\mathrm{Nag_Reverse_Biorthogonal3_3}$, $\mathrm{Nag_Reverse_Biorthogonal3_5}$, $\mathrm{Nag_Reverse_Biorthogonal3_7}$, $\mathrm{Nag_Reverse_Biorthogonal3_9}$, $\mathrm{Nag_Reverse_Biorthogonal4_4}$, $\mathrm{Nag_Reverse_Biorthogonal5_5}$ or $\mathrm{Nag_Reverse_Biorthogonal6_8}$.
2:    $\mathbf{wtrans}$Nag_WaveletTransformInput
On entry: the type of discrete wavelet transform that is to be applied.
${\mathbf{wtrans}}=\mathrm{Nag_SingleLevel}$
Single-level decomposition or reconstruction by discrete wavelet transform.
${\mathbf{wtrans}}=\mathrm{Nag_MultiLevel}$
Multiresolution, by a multi-level DWT or its inverse.
Constraint: ${\mathbf{wtrans}}=\mathrm{Nag_SingleLevel}$ or $\mathrm{Nag_MultiLevel}$.
3:    $\mathbf{mode}$Nag_WaveletModeInput
On entry: the end extension method.
${\mathbf{mode}}=\mathrm{Nag_Periodic}$
Periodic end extension.
${\mathbf{mode}}=\mathrm{Nag_HalfPointSymmetric}$
Half-point symmetric end extension.
${\mathbf{mode}}=\mathrm{Nag_WholePointSymmetric}$
Whole-point symmetric end extension.
${\mathbf{mode}}=\mathrm{Nag_ZeroPadded}$
Zero end extension.
Constraint: ${\mathbf{mode}}=\mathrm{Nag_Periodic}$, $\mathrm{Nag_HalfPointSymmetric}$, $\mathrm{Nag_WholePointSymmetric}$ or $\mathrm{Nag_ZeroPadded}$.
4:    $\mathbf{m}$IntegerInput
On entry: the number of elements, $m$, in the first dimension (number of rows of data matrix $A$) of the input data.
Constraint: ${\mathbf{m}}\ge 2$.
5:    $\mathbf{n}$IntegerInput
On entry: the number of elements, $n$, in the second dimension (number of columns of data matrix $A$) of the input data.
Constraint: ${\mathbf{n}}\ge 2$.
6:    $\mathbf{nwlmax}$Integer *Output
On exit: the maximum number of levels of resolution, ${l}_{\mathrm{max}}$, that can be computed if a multi-level discrete wavelet transform is applied (${\mathbf{wtrans}}=\mathrm{Nag_MultiLevel}$). It is such that ${2}^{{l}_{\mathrm{max}}}\le \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)<{2}^{{l}_{\mathrm{max}}+1}$, for ${l}_{\mathrm{max}}$ an integer.
If ${\mathbf{wtrans}}=\mathrm{Nag_SingleLevel}$, nwlmax is not set.
7:    $\mathbf{nf}$Integer *Output
On exit: the filter length, ${n}_{f}$, for the supplied mother wavelet. This is used to determine the number of coefficients to be generated by the chosen transform.
8:    $\mathbf{nwct}$Integer *Output
On exit: the total number of wavelet coefficients, ${n}_{\mathrm{ct}}$, that will be generated. When ${\mathbf{wtrans}}=\mathrm{Nag_SingleLevel}$ the number of rows required in each of the output coefficient matrices can be calculated as ${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$. When ${\mathbf{wtrans}}=\mathrm{Nag_MultiLevel}$ the length of the array used to store all of the coefficient matrices must be at least ${n}_{\mathrm{ct}}$.
9:    $\mathbf{nwcn}$Integer *Output
On exit: for a single-level transform (${\mathbf{wtrans}}=\mathrm{Nag_SingleLevel}$), the number of coefficients that would be generated in the second dimension, ${n}_{\mathrm{cn}}$, for each coefficient type. For a multi-level transform (${\mathbf{wtrans}}=\mathrm{Nag_MultiLevel}$) this is set to $1$.
10:  $\mathbf{icomm}\left[180\right]$IntegerCommunication Array
On exit: contains details of the wavelet transform and the problem dimension which is to be communicated to the two-dimensional discrete transform functions in this chapter.
11:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 2$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 2$.
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.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

## 8Parallelism and Performance

nag_wfilt_2d (c09abc) is not threaded in any implementation.

None.

## 10Example

This example computes the two-dimensional multi-level resolution for a $6×6$ matrix by a discrete wavelet transform using the Haar wavelet with whole-point symmetric end extensions. The number of levels of transformation actually performed is one less than the maximum possible. This number of levels, the length of the wavelet filter, the total number of coefficients and the number of coefficients in each dimension for each level are printed along with the vertical detail coefficients from the first level, before a reconstruction is performed.

### 10.1Program Text

Program Text (c09abce.c)

### 10.2Program Data

Program Data (c09abce.d)

### 10.3Program Results

Program Results (c09abce.r)