# NAG Library Routine Document

## 1Purpose

c09daf computes the one-dimensional maximal overlap discrete wavelet transform (MODWT) at a single level. The initialization routine c09aaf must be called first to set up the MODWT options.

## 2Specification

Fortran Interface
 Subroutine c09daf ( n, x, lenc, ca, cd,
 Integer, Intent (In) :: n, lenc Integer, Intent (Inout) :: icomm(100), ifail Real (Kind=nag_wp), Intent (In) :: x(n) Real (Kind=nag_wp), Intent (Out) :: ca(lenc), cd(lenc)
#include nagmk26.h
 void c09daf_ (const Integer *n, const double x[], const Integer *lenc, double ca[], double cd[], Integer icomm[], Integer *ifail)

## 3Description

c09daf computes the one-dimensional MODWT of a given input data array, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, at a single level. For a chosen wavelet filter pair, the output coefficients are obtained by applying convolution to the input, $x$. The approximation (or smooth) coefficients, ${C}_{a}$, are produced by the low pass filter and the detail coefficients, ${C}_{d}$, by the high pass filter. Periodic (circular) convolution is available as an end extension method for application to finite data sets. The number ${n}_{c}$, of coefficients ${C}_{a}$ or ${C}_{d}$ is returned by the initialization routine c09aaf.
Percival D B and Walden A T (2000) Wavelet Methods for Time Series Analysis Cambridge University Press

## 5Arguments

1:     $\mathbf{n}$ – IntegerInput
On entry: the number of elements, $n$, in the data array $x$.
Constraint: this must be the same as the value n passed to the initialization routine c09aaf.
2:     $\mathbf{x}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: x contains the input dataset ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3:     $\mathbf{lenc}$ – IntegerInput
On entry: the dimension of the arrays ca and cd as declared in the (sub)program from which c09daf is called. This must be at least the number, ${n}_{c}$, of approximation coefficients, ${C}_{a}$, and detail coefficients, ${C}_{d}$, of the discrete wavelet transform as returned in nwc by the call to the initialization routine c09aaf. Note that ${n}_{c}=n$ for periodic end extension, but this is not the case for other end extension methods which will be available in future releases.
Constraint: ${\mathbf{lenc}}\ge {n}_{c}$, where ${n}_{c}$ is the value returned in nwc by the call to the initialization routine c09aaf.
4:     $\mathbf{ca}\left({\mathbf{lenc}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{ca}}\left(i\right)$ contains the $i$th approximation coefficient, ${C}_{a}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{n}_{c}$.
5:     $\mathbf{cd}\left({\mathbf{lenc}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{cd}}\left(\mathit{i}\right)$ contains the $\mathit{i}$th detail coefficient, ${C}_{d}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{n}_{c}$.
6:     $\mathbf{icomm}\left(100\right)$ – 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 c09aaf.
On exit: contains additional information on the computed transform.
7:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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, n is inconsistent with the value passed to the initialization routine: ${\mathbf{n}}=〈\mathit{\text{value}}〉$, n should be $〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=3$
On entry, array dimension lenc not large enough: ${\mathbf{lenc}}=〈\mathit{\text{value}}〉$ but must be at least $〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=6$
On entry, the initialization routine c09aaf has not been called first or it has not been called with ${\mathbf{wtrans}}=\text{'T'}$, or the communication array icomm has become corrupted.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

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.

## 8Parallelism and Performance

c09daf is not threaded in any implementation.

None.

## 10Example

This example computes the one-dimensional maximal overlap discrete wavelet decomposition for $8$ values using the Daubechies wavelet, ${\mathbf{wavnam}}=\text{'DB4'}$.

### 10.1Program Text

Program Text (c09dafe.f90)

### 10.2Program Data

Program Data (c09dafe.d)

### 10.3Program Results

Program Results (c09dafe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017