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_sum_convcorr_complex (c06pk)

## Purpose

nag_sum_convcorr_complex (c06pk) calculates the circular convolution or correlation of two complex vectors of period n$n$.

## Syntax

[x, y, ifail] = c06pk(job, x, y, 'n', n)
[x, y, ifail] = nag_sum_convcorr_complex(job, x, y, 'n', n)

## Description

nag_sum_convcorr_complex (c06pk) computes:
• if job = 1 ${\mathbf{job}}=1$, the discrete convolution of x$x$ and y$y$, defined by
 n − 1 n − 1 zk = ∑ xjyk − j = ∑ xk − jyj; j = 0 j = 0
$zk = ∑ j=0 n-1 xj y k-j = ∑ j=0 n-1 x k-j yj ;$
• if job = 2 ${\mathbf{job}}=2$, the discrete correlation of x$x$ and y$y$ defined by
 n − 1 wk = ∑ xjyk + j. j = 0
$wk = ∑ j=0 n-1 x-j y k+j .$
Here x$x$ and y$y$ are complex vectors, assumed to be periodic, with period n$n$, i.e., xj = xj ± n = xj ± 2n = ${x}_{j}={x}_{j±n}={x}_{j±2n}=\dots \text{}$; z$z$ and w$w$ are then also periodic with period n$n$.
Note:  this usage of the terms ‘convolution’ and ‘correlation’ is taken from Brigham (1974). The term ‘convolution’ is sometimes used to denote both these computations.
If $\stackrel{^}{x}$, $\stackrel{^}{y}$, $\stackrel{^}{z}$ and $\stackrel{^}{w}$ are the discrete Fourier transforms of these sequences, and $\stackrel{~}{x}$ is the inverse discrete Fourier transform of the sequence xj ${x}_{j}$, i.e.,
 n − 1 x̂k = 1/(sqrt(n)) ∑ xj × exp( − i(2πjk)/n), etc., j = 0
$x^k = 1n ∑ j=0 n-1 xj × exp( -i 2πjk n ) , etc.,$
and
 n − 1 x̃k = 1/(sqrt(n)) ∑ xj × exp(i(2πjk)/n), j = 0
$x~k = 1n ∑ j= 0 n- 1 xj × exp( i 2πjk n ) ,$
then k = sqrt(n) . k k ${\stackrel{^}{z}}_{k}=\sqrt{n}.{\stackrel{^}{x}}_{k}{\stackrel{^}{y}}_{k}$ and k = sqrt(n) . k k ${\stackrel{^}{w}}_{k}=\sqrt{n}.{\stackrel{-}{\stackrel{^}{x}}}_{k}{\stackrel{^}{y}}_{k}$ (the bar denoting complex conjugate).

## References

Brigham E O (1974) The Fast Fourier Transform Prentice–Hall

## Parameters

### Compulsory Input Parameters

1:     job – int64int32nag_int scalar
The computation to be performed:
job = 1${\mathbf{job}}=1$
zk = j = 0n1 xj ykj ${z}_{k}=\sum _{j=0}^{n-1}{x}_{j}{y}_{k-j}$ (convolution);
job = 2${\mathbf{job}}=2$
wk = j = 0n1 xj yk + j ${w}_{k}=\sum _{j=0}^{n-1}{\stackrel{-}{x}}_{j}{y}_{k+j}$ (correlation).
Constraint: job = 1${\mathbf{job}}=1$ or 2$2$.
2:     x(n) – complex array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The elements of one period of the vector x$x$. If x is declared with bounds (0 : n1)$\left(0:{\mathbf{n}}-1\right)$ in the function from which nag_sum_convcorr_complex (c06pk) is called, then x(j) ${\mathbf{x}}\left(\mathit{j}\right)$ must contain xj${x}_{\mathit{j}}$, for j = 0,1,,n1$\mathit{j}=0,1,\dots ,n-1$.
3:     y(n) – complex array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The elements of one period of the vector y$y$. If y is declared with bounds (0 : n1)$\left(0:{\mathbf{n}}-1\right)$ in the function from which nag_sum_convcorr_complex (c06pk) is called, then y(j)${\mathbf{y}}\left(\mathit{j}\right)$ must contain yj${y}_{\mathit{j}}$, for j = 0,1,,n1$\mathit{j}=0,1,\dots ,n-1$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
n$n$, the number of values in one period of the vectors x and y. The total number of prime factors of n, counting repetitions, must not exceed 30$30$.
Constraint: n1${\mathbf{n}}\ge 1$.

