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_real_nowork (c06ek)

## Purpose

nag_sum_convcorr_real_nowork (c06ek) calculates the circular convolution or correlation of two real vectors of period n$n$. (No extra workspace is required.)
Note: this function is scheduled to be withdrawn, please see c06ek in Advice on Replacement Calls for Withdrawn/Superseded Routines..

## Syntax

[x, y, ifail] = c06ek(job, x, y, 'n', n)
[x, y, ifail] = nag_sum_convcorr_real_nowork(job, x, y, 'n', n)

## Description

nag_sum_convcorr_real_nowork (c06ek) 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 xj y k+j .$
Here x$x$ and y$y$ are real 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, 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.,$
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).
This function calls the same auxiliary functions as nag_sum_fft_real_1d_nowork (c06ea) and nag_sum_fft_hermitian_1d_nowork (c06eb) to compute discrete Fourier transforms, and there are some restrictions on the value of n$n$.

## 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}{x}_{j}{y}_{k+j}$ (correlation).
Constraint: job = 1${\mathbf{job}}=1$ or 2$2$.
2:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n > 1${\mathbf{n}}>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_real_nowork (c06ek) 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) – double array
n, the dimension of the array, must satisfy the constraint n > 1${\mathbf{n}}>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_real_nowork (c06ek) 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.
Constraint: n > 1${\mathbf{n}}>1$.

None.

### Output Parameters

1:     x(n) – double array
The corresponding elements of the discrete convolution or correlation.
2:     y(n) – double array
The discrete Fourier transform of the convolution or correlation returned in the array x; the transform is stored in Hermitian form. If the components of the transform are:
 Ẑk = ak + i bk Ẑn − k = ak − i bk }
k = 0,1, … n / 2
$Z^k = ak + i bk Z^ n-k = ak - i bk } k=0,1,…n/2$
where b0${b}_{0}$ and bn / 2${b}_{n/2}$ when n$n$ is even then x(k + 1)${\mathbf{x}}\left(k+1\right)$ holds ak${a}_{k}$ and x(nk + 1)${\mathbf{x}}\left(n-k+1\right)$ holds nonzero bk${b}_{k}$ (see Section [Real transforms] in the C06 Chapter Introduction).
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$
At least one of the prime factors of n is greater than 19$19$.
ifail = 2${\mathbf{ifail}}=2$
n has more than 20$20$ prime factors.
ifail = 3${\mathbf{ifail}}=3$
 On entry, n ≤ 1${\mathbf{n}}\le 1$.
ifail = 4${\mathbf{ifail}}=4$
 On entry, job ≠ 1${\mathbf{job}}\ne 1$ or 2$2$.

## 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_real_nowork (c06ek) 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$.
On the other hand, nag_sum_convcorr_real_nowork (c06ek) is particularly slow if n$n$ has several unpaired prime factors, i.e., if the ‘square-free’ part of n$n$ has several factors. For such values of n$n$, nag_sum_convcorr_real (c06fk) (which requires additional double workspace) is considerably faster.

## Example

```function nag_sum_convcorr_real_nowork_example
job = int64(1);
x = [1;
1;
1;
1;
1;
0;
0;
0;
0];
y = [0.5;
0.5;
0.5;
0.5;
0;
0;
0;
0;
0];
[xOut, yOut, ifail] = nag_sum_convcorr_real_nowork(job, x, y)
```
```

xOut =

0.5000
1.0000
1.5000
2.0000
2.0000
1.5000
1.0000
0.5000
0.0000

yOut =

3.3333
-1.0585
-0.0082
0.0833
0.0667
-0.0243
-0.1443
-0.0465
-0.8882

ifail =

0

```
```function c06ek_example
job = int64(1);
x = [1;
1;
1;
1;
1;
0;
0;
0;
0];
y = [0.5;
0.5;
0.5;
0.5;
0;
0;
0;
0;
0];
[xOut, yOut, ifail] = c06ek(job, x, y)
```
```

xOut =

0.5000
1.0000
1.5000
2.0000
2.0000
1.5000
1.0000
0.5000
0.0000

yOut =

3.3333
-1.0585
-0.0082
0.0833
0.0667
-0.0243
-0.1443
-0.0465
-0.8882

ifail =

0

```