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 = ∫ℝ x(t) 1/(sqrt(s)) ψ* ((t − k)/s) dt , $Cs,k = ∫ ℝ x(t) 1 s ψ* ( t-k s ) dt ,$
of a signal x(t)$x\left(t\right)$ at scale s$s$ and position k$k$, where the signal is sampled discretely at n$n$ equidistant points xi${x}_{\mathit{i}}$, for i = 1,2,,n$\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 , $ψ(x) = 1 π 1/4 ( cos(κx) - e -κ2/2 ) e -x2/2 ,$
where the correction term, eκ2 / 2${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 ) , $ψ^(m) (x) = dm ( e -x2 ) d xm ,$
taking m = 1,,8$m=1,\dots ,8$. These are the Hermite polynomials multiplied by the Gaussian. The sign is then adjusted to give ψ̂(m)(0) > 0${\stackrel{^}{\psi }}^{\left(m\right)}\left(0\right)>0$ when m$m$ is even while the sign of the succeeding odd derivative, ψ̂(m + 1)${\stackrel{^}{\psi }}^{\left(m+1\right)}$, is made consistent with the preceding even numbered derivative. They are normalized by the L2${L}^{2}$-norm,
pm =
 (∞ )∫[ψ̂(m)(x)]2dx − ∞ 1 / 2
$pm = ( ∫ -∞ ∞ [ ψ^ (m) (x) ] 2 d x ) 1/2$
The resulting normalized derivatives can be written in terms of the Hermite polynomials, Hm(x)${H}_{m}\left(x\right)$, as
 ψ(m) (x) = ( α Hm(x) e − x2 )/(pm) , $ψ (m) (x) = α Hm(x) e -x2 pm ,$
