# NAG CL Interfacec06fkc (convcorr_​real)

Settings help

CL Name Style:

## 1Purpose

c06fkc calculates the circular convolution or correlation of two real vectors of period $n$.

## 2Specification

 #include
 void c06fkc (Nag_VectorOp job, double x[], double y[], Integer n, NagError *fail)
The function may be called by the names: c06fkc or nag_sum_convcorr_real.

## 3Description

c06fkc computes:
• if ${\mathbf{job}}=\mathrm{Nag_Convolution}$, the discrete convolution of $x$ and $y$, defined by
 $zk = ∑ j=0 n-1 xj y k-j = ∑ j=0 n-1 x k-j yj ;$
• if ${\mathbf{job}}=\mathrm{Nag_Correlation}$, the discrete correlation of $x$ and $y$ defined by
 $wk = ∑ j=0 n-1 xj y k+j .$
Here $x$ and $y$ are real vectors, assumed to be periodic, with period $n$, i.e., ${x}_{j}={x}_{j±n}={x}_{j±2n}=\cdots \text{}$; $z$ and $w$ are then also periodic with period $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.,
 $x^k = 1n ∑ j=0 n-1 xj × exp(-i 2πjk n ) , etc.,$
then ${\stackrel{^}{z}}_{k}=\sqrt{n}.{\stackrel{^}{x}}_{k}{\stackrel{^}{y}}_{k}$ and ${\stackrel{^}{w}}_{k}=\sqrt{n}.{\overline{\stackrel{^}{x}}}_{k}{\stackrel{^}{y}}_{k}$ (the bar denoting complex conjugate).
This function calls the same auxiliary functions as c06pac to compute discrete Fourier transforms.

## 4References

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

## 5Arguments

1: $\mathbf{job}$Nag_VectorOp Input
On entry: the computation to be performed.
${\mathbf{job}}=\mathrm{Nag_Convolution}$
${z}_{k}=\sum _{j=0}^{n-1}{x}_{j}{y}_{k-j}$;
${\mathbf{job}}=\mathrm{Nag_Correlation}$
${w}_{k}=\sum _{j=0}^{n-1}{x}_{j}{y}_{k+j}$.
Constraint: ${\mathbf{job}}=\mathrm{Nag_Convolution}$ or $\mathrm{Nag_Correlation}$.
2: $\mathbf{x}\left[{\mathbf{n}}\right]$double Input/Output
On entry: the elements of one period of the vector $x$. ${\mathbf{x}}\left[\mathit{j}\right]$ must contain ${x}_{\mathit{j}}$, for $\mathit{j}=0,1,\dots ,n-1$.
On exit: the corresponding elements of the discrete convolution or correlation.
3: $\mathbf{y}\left[{\mathbf{n}}\right]$double Input/Output
On entry: the elements of one period of the vector $y$. ${\mathbf{y}}\left[\mathit{j}\right]$ must contain ${y}_{\mathit{j}}$, for $\mathit{j}=0,1,\dots ,n-1$.
On exit: 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 ${z}_{k}$ are written as ${a}_{k}+i{b}_{k}$, then for $0\le k\le n/2$, ${a}_{k}$ is contained in ${\mathbf{y}}\left[k\right]$, and for $1\le k\le n/2-1$, ${b}_{k}$ is contained in ${\mathbf{y}}\left[n-k\right]$. (See also Section 2.1.2 in the C06 Chapter Introduction.)
4: $\mathbf{n}$Integer Input
On entry: $n$, the number of values in one period of the vectors x and y.
Constraint: ${\mathbf{n}}>1$.
5: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_INT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}>1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.

## 7Accuracy

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

## 8Parallelism and Performance

c06fkc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
c06fkc makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

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

## 10Example

This example reads in the elements of one period of two real vectors $x$ and $y$, and prints their discrete convolution and correlation (as computed by c06fkc). In realistic computations the number of data values would be much larger.

### 10.1Program Text

Program Text (c06fkce.c)

### 10.2Program Data

Program Data (c06fkce.d)

### 10.3Program Results

Program Results (c06fkce.r)