# NAG Library Routine Document

## 1Purpose

c09ddf computes the inverse one-dimensional multi-level maximal overlap discrete wavelet transform (MODWT). This routine reconstructs data from (possibly filtered or otherwise manipulated) wavelet transform coefficients calculated by c09dcf from an original set of data. The initialization routine c09aaf must be called first to set up the MODWT options.

## 2Specification

Fortran Interface
 Subroutine c09ddf ( lenc, c, n, y,
 Integer, Intent (In) :: nwlinv, lenc, n, icomm(100) Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: c(lenc) Real (Kind=nag_wp), Intent (Out) :: y(n) Character (1), Intent (In) :: keepa
#include nagmk26.h
 void c09ddf_ (const Integer *nwlinv, const char *keepa, const Integer *lenc, const double c[], const Integer *n, double y[], const Integer icomm[], Integer *ifail, const Charlen length_keepa)

## 3Description

c09ddf performs the inverse operation of c09dcf. That is, given a set of wavelet coefficients computed by c09dcf using a MODWT as set up by the initialization routine c09aaf on a real array of length $n$, c09ddf will reconstruct the data array ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, from which the coefficients were derived.

## 4References

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

## 5Arguments

1:     $\mathbf{nwlinv}$ – IntegerInput
On entry: the number of levels to be used in the inverse multi-level transform. The number of levels must be less than or equal to ${n}_{\mathrm{fwd}}$, which has the value of argument nwl as used in the computation of the wavelet coefficients using c09dcf. The data will be reconstructed to level $\left({\mathbf{nwl}}-{\mathbf{nwlinv}}\right)$, where level $0$ is the original input dataset provided to c09dcf.
Constraint: $1\le {\mathbf{nwlinv}}\le {\mathbf{nwl}}$, where nwl is the value used in a preceding call to c09dcf.
2:     $\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'}$.
3:     $\mathbf{lenc}$ – IntegerInput
On entry: the dimension of the array c as declared in the (sub)program from which c09ddf is called.
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}$, where ${n}_{a}$ is the number of approximation or detail coefficients at each level and is unchanged from the preceding call to c09dcf.
4:     $\mathbf{c}\left({\mathbf{lenc}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: 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 $\mathit{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. This number is returned as output in na from a preceding call to c09dcf. See c09dcf for details.
5:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the length of the data array, $y$, to be reconstructed.
Constraint: This must be the same as the value n passed to the initialization routine c09aaf.
6:     $\mathbf{y}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the dataset reconstructed from the multi-level wavelet transform coefficients and the transformation options supplied to the initialization routine c09aaf.
7:     $\mathbf{icomm}\left(100\right)$ – Integer arrayCommunication Array
On entry: contains details of the discrete wavelet transform and the problem dimension for the forward transform previously computed by c09dcf.
8:     $\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, ${\mathbf{nwlinv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nwlinv}}\ge 1$.
On entry, nwlinv is larger than the number of levels computed by the preceding call to c09dcf: ${\mathbf{nwlinv}}=〈\mathit{\text{value}}〉$, expected $〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{keepa}}=〈\mathit{\text{value}}〉$ was an illegal value.
${\mathbf{ifail}}=3$
On entry, lenc is set too small: ${\mathbf{lenc}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lenc}}\ge 〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=5$
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}}=7$
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 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

c09ddf is not threaded in any implementation.