# NAG FL Interfacec09dcf (dim1_​mxolap_​multi_​fwd)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine c09dcf ( n, x, lenc, c, nwl, na,
 Integer, Intent (In) :: n, lenc, nwl Integer, Intent (Inout) :: icomm(100), ifail Integer, Intent (Out) :: na Real (Kind=nag_wp), Intent (In) :: x(n) Real (Kind=nag_wp), Intent (Out) :: c(lenc) Character (1), Intent (In) :: keepa
#include <nag.h>
 void c09dcf_ (const Integer *n, const double x[], const char *keepa, const Integer *lenc, double c[], const Integer *nwl, Integer *na, Integer icomm[], Integer *ifail, const Charlen length_keepa)
The routine may be called by the names c09dcf or nagf_wav_dim1_mxolap_multi_fwd.

## 3Description

c09dcf computes the multi-level MODWT for a data set, ${\mathit{x}}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, in one dimension. For a chosen number of levels, ${n}_{l}$, with ${n}_{l}\le {l}_{\mathrm{max}}$, where ${l}_{\mathrm{max}}$ is returned by the initialization routine c09aaf in nwlmax, the transform is returned as a set of coefficients for the different levels stored in a single array. Periodic reflection is currently the only available end extension method to reduce the edge effects caused by finite data sets.
The argument keepa can be set to retain both approximation and detail coefficients at each level resulting in ${n}_{l}×\left({n}_{a}+{n}_{d}\right)$ coefficients being returned in the output array, c, where ${n}_{a}$ is the number of approximation coefficients and ${n}_{d}$ is the number of detail coefficients. Otherwise, only the detail coefficients are stored for each level along with the approximation coefficients for the final level, in which case the length of the output array, c, is ${n}_{a}+{n}_{l}×{n}_{d}$. In the present implementation, for simplicity, ${n}_{a}$ and ${n}_{d}$ are chosen to be equal by adding zero padding to the wavelet filters where necessary.

## 4References

Percival D B and Walden A T (2000) Wavelet Methods for Time Series Analysis Cambridge University Press

## 5Arguments

