c09cc computes the one-dimensional multi-level discrete wavelet transform (DWT). The initialization method C09 Communication class constructor must be called first to set up the DWT options.

# Syntax

C#
```public static void c09cc(
int n,
double[] x,
double[] c,
int[] dwtlev,
C09..::..C09Communications communications,
out int ifail
)```
Visual Basic
```Public Shared Sub c09cc ( _
n As Integer, _
x As Double(), _
c As Double(), _
dwtlev As Integer(), _
communications As C09..::..C09Communications, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void c09cc(
int n,
array<double>^ x,
array<double>^ c,
array<int>^ dwtlev,
C09..::..C09Communications^ communications,
[OutAttribute] int% ifail
)```
F#
```static member c09cc :
n : int *
x : float[] *
c : float[] *
dwtlev : int[] *
communications : C09..::..C09Communications *
ifail : int byref -> unit
```

#### Parameters

n
Type: System..::..Int32
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 method c09aa.
x
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: x contains the one-dimensional input dataset ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
c
Type: array<System..::..Double>[]()[][]
An array of size [lenc]
On exit: let $q\left(\mathit{i}\right)$ denote the number of coefficients (of each type) produced by the wavelet transform at level $\mathit{i}$, for $\mathit{i}={n}_{\mathrm{fwd}},{n}_{\mathrm{fwd}}-1,\dots ,1$. These values are returned in dwtlev. Setting ${k}_{1}=q\left({n}_{\mathrm{fwd}}\right)$ and ${k}_{\mathit{j}+1}={k}_{\mathit{j}}+q\left({n}_{\mathrm{fwd}}-\mathit{j}+1\right)$, for $\mathit{j}=1,2,\dots ,{n}_{\mathrm{fwd}}$, the coefficients are stored as follows:
${\mathbf{c}}\left[\mathit{i}-1\right]$, for $\mathit{i}=1,2,\dots ,{k}_{1}$
Contains the level ${n}_{\mathrm{fwd}}$ approximation coefficients, ${a}_{{n}_{\mathrm{fwd}}}$.
${\mathbf{c}}\left[\mathit{i}-1\right]$, for $\mathit{i}={k}_{1}+1,\dots ,{k}_{2}$
Contains the level ${n}_{\mathrm{fwd}}$ detail coefficients ${d}_{{n}_{\mathrm{fwd}}}$.
${\mathbf{c}}\left[\mathit{i}-1\right]$, for $\mathit{i}={k}_{j}+1,\dots ,{k}_{j+1}$
Contains the level ${n}_{\mathrm{fwd}}-\mathit{j}+1$ detail coefficients, for $\mathit{j}=2,3,\dots ,{n}_{\mathrm{fwd}}$.
dwtlev
Type: array<System..::..Int32>[]()[][]
An array of size [${\mathbf{nwl}}+1$]
On exit: the number of transform coefficients at each level. ${\mathbf{dwtlev}}\left[0\right]$ and ${\mathbf{dwtlev}}\left[1\right]$ contain the number, $q\left({n}_{\mathrm{fwd}}\right)$, of approximation and detail coefficients respectively, for the final level of resolution (these are equal); ${\mathbf{dwtlev}}\left[\mathit{i}-1\right]$ contains the number of detail coefficients, $q\left({n}_{\mathrm{fwd}}-\mathit{i}+2\right)$, for the (${n}_{\mathrm{fwd}}-\mathit{i}+2$)th level, for $\mathit{i}=3,4,\dots ,{n}_{\mathrm{fwd}}+1$.
communications
Type: NagLibrary..::..C09..::..C09Communications
An Object of type C09.c09ccCommunications.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

c09cc computes the multi-level DWT of one-dimensional data. For a given wavelet and end extension method, c09cc will compute a multi-level transform of a data array, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, using a specified number, ${n}_{\mathrm{fwd}}$, of levels. The number of levels specified, ${n}_{\mathrm{fwd}}$, must be no more than the value ${l}_{\mathrm{max}}$ returned in nwlmax by the initialization method C09 Communication class constructor for the given problem. The transform is returned as a set of coefficients for the different levels (packed into a single array) and a representation of the multi-level structure.
The notation used here assigns level $0$ to the input dataset, $x$, with level $1$ being the first set of coefficients computed, with the detail coefficients, ${d}_{1}$, being stored while the approximation coefficients, ${a}_{1}$, are used as the input to a repeat of the wavelet transform. This process is continued until, at level ${n}_{\mathrm{fwd}}$, both the detail coefficients, ${d}_{{n}_{\mathrm{fwd}}}$, and the approximation coefficients, ${a}_{{n}_{\mathrm{fwd}}}$ are retained. The output array, $C$, stores these sets of coefficients in reverse order, starting with ${a}_{{n}_{\mathrm{fwd}}}$ followed by ${d}_{{n}_{\mathrm{fwd}}},{d}_{{n}_{\mathrm{fwd}}-1},\dots ,{d}_{1}$.

None.

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
On entry, n is inconsistent with the value passed to the initialization method: ${\mathbf{n}}=〈\mathit{\text{value}}〉$, n should be $〈\mathit{\text{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, ${\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 method: ${\mathbf{nwl}}=〈\mathit{\text{value}}〉$, maximum $\text{}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=7$
Either the initialization method has not been called first or array icomm has been corrupted.
Either the initialization method was called with ${\mathbf{wtrans}}=\text{"S"}$ or array icomm has been corrupted.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# 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.

# Parallelism and Performance

None.

The wavelet coefficients at each level can be extracted from the output array c using the information contained in dwtlev on exit (see the descriptions of c and dwtlev in [Parameters]). For example, given an input data set, $x$, denoising can be carried out by applying a thresholding operation to the detail coefficients at every level. The elements ${\mathbf{c}}\left[i-1\right]$, for $i={k}_{1}+1,\dots ,{k}_{{n}_{\mathrm{fwd}}}+1$, as described in [Parameters], contain the detail coefficients, ${\stackrel{^}{d}}_{\mathit{i}\mathit{j}}$, for $\mathit{i}={n}_{\mathrm{fwd}},{n}_{\mathrm{fwd}}-1,\dots ,1$ and $\mathit{j}=1,2,\dots ,q\left(i\right)$, where ${\stackrel{^}{d}}_{ij}={d}_{ij}+\sigma {\epsilon }_{ij}$ and $\sigma {\epsilon }_{ij}$ is the transformed noise term. If some threshold parameter $\alpha$ is chosen, a simple hard thresholding rule can be applied as
 $d-ij=0,if ​d^ij≤αd^ij,if ​d^ij>α,$
taking ${\stackrel{-}{d}}_{ij}$ to be an approximation to the required detail coefficient without noise, ${d}_{ij}$. The resulting coefficients can then be used as input to c09cd in order to reconstruct the denoised signal.