NAG C Library Function Document

nag_sum_convcorr_real (c06fkc)


nag_sum_convcorr_real (c06fkc) calculates the circular convolution or correlation of two real vectors of period n.


#include <nag.h>
#include <nagc06.h>
void  nag_sum_convcorr_real (Nag_VectorOp job, double x[], double y[], Integer n, NagError *fail)


nag_sum_convcorr_real (c06fkc) computes:
Here x and y are real vectors, assumed to be periodic, with period n, i.e., xj = x j±n = x j±2n = ; 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 x^ , y^ , z^  and 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 z^k = n . x^k y^k  and w^k = n . x^- k y^k  (the bar denoting complex conjugate).
This function calls the same auxiliary functions as nag_sum_fft_realherm_1d (c06pac) to compute discrete Fourier transforms.


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


1:     job Nag_VectorOpInput
On entry: the computation to be performed.
zk = j=0 n-1 x j y k-j ;
w k = j=0 n-1 x j y k+j .
Constraint: job=Nag_Convolution or Nag_Correlation.
2:     x[n] doubleInput/Output
On entry: the elements of one period of the vector x. x[j]  must contain xj, for j=0,1,,n-1.
On exit: the corresponding elements of the discrete convolution or correlation.
3:     y[n] doubleInput/Output
On entry: the elements of one period of the vector y. y[j] must contain yj, for j=0,1,,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 zk are written as ak+ibk, then for 0kn/2, ak is contained in y[k], and for 1kn/2-1, bk is contained in y[n-k]. (See also Section 2.1.2 in the c06 Chapter Introduction.)
4:     n IntegerInput
On entry: n, the number of values in one period of the vectors x and y.
Constraint: n>1.
5:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

Dynamic memory allocation failed.
See Section in How to Use the NAG Library and its Documentation for further information.
On entry, argument value had an illegal value.
On entry, n=value.
Constraint: n>1.
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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.


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

Parallelism and Performance

nag_sum_convcorr_real (c06fkc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_sum_convcorr_real (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.

Further Comments

The time taken is approximately proportional to n × logn, but also depends on the factorization of n. nag_sum_convcorr_real (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.


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 nag_sum_convcorr_real (c06fkc)). In realistic computations the number of data values would be much larger.

Program Text

Program Text (c06fkce.c)

Program Data

Program Data (c06fkce.d)

Program Results

Program Results (c06fkce.r)