hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_sum_convcorr_real (c06fk)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_sum_convcorr_real (c06fk) calculates the circular convolution or correlation of two real vectors of period n (using a work array for extra speed).

Syntax

[x, y, ifail] = c06fk(job, x, y, 'n', n)
[x, y, ifail] = nag_sum_convcorr_real(job, x, y, 'n', n)

Description

nag_sum_convcorr_real (c06fk) 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 (c06pa) to compute discrete Fourier transforms.

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
zk = j=0 n-1 x j y k-j  (convolution);
job=2
w k = j=0 n-1 x j y k+j  (correlation).
Constraint: job=1 or 2.
2:     xn – double array
The elements of one period of the vector x. If x is declared with bounds 0:n-1 in the function from which nag_sum_convcorr_real (c06fk) is called, then xj  must contain xj, for j=0,1,,n-1.
3:     yn – double array
The elements of one period of the vector y. If y is declared with bounds 0:n-1 in the function from which nag_sum_convcorr_real (c06fk) is called, then yj must contain yj, for j=0,1,,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, the number of values in one period of the vectors x and y.
Constraint: n>1.

Output Parameters

1:     xn – double array
The corresponding elements of the discrete convolution or correlation.
2:     yn – 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 zk are written as ak+ibk, then for 0kn/2, ak is contained in yk, and for 1kn/2-1, bk is contained in yn-k. (See also Real transforms in the C06 Chapter Introduction.)
3:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=3
On entry,n1.
   ifail=4
On entry,job1 or 2.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

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

Further Comments

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

Example

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


fprintf('c06fk example results\n\n');

x = [1;    1;    1;    1;    1;    0;    0;    0;    0];
y = [0.5;  0.5;  0.5;  0.5;  0;    0;    0;    0;    0];

job = int64(1);
[conv, tconv, ifail] = c06fk(job, x, y);

job = int64(2);
[corr, tcorr, ifail] = c06fk(job, x, y);

result = [conv corr];
disp('Convolution  Correlation');
disp(result);


c06fk example results

Convolution  Correlation
    0.5000    2.0000
    1.0000    1.5000
    1.5000    1.0000
    2.0000    0.5000
    2.0000    0.0000
    1.5000    0.5000
    1.0000    1.0000
    0.5000    1.5000
    0.0000    2.0000


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015