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_cont (c09ba)

## Purpose

nag_wav_1d_cont (c09ba) computes the real, continuous wavelet transform in one dimension.

## Syntax

[c, ifail] = c09ba(wavnam, wparam, x, scales, 'n', n, 'nscal', nscal)
[c, ifail] = nag_wav_1d_cont(wavnam, wparam, x, scales, 'n', n, 'nscal', nscal)

## Description

nag_wav_1d_cont (c09ba) computes the real part of the one-dimensional, continuous wavelet transform
 $Cs,k = ∫ ℝ xt 1 s ψ* t-k s dt ,$
of a signal $x\left(t\right)$ at scale $s$ and position $k$, where the signal is sampled discretely at $n$ equidistant points ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$. $\psi$ is the wavelet function, which can be chosen to be the Morlet wavelet, the derivatives of a Gaussian or the Mexican hat wavelet ($*$ denotes the complex conjugate). The integrals of the scaled, shifted wavelet function are approximated and the convolution is then computed.
The mother wavelets supplied for use with this function are defined as follows.
1. The Morlet wavelet (real part) with nondimensional wave number $\kappa$ is
 $ψx = 1 π 1/4 cosκx - e -κ2/2 e -x2/2 ,$
where the correction term, ${e}^{-{\kappa }^{2}/2}$ (required to satisfy the admissibility condition) is included.
2. The derivatives of a Gaussian are obtained from
 $ψ^m x = dm e -x2 d xm ,$
taking $m=1,\dots ,8$. These are the Hermite polynomials multiplied by the Gaussian. The sign is then adjusted to give ${\stackrel{^}{\psi }}^{\left(m\right)}\left(0\right)>0$ when $m$ is even while the sign of the succeeding odd derivative, ${\stackrel{^}{\psi }}^{\left(m+1\right)}$, is made consistent with the preceding even numbered derivative. They are normalized by the ${L}^{2}$-norm,
 $pm = ∫ -∞ ∞ ψ^ m x 2 d x 1/2$
The resulting normalized derivatives can be written in terms of the Hermite polynomials, ${H}_{m}\left(x\right)$, as
 $ψ m x = α Hmx e -x2 pm ,$
where
Thus, the derivatives of a Gaussian provided here are,
 $ψ1 x = - 2π 1/4 2 x e -x2 ,$
 $ψ2 x = - 2π 1/4 1 3 4x2 - 2 e -x2 ,$
 $ψ3 x = 2π 1/4 115 8x3 - 12x e -x2 ,$
 $ψ4 x = 2π 1/4 1105 16x4 - 48x2 + 12 e -x2 ,$
 $ψ5 x = - 2π 1/4 1 3105 32x5 - 160x3 + 120x e -x2 ,$
 $ψ6 x = - 2π 1/4 1 31155 64x6 - 480x4 + 720x2 - 120 e -x2 ,$
 $ψ7 x = 2π 1/4 1 315015 128x7 - 1344x5 + 3360x3 - 1680x e -x2 ,$
 $ψ8 x = 2π 1/4 1 451001 256x8 - 3584x6 + 13440x4 - 13440x2 + 1680 e -x2 .$
3. The second derivative of a Gaussian is known as the Mexican hat wavelet and is supplied as an additional function in the form
 $ψx = 2 3 π1/4 1-x2 e -x2/2 .$
The remaining normalized derivatives of a Gaussian can be expressed as multiples of the exponential ${e}^{-{t}^{2}/2}$ by applying the substitution $x=t/\sqrt{2}$ followed by multiplication with the scaling factor, $1/\sqrt[4]{2}$.

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{wavnam}$ – string
The name of the mother wavelet. See the C09 Chapter Introduction for details.
${\mathbf{wavnam}}=\text{'MORLET'}$
Morlet wavelet.
${\mathbf{wavnam}}=\text{'DGAUSS'}$
Derivative of a Gaussian wavelet.
${\mathbf{wavnam}}=\text{'MEXHAT'}$
Mexican hat wavelet.
Constraint: ${\mathbf{wavnam}}=\text{'MORLET'}$, $\text{'DGAUSS'}$ or $\text{'MEXHAT'}$.
2:     $\mathrm{wparam}$int64int32nag_int scalar
The nondimensional wave number for the Morlet wavelet or the order of the derivative for the Gaussian wavelet. It is not referenced when ${\mathbf{wavnam}}=\text{'MEXHAT'}$.
Constraints:
• if ${\mathbf{wavnam}}=\text{'MORLET'}$, $5\le {\mathbf{wparam}}\le 20$;
• if ${\mathbf{wavnam}}=\text{'DGAUSS'}$, $1\le {\mathbf{wparam}}\le 8$.
3:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
x contains the input dataset ${\mathbf{x}}\left(\mathit{j}\right)={x}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$.
4:     $\mathrm{scales}\left({\mathbf{nscal}}\right)$int64int32nag_int array
The scales at which the transform is to be computed.
Constraint: ${\mathbf{scales}}\left(\mathit{i}\right)\ge 1$, for $\mathit{i}=1,2,\dots ,{\mathbf{nscal}}$.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the array x.
The size, $n$, of the input dataset $x$.
Constraint: ${\mathbf{n}}\ge 2$.
2:     $\mathrm{nscal}$int64int32nag_int scalar
Default: the dimension of the array scales.
The dimension of the array scales and the first dimension of the array c. the number of scales to be computed.
Constraint: ${\mathbf{nscal}}\ge 1$.