work

### Output Parameters

1:     x(n) – complex array
The corresponding elements of the discrete convolution or correlation.
2:     y(n) – complex array
The discrete Fourier transform of the convolution or correlation returned in the array x.
3:     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 < 1${\mathbf{n}}<1$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, job ≠ 1${\mathbf{job}}\ne 1$ or 2$2$.
ifail = 3${\mathbf{ifail}}=3$
An unexpected error has occurred in an internal call. Check all function calls and array dimensions. Seek expert help.
ifail = 4${\mathbf{ifail}}=4$
 On entry, n has more than 30$30$ prime factors.

## Accuracy

The results should be accurate to within a small multiple of the machine precision.

The time taken is approximately proportional to n × log(n)$n×\mathrm{log}\left(n\right)$, but also depends on the factorization of n$n$. nag_sum_convcorr_complex (c06pk) is faster if the only prime factors of n$n$ are 2$2$, 3$3$ or 5$5$; and fastest of all if n$n$ is a power of 2$2$.

## Example

```function nag_sum_convcorr_complex_example
job = int64(1);
x = [ 1 - 0.5i;
1 - 0.5i;
1 - 0.5i;
1 - 0.5i;
1 - 0.5i;
0 - 0.5i;
0 - 0.5i;
0 - 0.5i;
0 - 0.5i];
y = [ 0.5 - 0.25i;
0.5 - 0.25i;
0.5 - 0.25i;
0.5 - 0.25i;
0 - 0.25i;
0 - 0.25i;
0 - 0.25i;
0 - 0.25i;
0 - 0.25i];
[xOut, yOut, ifail] = nag_sum_convcorr_complex(job, x, y)
```
```

xOut =

-0.6250 - 2.2500i
-0.1250 - 2.2500i
0.3750 - 2.2500i
0.8750 - 2.2500i
0.8750 - 2.2500i
0.3750 - 2.2500i
-0.1250 - 2.2500i
-0.6250 - 2.2500i
-1.1250 - 2.2500i

yOut =

-0.0417 - 6.7500i
-1.0585 - 0.8882i
-0.0082 - 0.0465i
0.0833 - 0.1443i
0.0667 - 0.0243i
0.0667 + 0.0243i
0.0833 + 0.1443i
-0.0082 + 0.0465i
-1.0585 + 0.8882i

ifail =

0

```
```function c06pk_example
job = int64(1);
x = [ 1 - 0.5i;
1 - 0.5i;
1 - 0.5i;
1 - 0.5i;
1 - 0.5i;
0 - 0.5i;
0 - 0.5i;
0 - 0.5i;
0 - 0.5i];
y = [ 0.5 - 0.25i;
0.5 - 0.25i;
0.5 - 0.25i;
0.5 - 0.25i;
0 - 0.25i;
0 - 0.25i;
0 - 0.25i;
0 - 0.25i;
0 - 0.25i];
[xOut, yOut, ifail] = c06pk(job, x, y)
```
```

xOut =

-0.6250 - 2.2500i
-0.1250 - 2.2500i
0.3750 - 2.2500i
0.8750 - 2.2500i
0.8750 - 2.2500i
0.3750 - 2.2500i
-0.1250 - 2.2500i
-0.6250 - 2.2500i
-1.1250 - 2.2500i

yOut =

-0.0417 - 6.7500i
-1.0585 - 0.8882i
-0.0082 - 0.0465i
0.0833 - 0.1443i
0.0667 - 0.0243i
0.0667 + 0.0243i
0.0833 + 0.1443i
-0.0082 + 0.0465i
-1.0585 + 0.8882i

ifail =

0

```