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_fft_complex_2d (c06pu)

## Purpose

nag_sum_fft_complex_2d (c06pu) computes the two-dimensional discrete Fourier transform of a bivariate sequence of complex data values (using complex data type).

## Syntax

[x, ifail] = c06pu(direct, m, n, x)
[x, ifail] = nag_sum_fft_complex_2d(direct, m, n, x)

## Description

nag_sum_fft_complex_2d (c06pu) computes the two-dimensional discrete Fourier transform of a bivariate sequence of complex data values z j1 j2 ${z}_{{\mathit{j}}_{1}{\mathit{j}}_{2}}$, for j1 = 0,1,,m1$\mathit{j1}=0,1,\dots ,m-1$ and j2 = 0,1,,n1$\mathit{j2}=0,1,\dots ,n-1$.
The discrete Fourier transform is here defined by
 m − 1 n − 1 ẑ k1 k2 = 1/(sqrt(mn)) ∑ ∑ z j1 j2 × exp( ± 2πi(( j1 k1 )/m + ( j2 k2 )/n)), j1 = 0 j2 = 0
$z^ k1 k2 = 1mn ∑ j1=0 m-1 ∑ j2=0 n-1 z j1 j2 × exp( ±2πi ( j1 k1 m + j2 k2 n ) ) ,$
where k1 = 0,1,,m1 ${k}_{1}=0,1,\dots ,m-1$ and k2 = 0,1,,n1 ${k}_{2}=0,1,\dots ,n-1$.
(Note the scale factor of 1/(sqrt(mn)) $\frac{1}{\sqrt{mn}}$ in this definition.) The minus sign is taken in the argument of the exponential within the summation when the forward transform is required, and the plus sign is taken when the backward transform is required.
A call of nag_sum_fft_complex_2d (c06pu) with direct = 'F'${\mathbf{direct}}=\text{'F'}$ followed by a call with direct = 'B'${\mathbf{direct}}=\text{'B'}$ will restore the original data.
This function performs multiple one-dimensional discrete Fourier transforms by the fast Fourier transform (FFT) algorithm in Brigham (1974) and Temperton (1983).

## References

Brigham E O (1974) The Fast Fourier Transform Prentice–Hall
Temperton C (1983) Self-sorting mixed-radix fast Fourier transforms J. Comput. Phys. 52 1–23

## Parameters

### Compulsory Input Parameters

1:     direct – string (length ≥ 1)
If the forward transform as defined in Section [Description] is to be computed, then direct must be set equal to 'F'.
If the backward transform is to be computed then direct must be set equal to 'B'.
Constraint: direct = 'F'${\mathbf{direct}}=\text{'F'}$ or 'B'$\text{'B'}$.
2:     m – int64int32nag_int scalar
m$m$, the first dimension of the transform.
Constraint: m1${\mathbf{m}}\ge 1$.
3:     n – int64int32nag_int scalar
n$n$, the second dimension of the transform.
Constraint: n1${\mathbf{n}}\ge 1$.
4:     x( m × n ${\mathbf{m}}×{\mathbf{n}}$) – complex array
The complex data values. x(m × j2 + j1)${\mathbf{x}}\left({\mathbf{m}}×{\mathit{j}}_{2}+{\mathit{j}}_{1}\right)$ must contain z j1 j2 ${z}_{{\mathit{j}}_{1}{\mathit{j}}_{2}}$, for j1 = 1,2,,m$\mathit{j1}=1,2,\dots ,{\mathbf{m}}$ and j2 = 1,2,,n$\mathit{j2}=1,2,\dots ,{\mathbf{n}}$.

None.

work

### Output Parameters

1:     x( m × n ${\mathbf{m}}×{\mathbf{n}}$) – complex array
The corresponding elements of the computed transform.
2:     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, m < 1${\mathbf{m}}<1$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, n < 1${\mathbf{n}}<1$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, direct ≠ 'F'${\mathbf{direct}}\ne \text{'F'}$ or 'B'$\text{'B'}$.
ifail = 4${\mathbf{ifail}}=4$
 On entry, n has more than 30$30$ prime factors.
ifail = 5${\mathbf{ifail}}=5$
 On entry, m has more than 30$30$ prime factors.
ifail = 6${\mathbf{ifail}}=6$
An unexpected error has occurred in an internal call. Check all function calls and array dimensions. Seek expert help.

## Accuracy

Some indication of accuracy can be obtained by performing a subsequent inverse transform and comparing the results with the original sequence (in exact arithmetic they would be identical).

The time taken is approximately proportional to mn × log(mn) $mn×\mathrm{log}\left(mn\right)$, but also depends on the factorization of the individual dimensions m$m$ and n$n$. nag_sum_fft_complex_2d (c06pu) is faster if the only prime factors are 2$2$, 3$3$ or 5$5$; and fastest of all if they are powers of 2$2$. This function requires a workspace of size mn + n + m + 30$mn+n+m+30$ which is internally allocated.

## Example

```function nag_sum_fft_complex_2d_example
direct = 'F';
m = int64(3);
n = int64(5);
x = [1;
0.994 - 0.111i;
0.903 - 0.43i;
0.999 - 0.04i;
0.989 - 0.151i;
0.885 - 0.466i;
0.987 - 0.159i;
0.963 - 0.268i;
0.823 - 0.568i;
0.936 - 0.352i;
0.891 - 0.454i;
0.694 - 0.72i;
0.802 - 0.597i;
0.731 - 0.682i;
0.467 - 0.884i];
[xOut, ifail] = nag_sum_fft_complex_2d(direct, m, n, x)
```
```

xOut =

3.3731 - 1.5187i
0.4565 + 0.1368i
-0.1705 + 0.4927i
0.4814 - 0.0907i
0.0549 + 0.0317i
-0.0375 + 0.0584i
0.2507 + 0.1776i
0.0093 + 0.0389i
-0.0423 + 0.0082i
0.0543 + 0.3188i
-0.0217 + 0.0356i
-0.0377 - 0.0255i
-0.4194 + 0.4145i
-0.0759 + 0.0045i
-0.0022 - 0.0829i

ifail =

0

```
```function c06pu_example
direct = 'F';
m = int64(3);
n = int64(5);
x = [1;
0.994 - 0.111i;
0.903 - 0.43i;
0.999 - 0.04i;
0.989 - 0.151i;
0.885 - 0.466i;
0.987 - 0.159i;
0.963 - 0.268i;
0.823 - 0.568i;
0.936 - 0.352i;
0.891 - 0.454i;
0.694 - 0.72i;
0.802 - 0.597i;
0.731 - 0.682i;
0.467 - 0.884i];
[xOut, ifail] = c06pu(direct, m, n, x)
```
```

xOut =

3.3731 - 1.5187i
0.4565 + 0.1368i
-0.1705 + 0.4927i
0.4814 - 0.0907i
0.0549 + 0.0317i
-0.0375 + 0.0584i
0.2507 + 0.1776i
0.0093 + 0.0389i
-0.0423 + 0.0082i
0.0543 + 0.3188i
-0.0217 + 0.0356i
-0.0377 - 0.0255i
-0.4194 + 0.4145i
-0.0759 + 0.0045i
-0.0022 - 0.0829i

ifail =

0

```