where
α =
 { 1, when ​m = 0,3  mod  4; − 1, when ​m = 1,2  mod  4.
Thus, the derivatives of a Gaussian provided here are,
 ψ(1) (x) = − (2/π)1 / 4 2 x e − x2 , $ψ(1) (x) = - (2π) 1/4 2 x e -x2 ,$
 ψ(2) (x) = − (2/π)1 / 4 1/(sqrt(3)) (4x2 − 2) e − x2 , $ψ(2) (x) = - (2π) 1/4 1 3 ( 4x2 - 2 ) e -x2 ,$
 ψ(3) (x) = (2/π)1 / 4 1/(sqrt(15)) (8x3 − 12x) e − x2 , $ψ(3) (x) = (2π) 1/4 115 ( 8x3 - 12x ) e -x2 ,$
 ψ(4) (x) = (2/π)1 / 4 1/(sqrt(105)) (16x4 − 48x2 + 12) e − x2 , $ψ(4) (x) = ( 2π ) 1/4 1105 ( 16x4 - 48x2 + 12 ) e -x2 ,$
 ψ(5) (x) = − (2/π)1 / 4 1/(3sqrt(105)) (32x5 − 160x3 + 120x) e − x2 , $ψ(5) (x) = - ( 2π ) 1/4 1 3105 ( 32x5 - 160x3 + 120x ) e -x2 ,$
 ψ(6) (x) = − (2/π)1 / 4 1/(3sqrt(1155)) (64x6 − 480x4 + 720x2 − 120) e − x2 , $ψ(6) (x) = - (2π) 1/4 1 31155 ( 64x6 - 480x4 + 720x2 - 120 ) e -x2 ,$
 ψ(7) (x) = (2/π)1 / 4 1/(3sqrt(15015)) (128x7 − 1344x5 + 3360x3 − 1680x) e − x2 , $ψ(7) (x) = (2π) 1/4 1 315015 ( 128x7 - 1344x5 + 3360x3 - 1680x ) e -x2 ,$
 ψ(8) (x) = (2/π)1 / 4 1/(45sqrt(1001)) (256x8 − 3584x6 + 13440x4 − 13440x2 + 1680) 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/((sqrt(3)π1 / 4)) (1 − x2) e − x2 / 2 . $ψ(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 t2 / 2 ${e}^{-{t}^{2}/2}$ by applying the substitution x = t / sqrt(2) $x=t/\sqrt{2}$ followed by multiplication with the scaling factor, 1 / root(4,2) $1/\sqrt[4]{2}$.

## References

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

## Parameters

### Compulsory Input Parameters

1:     wavnam – string
The name of the mother wavelet. See the C09 Chapter Introduction for details.
wavnam = 'MORLET'${\mathbf{wavnam}}=\text{'MORLET'}$
Morlet wavelet.
wavnam = 'DGAUSS'${\mathbf{wavnam}}=\text{'DGAUSS'}$
Derivative of a Gaussian wavelet.
wavnam = 'MEXHAT'${\mathbf{wavnam}}=\text{'MEXHAT'}$
Mexican hat wavelet.
Constraint: wavnam = 'MORLET'${\mathbf{wavnam}}=\text{'MORLET'}$, 'DGAUSS'$\text{'DGAUSS'}$ or 'MEXHAT'$\text{'MEXHAT'}$.
2:     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 wavnam = 'MEXHAT'${\mathbf{wavnam}}=\text{'MEXHAT'}$.
Constraints:
• if wavnam = 'MORLET'${\mathbf{wavnam}}=\text{'MORLET'}$, 5wparam20$5\le {\mathbf{wparam}}\le 20$;
• if wavnam = 'DGAUSS'${\mathbf{wavnam}}=\text{'DGAUSS'}$, 1wparam8$1\le {\mathbf{wparam}}\le 8$.
3:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n2${\mathbf{n}}\ge 2$.
x contains the input dataset x(j) = xj${\mathbf{x}}\left(\mathit{j}\right)={x}_{\mathit{j}}$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$.
4:     scales(nscal) – int64int32nag_int array
nscal, the dimension of the array, must satisfy the constraint nscal1${\mathbf{nscal}}\ge 1$.
The scales at which the transform is to be computed.
Constraint: scales(i)1${\mathbf{scales}}\left(\mathit{i}\right)\ge 1$, for i = 1,2,,nscal$\mathit{i}=1,2,\dots ,{\mathbf{nscal}}$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array x.
The size, n$n$, of the input dataset x$x$.
Constraint: n2${\mathbf{n}}\ge 2$.
2:     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 as declared in the (sub)program from which nag_wav_1d_cont (c09ba) is called. The number of scales to be computed.
Constraint: nscal1${\mathbf{nscal}}\ge 1$.

None.

### Output Parameters

1:     c(nscal,n) – double array
The transform coefficients at the requested scales, where c(i,j)${\mathbf{c}}\left(i,j\right)$ is the transform coefficient Ci,j${C}_{i,j}$ at scale i$i$ and position j$j$.
2:     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, wavnam had an illegal value.
ifail = 2${\mathbf{ifail}}=2$
Constraint: if wavnam = 'DGAUSS'${\mathbf{wavnam}}=\text{'DGAUSS'}$, 1wparam8$1\le {\mathbf{wparam}}\le 8$.
Constraint: if wavnam = 'MORLET'${\mathbf{wavnam}}=\text{'MORLET'}$, 5wparam20$5\le {\mathbf{wparam}}\le 20$.
ifail = 3${\mathbf{ifail}}=3$
Constraint: n2${\mathbf{n}}\ge 2$.
ifail = 5${\mathbf{ifail}}=5$
Constraint: nscal1${\mathbf{nscal}}\ge 1$.
ifail = 999${\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$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 213 + (n + nk1) ${2}^{13}+\left({\mathbf{n}}+{n}_{k}-1\right)$ double elements and nk${n}_{k}$ integer elements, where nk = k × max (scales(i)) ${n}_{k}=k×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{scales}}\left(\mathit{i}\right)\right)$ and k = 17$k=17$ when wavnam = 'MORLET'${\mathbf{wavnam}}=\text{'MORLET'}$ or 'DGAUSS'$\text{'DGAUSS'}$ and k = 11$k=11$ when wavnam = 'MEXHAT'${\mathbf{wavnam}}=\text{'MEXHAT'}$.

## Example

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

[c, ifail] = nag_wav_1d_cont(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
```
```

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

```
```function c09ba_example
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
```
```

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

```