1: $\mathbf{n}$Integer Input
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) array Input
On entry: x contains the input dataset ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3: $\mathbf{keepa}$Character(1) Input
On entry: determines whether the approximation coefficients are stored in array c for every level of the computed transform or else only for the final level. In both cases, the detail coefficients are stored in c for every level computed.
${\mathbf{keepa}}=\text{'A'}$
Retain approximation coefficients for all levels computed.
${\mathbf{keepa}}=\text{'F'}$
Retain approximation coefficients for only the final level computed.
Constraint: ${\mathbf{keepa}}=\text{'A'}$ or $\text{'F'}$.
4: $\mathbf{lenc}$Integer Input
On entry: the dimension of the array c as declared in the (sub)program from which c09dcf is called. c must be large enough to contain the number of wavelet coefficients.
If ${\mathbf{keepa}}=\text{'F'}$, the total number of coefficients, ${n}_{c}$, is returned in nwc by the call to the initialization routine c09aaf and corresponds to the MODWT being continued for the maximum number of levels possible for the given data set. When the number of levels, ${n}_{l}$, is chosen to be less than the maximum, then the number of stored coefficients is correspondingly smaller and lenc can be reduced by noting that ${n}_{d}$ detail coefficients are stored at each level, with the storage increased at the final level to contain the ${n}_{a}$ approximation coefficients.
If ${\mathbf{keepa}}=\text{'A'}$, ${n}_{d}$ detail coefficients and ${n}_{a}$ approximation coefficients are stored for each level computed, requiring ${\mathbf{lenc}}\ge {n}_{l}×\left({n}_{a}+{n}_{d}\right)=2×{n}_{l}×{n}_{a}$, since the numbers of stored approximation and detail coefficients are equal. The number of approximation (or detail) coefficients at each level, ${n}_{a}$, is returned in na.
Constraints:
• if ${\mathbf{keepa}}=\text{'F'}$, ${\mathbf{lenc}}\ge \left({n}_{l}+1\right)×{n}_{a}$;
• if ${\mathbf{keepa}}=\text{'A'}$, ${\mathbf{lenc}}\ge 2×{n}_{l}×{n}_{a}$.
5: $\mathbf{c}\left({\mathbf{lenc}}\right)$Real (Kind=nag_wp) array Output
On exit: the coefficients of a multi-level wavelet transform of the dataset.
The coefficients are stored in c as follows:
If ${\mathbf{keepa}}=\text{'F'}$,
${\mathbf{c}}\left(1:{n}_{a}\right)$
Contains the level ${n}_{l}$ approximation coefficients;
${\mathbf{c}}\left({n}_{a}+\left(i-1\right)×{n}_{d}+1:{n}_{a}+i×{n}_{d}\right)$
Contains the level $\left({n}_{l}-\mathit{i}+1\right)$ detail coefficients, for $\mathit{i}=1,2,\dots ,{n}_{l}$;
If ${\mathbf{keepa}}=\text{'A'}$,
${\mathbf{c}}\left(\left(i-1\right)×{n}_{a}+1:i×{n}_{a}\right)$
Contains the level $\left({n}_{l}-\mathit{i}+1\right)$ approximation coefficients, for $\mathit{i}=1,2,\dots ,{n}_{l}$;
${\mathbf{c}}\left({n}_{l}×{n}_{a}+\left(i-1\right)×{n}_{d}+1:{n}_{l}×{n}_{a}+i×{n}_{d}\right)$
Contains the level i detail coefficients, for $\mathit{i}=1,2,\dots ,{n}_{l}$;
The values ${n}_{a}$ and ${n}_{d}$ denote the numbers of approximation and detail coefficients respectively, which are equal and returned in na.
6: $\mathbf{nwl}$Integer Input
On entry: the number of levels, ${n}_{l}$, in the multi-level resolution to be performed.
Constraint: $1\le {\mathbf{nwl}}\le {l}_{\mathrm{max}}$, where ${l}_{\mathrm{max}}$ is the value returned in nwlmax (the maximum number of levels) by the call to the initialization routine c09aaf.
7: $\mathbf{na}$Integer Output
On exit: na contains the number of approximation coefficients, ${n}_{a}$, at each level which is equal to the number of detail coefficients, ${n}_{d}$. With periodic end extension (${\mathbf{mode}}=\text{'P'}$ in c09aaf) this is the same as the length, n, of the data array, x.
8: $\mathbf{icomm}\left(100\right)$Integer array Communication 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.
9: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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}}=2$
On entry, ${\mathbf{keepa}}=⟨\mathit{\text{value}}⟩$ was an illegal value.
${\mathbf{ifail}}=4$
On entry, lenc is set too small: ${\mathbf{lenc}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{lenc}}\ge ⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=6$
On entry, ${\mathbf{nwl}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nwl}}\ge 1$.
On entry, nwl is larger than the maximum number of levels returned by the initialization function: ${\mathbf{nwl}}=⟨\mathit{\text{value}}⟩$, maximum = $⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=8$
On entry, the initialization routine c09aaf has not been called first or it has not been called with ${\mathbf{wtrans}}=\text{'U'}$, or the communication array icomm has become corrupted.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface 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

c09dcf is not threaded in any implementation.

The wavelet coefficients at each level can be extracted from the output array c using the information contained in na on exit.

## 10Example

A set of data values (${\mathbf{n}}=64$) is decomposed using the MODWT over two levels and then the inverse (c09ddf) is applied to restore the original data set.

### 10.1Program Text

Program Text (c09dcfe.f90)

### 10.2Program Data

Program Data (c09dcfe.d)

### 10.3Program Results

Program Results (c09dcfe.r)