### Output Parameters

1:     $\mathrm{c}\left({\mathbf{nscal}},{\mathbf{n}}\right)$ – double array
The transform coefficients at the requested scales, where ${\mathbf{c}}\left(i,j\right)$ is the transform coefficient ${C}_{i,j}$ at scale $i$ and position $j$.
2:     $\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, ${\mathbf{wavnam}}=_$ was an illegal value.
${\mathbf{ifail}}=2$
Constraint: if ${\mathbf{wavnam}}=\text{'DGAUSS'}$, $1\le {\mathbf{wparam}}\le 8$.
Constraint: if ${\mathbf{wavnam}}=\text{'MORLET'}$, $5\le {\mathbf{wparam}}\le 20$.
${\mathbf{ifail}}=3$
Constraint: ${\mathbf{n}}\ge 2$.
${\mathbf{ifail}}=5$
Constraint: ${\mathbf{nscal}}\ge 1$.
${\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 nag_wav_1d_cont (c09ba) is determined by the fact that the convolution must be computed as a discrete approximation to the continuous form. The input signal, $x$, is taken to be piecewise constant using the supplied discrete values.

Workspace is internally allocated by nag_wav_1d_cont (c09ba). The total size of these arrays is ${2}^{13}+\left({\mathbf{n}}+{n}_{k}-1\right)$ double elements and ${n}_{k}$ integer elements, where ${n}_{k}=k×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{scales}}\left(\mathit{i}\right)\right)$ and $k=17$ when ${\mathbf{wavnam}}=\text{'MORLET'}$ or $\text{'DGAUSS'}$ and $k=11$ when ${\mathbf{wavnam}}=\text{'MEXHAT'}$.

## Example

This example computes the continuous wavelet transform of a dataset containing a single nonzero value representing an impulse. The Morlet wavelet is used with wave number $\kappa =5$ and scales $1$, $2$, $3$, $4$.
```function c09ba_example

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

wavnam = 'Morlet';
wparam = int64(5);
scales = [int64(1), 2, 3, 4];
x = zeros(10,1);
x(5) = 1;

[c, ifail] = c09ba(wavnam, wparam, x, scales);
fprintf('\nNumber of Scales : 4\n');
fprintf('Wavelet coefficients c :\n');
fprintf('Scale:    %d           %d            %d            %d\n', scales);
for j = 1:10
fprintf('    %11.4e  %11.4e  %11.4e  %11.4e\n', c(:,j));
end

```
```c09ba example results

Number of Scales : 4
Wavelet coefficients c :
Scale:    1           2            3            4
-1.7651e-05   1.5012e-04   5.2331e-02   1.4454e-01
-1.3643e-03  -5.8141e-02   1.7057e-01  -8.4364e-02
4.6511e-03   1.8442e-01  -1.4891e-01  -2.8870e-01
8.9294e-02  -2.6380e-01  -2.6822e-01  -9.4993e-02
-9.2563e-02   1.3289e-01   2.5680e-01   2.8293e-01
-9.2563e-02   1.3289e-01   2.5680e-01   2.8293e-01
8.9294e-02  -2.6380e-01  -2.6822e-01  -9.4993e-02
4.6511e-03   1.8442e-01  -1.4891e-01  -2.8870e-01
-1.3643e-03  -5.8141e-02   1.7057e-01  -8.4364e-02
-1.7651e-05   1.5012e-04   5.2331e-02   1.4454e-01
```