Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_wav_1d_mxolap_fwd (c09da)

## Purpose

nag_wav_1d_mxolap_fwd (c09da) computes the one-dimensional maximal overlap discrete wavelet transform (MODWT) at a single level. The initialization function nag_wav_1d_init (c09aa) must be called first to set up the MODWT options.

## Syntax

[ca, cd, icomm, ifail] = c09da(x, lenc, icomm, 'n', n)
[ca, cd, icomm, ifail] = nag_wav_1d_mxolap_fwd(x, lenc, icomm, 'n', n)

## Description

nag_wav_1d_mxolap_fwd (c09da) 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 function nag_wav_1d_init (c09aa).

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
x contains the input dataset ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
2:     $\mathrm{lenc}$int64int32nag_int scalar
The dimension of the arrays ca and cd. 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 function nag_wav_1d_init (c09aa). 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 function nag_wav_1d_init (c09aa).
3:     $\mathrm{icomm}\left(100\right)$int64int32nag_int array
Contains details of the discrete wavelet transform and the problem dimension as setup in the call to the initialization function nag_wav_1d_init (c09aa).

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the array x.
The number of elements, $n$, in the data array $x$.
Constraint: this must be the same as the value n passed to the initialization function nag_wav_1d_init (c09aa).

### Output Parameters

1:     $\mathrm{ca}\left({\mathbf{lenc}}\right)$ – double array
${\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}$.
2:     $\mathrm{cd}\left({\mathbf{lenc}}\right)$ – double array
${\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}$.
3:     $\mathrm{icomm}\left(100\right)$int64int32nag_int array
Contains additional information on the computed transform.
4:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
On entry, n is inconsistent with the value passed to the initialization function.
${\mathbf{ifail}}=3$
On entry, array dimension lenc not large enough.
${\mathbf{ifail}}=6$
On entry, the initialization function nag_wav_1d_init (c09aa) 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$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

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

None.

## Example

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

fprintf('c09da example results\n\n');

% 1d maximal overlap discrete wavelet decomposition using a Daubechies wavelet

n      = int64(8);
x      = [1 3 5 7 6 4 5 2];

wavnam = 'DB4';
mode   = 'Periodic';
wtrans = 'Time invariant';

% Setup for wavelet
[nwlmax, nf, nwc, icomm, ifail] = c09aa(wavnam, wtrans, mode, n);

% Compute decomposition
[ca, cd, icomm, ifail] = c09da(x, nwc, icomm);

disp('Approximation coefficients:')
fprintf('%8.4f',ca);
fprintf('\n');
disp('Detail coefficients:')
fprintf('%8.4f',cd);
fprintf('\n');

% Reconstruct
[y, ifail] = c09db(ca, cd, n, icomm);
disp('Reconstruction:')
fprintf('%8.4f',y);
fprintf('\n');

```
```c09da example results

Approximation coefficients:
2.7781  1.5146  2.2505  4.8788  6.6845  6.3423  4.7869  3.7644
Detail coefficients:
-0.6187  0.6272  0.1883 -1.1966  1.2618  0.3354 -0.3314 -0.2660
Reconstruction:
1.0000  3.0000  5.0000  7.0000  6.0000  4.0000  5.0000  2.0000
```

Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015