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}_{{\mathit{j}}_{1}{\mathit{j}}_{2}}$, for $\mathit{j1}=0,1,\dots ,m-1$ and $\mathit{j2}=0,1,\dots ,n-1$.
The discrete Fourier transform is here defined by
 $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 ${k}_{1}=0,1,\dots ,m-1$ and ${k}_{2}=0,1,\dots ,n-1$.
(Note the scale factor of $\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 ${\mathbf{direct}}=\text{'F'}$ followed by a call with ${\mathbf{direct}}=\text{'B'}$ will restore the original data.
This function calls nag_sum_fft_complex_1d_multi_row (c06pr) to perform multiple one-dimensional discrete Fourier transforms by the fast Fourier transform (FFT) algorithm in Brigham (1974).

## 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:     $\mathrm{direct}$ – string (length ≥ 1)
If the forward transform as defined in 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: ${\mathbf{direct}}=\text{'F'}$ or $\text{'B'}$.
2:     $\mathrm{m}$int64int32nag_int scalar
$m$, the first dimension of the transform.
Constraint: ${\mathbf{m}}\ge 1$.
3:     $\mathrm{n}$int64int32nag_int scalar
$n$, the second dimension of the transform.
Constraint: ${\mathbf{n}}\ge 1$.
4:     $\mathrm{x}\left({\mathbf{m}}×{\mathbf{n}}\right)$ – complex array
The complex data values. ${\mathbf{x}}\left({\mathbf{m}}×{\mathit{j}}_{2}+{\mathit{j}}_{1}\right)$ must contain ${z}_{{\mathit{j}}_{1}{\mathit{j}}_{2}}$, for $\mathit{j1}=1,2,\dots ,{\mathbf{m}}$ and $\mathit{j2}=1,2,\dots ,{\mathbf{n}}$.

None.

### Output Parameters

1:     $\mathrm{x}\left({\mathbf{m}}×{\mathbf{n}}\right)$ – complex array
The corresponding elements of the computed transform.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{m}}<1$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{n}}<1$.
${\mathbf{ifail}}=3$
 On entry, ${\mathbf{direct}}\ne \text{'F'}$ or $\text{'B'}$.
${\mathbf{ifail}}=6$
An unexpected error has occurred in an internal call. Check all function calls and array dimensions. Seek expert help.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## 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×\mathrm{log}\left(mn\right)$, but also depends on the factorization of the individual dimensions $m$ and $n$. nag_sum_fft_complex_2d (c06pu) is faster if the only prime factors are $2$, $3$ or $5$; and fastest of all if they are powers of $2$.

## Example

This example reads in a bivariate sequence of complex data values and prints the two-dimensional Fourier transform. It then performs an inverse transform and prints the sequence so obtained, which may be compared to the original data values.
```function c06pu_example

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

m = int64(3);
n = int64(5);
x = [ 1.000     0.999     0.987     0.936     0.802;
0.994     0.989     0.963     0.891     0.731;
0.903     0.885     0.823     0.694     0.467];
y = [ 0.000    -0.040    -0.159    -0.352    -0.597;
-0.111    -0.151    -0.268    -0.454    -0.682
-0.430    -0.466    -0.568    -0.720    -0.884];
z = x + i*y;

% transform, then inverse transform to restore data
direct = 'F';
[zt, ifail] = c06pu(direct, m, n, z);
direct = 'B';
[zr, ifail] = c06pu(direct, m, n, zt);

title = 'Original data:';
[ifail] = x04da('General','Non-unit', z, title);
disp(' ');
title = 'Components of discrete Fourier transform:';
[ifail] = x04da('General','Non-unit', zt, title);
disp(' ');
title = 'Original data as restored by inverse transform';
[ifail] = x04da('General','Non-unit', zr, title);

```
```c06pu example results

Original data:
1       2       3       4       5
1   1.0000  0.9990  0.9870  0.9360  0.8020
0.0000 -0.0400 -0.1590 -0.3520 -0.5970

2   0.9940  0.9890  0.9630  0.8910  0.7310
-0.1110 -0.1510 -0.2680 -0.4540 -0.6820

3   0.9030  0.8850  0.8230  0.6940  0.4670
-0.4300 -0.4660 -0.5680 -0.7200 -0.8840

Components of discrete Fourier transform:
1          2          3          4          5
1      3.3731     0.4814     0.2507     0.0543    -0.4194
-1.5187    -0.0907     0.1776     0.3188     0.4145

2      0.4565     0.0549     0.0093    -0.0217    -0.0759
0.1368     0.0317     0.0389     0.0356     0.0045

3     -0.1705    -0.0375    -0.0423    -0.0377    -0.0022
0.4927     0.0584     0.0082    -0.0255    -0.0829

Original data as restored by inverse transform
1       2       3       4       5
1   1.0000  0.9990  0.9870  0.9360  0.8020
0.0000 -0.0400 -0.1590 -0.3520 -0.5970

2   0.9940  0.9890  0.9630  0.8910  0.7310
-0.1110 -0.1510 -0.2680 -0.4540 -0.6820

3   0.9030  0.8850  0.8230  0.6940  0.4670
-0.4300 -0.4660 -0.5680 -0.7200 -0.8840
```