# NAG FL Interfacec09baf (dim1_​cont)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

c09baf computes the real, continuous wavelet transform in one dimension.

## 2Specification

Fortran Interface
 Subroutine c09baf ( n, x, c,
 Integer, Intent (In) :: wparam, n, nscal, scales(nscal) Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x(n) Real (Kind=nag_wp), Intent (Out) :: c(nscal,n) Character (*), Intent (In) :: wavnam
#include <nag.h>
 void c09baf_ (const char *wavnam, const Integer *wparam, const Integer *n, const double x[], const Integer *nscal, const Integer scales[], double c[], Integer *ifail, const Charlen length_wavnam)
The routine may be called by the names c09baf or nagf_wav_dim1_cont.

## 3Description

c09baf computes the real part of the one-dimensional, continuous wavelet transform
 $Cs,k = ∫ ℝ x(t) 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 routine are defined as follows.
1. 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. 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 dx) 1/2$
The resulting normalized derivatives can be written in terms of the Hermite polynomials, ${H}_{m}\left(x\right)$, as
 $ψ (m) (x) = α Hm(x) 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. 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{2}$.
Daubechies I (1992) Ten Lectures on Wavelets SIAM, Philadelphia

## 5Arguments

1: $\mathbf{wavnam}$Character(*) Input
On entry: 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: $\mathbf{wparam}$Integer Input
On entry: 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: $\mathbf{n}$Integer Input
On entry: the size, $n$, of the input dataset $x$.
Constraint: ${\mathbf{n}}\ge 2$.
4: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: x contains the input dataset ${\mathbf{x}}\left(\mathit{j}\right)={x}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$.
5: $\mathbf{nscal}$Integer Input
On entry: the dimension of the array scales and the first dimension of the array c as declared in the (sub)program from which c09baf is called. The number of scales to be computed.
Constraint: ${\mathbf{nscal}}\ge 1$.
6: $\mathbf{scales}\left({\mathbf{nscal}}\right)$Integer array Input
On entry: 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}}$.
7: $\mathbf{c}\left({\mathbf{nscal}},{\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: 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$.
8: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{wavnam}}=⟨\mathit{\text{value}}⟩$ was an illegal value.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{wavnam}}=\text{'MORLET'}$ and ${\mathbf{wparam}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{wavnam}}=\text{'MORLET'}$, $5\le {\mathbf{wparam}}\le 20$.
On entry, ${\mathbf{wavnam}}=\text{'DGAUSS'}$ and ${\mathbf{wparam}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{wavnam}}=\text{'DGAUSS'}$, $1\le {\mathbf{wparam}}\le 8$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 2$.
${\mathbf{ifail}}=5$
On entry, ${\mathbf{nscal}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nscal}}\ge 1$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

The accuracy of c09baf 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.

## 8Parallelism and Performance

c09baf is not threaded in any implementation.

Workspace is internally allocated by c09baf. The total size of these arrays is ${2}^{13}+\left({\mathbf{n}}+{n}_{k}-1\right)$ real 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'}$.

## 10Example

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

### 10.1Program Text

Program Text (c09bafe.f90)

### 10.2Program Data

Program Data (c09bafe.d)

### 10.3Program Results

Program Results (c09bafe.r)