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_sngl_fwd (c09ca)

## Purpose

nag_wav_1d_sngl_fwd (c09ca) computes the one-dimensional discrete wavelet transform (DWT) at a single level. The initialization function nag_wav_1d_init (c09aa) must be called first to set up the DWT options.

## Syntax

[ca, cd, icomm, ifail] = c09ca(x, lenc, icomm, 'n', n)
[ca, cd, icomm, ifail] = nag_wav_1d_sngl_fwd(x, lenc, icomm, 'n', n)

## Description

nag_wav_1d_sngl_fwd (c09ca) computes the one-dimensional DWT of a given input data array, xi${x}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$, at a single level. For a chosen wavelet filter pair, the output coefficients are obtained by applying convolution and downsampling by two to the input, x$x$. The approximation (or smooth) coefficients, Ca${C}_{a}$, are produced by the low pass filter and the detail coefficients, Cd${C}_{d}$, by the high pass filter. To reduce distortion effects at the ends of the data array, several end extension methods are commonly used. Those provided are: periodic or circular convolution end extension, half-point symmetric end extension, whole-point symmetric end extension or zero end extension. The number nc${n}_{c}$, of coefficients Ca${C}_{a}$ or Cd${C}_{d}$ is returned by the initialization function nag_wav_1d_init (c09aa).

## References

Daubechies I (1992) Ten Lectures on Wavelets SIAM, Philadelphia

## Parameters

### Compulsory Input Parameters

1:     x(n) – double array
n, the dimension of the array, must satisfy the constraint .
x contains the input dataset xi${x}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
2:     lenc – int64int32nag_int scalar
The dimension of the arrays ca and cd as declared in the (sub)program from which nag_wav_1d_sngl_fwd (c09ca) is called. This must be at least the number, nc${n}_{c}$, of approximation coefficients, Ca${C}_{a}$, and detail coefficients, Cd${C}_{d}$, of the discrete wavelet transform as returned in nwc by the call to the initialization function nag_wav_1d_init (c09aa).
Constraint: lencnc${\mathbf{lenc}}\ge {n}_{c}$, where nc${n}_{c}$ is the value returned in nwc by the call to the initialization function nag_wav_1d_init (c09aa).
3:     icomm(100$100$) – 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:     n – int64int32nag_int scalar
Default: The dimension of the array x.
The number of elements, n$n$, in the data array x$x$.
Constraint: this must be the same as the value n passed to the initialization function nag_wav_1d_init (c09aa).

None.

### Output Parameters

1:     ca(lenc) – double array
ca(i)${\mathbf{ca}}\left(i\right)$ contains the i$i$th approximation coefficient, Ca(i)${C}_{a}\left(\mathit{i}\right)$, for i = 1,2,,nc$\mathit{i}=1,2,\dots ,{n}_{c}$.
2:     cd(lenc) – double array
cd(i)${\mathbf{cd}}\left(\mathit{i}\right)$ contains the i$\mathit{i}$th detail coefficient, Cd(i)${C}_{d}\left(\mathit{i}\right)$, for i = 1,2,,nc$\mathit{i}=1,2,\dots ,{n}_{c}$.
3:     icomm(100$100$) – int64int32nag_int array
Contains additional information on the computed transform.
4:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
On entry, n is inconsistent with the value passed to the initialization function nag_wav_1d_init (c09aa).
ifail = 2${\mathbf{ifail}}=2$
On entry, lenc < nc${\mathbf{lenc}}<{n}_{c}$, where nc${n}_{c}$ is the value returned in nwc by the call to the initialization function nag_wav_1d_init (c09aa).
ifail = 6${\mathbf{ifail}}=6$
On entry, the initialization function nag_wav_1d_init (c09aa) has not been called first or it has been called with wtrans = 'M'${\mathbf{wtrans}}=\text{'M'}$, or the communication array icomm has become corrupted.

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

```function nag_wav_1d_sngl_fwd_example
n = int64(8);
wavnam = 'DB4';
mode = 'zero';
wtrans = 'Single Level';
x = [1; 3; 5; 7; 6; 4; 5; 2];
fprintf('\n Input Data:\n');
fprintf('%8.4f ', x);
fprintf('\n');

% Query wavelet filter dimensions
[nwl, nf, nwc, icomm, ifail] = nag_wav_1d_init(wavnam, wtrans, mode, n);

if ifail == int64(0)
% Compute the transform
[ca, cd, icomm, ifail] = nag_wav_1d_sngl_fwd(x, nwc, icomm);

if ifail == int64(0)
fprintf(' Approximation coefficients CA :\n');
fprintf('%8.4f ', ca);
fprintf('\n');
fprintf(' Detail coefficients        CD :\n');
fprintf('%8.4f ', cd);
fprintf('\n');

% Reconstruct original data
[y, ifail] = nag_wav_1d_sngl_inv(ca, cd, n, icomm);

if ifail == int64(0)
fprintf(' Reconstruction       Y : \n');
fprintf('%8.4f ', y);
fprintf('\n');
end
end
end
```
```

Input Data:
1.0000   3.0000   5.0000   7.0000   6.0000   4.0000   5.0000   2.0000
Approximation coefficients CA :
0.0011  -0.0043  -0.0174   4.4778   8.9557   7.3401   2.5816
Detail coefficients        CD :
0.0237   0.0410  -0.5966   1.7763  -0.7517   0.3332  -0.1188
Reconstruction       Y :
1.0000   3.0000   5.0000   7.0000   6.0000   4.0000   5.0000   2.0000

```
```function c09ca_example
n = int64(8);
wavnam = 'DB4';
mode = 'zero';
wtrans = 'Single Level';
x = [1; 3; 5; 7; 6; 4; 5; 2];
fprintf('\n Input Data:\n');
fprintf('%8.4f ', x);
fprintf('\n');

% Query wavelet filter dimensions
[nwl, nf, nwc, icomm, ifail] = c09aa(wavnam, wtrans, mode, n);

if ifail == int64(0)
% Compute the transform
[ca, cd, icomm, ifail] = c09ca(x, nwc, icomm);

if ifail == int64(0)
fprintf(' Approximation coefficients CA :\n');
fprintf('%8.4f ', ca);
fprintf('\n');
fprintf(' Detail coefficients        CD :\n');
fprintf('%8.4f ', cd);
fprintf('\n');

% Reconstruct original data
[y, ifail] = c09cb(ca, cd, n, icomm);

if ifail == int64(0)
fprintf(' Reconstruction       Y : \n');
fprintf('%8.4f ', y);
fprintf('\n');
end
end
end
```
```

Input Data:
1.0000   3.0000   5.0000   7.0000   6.0000   4.0000   5.0000   2.0000
Approximation coefficients CA :
0.0011  -0.0043  -0.0174   4.4778   8.9557   7.3401   2.5816
Detail coefficients        CD :
0.0237   0.0410  -0.5966   1.7763  -0.7517   0.3332  -0.1188
Reconstruction       Y :
1.0000   3.0000   5.0000   7.0000   6.0000   4.0000   5.0000   2.0000

```