PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_sum_fft_realherm_1d (c06pa)
Purpose
nag_sum_fft_realherm_1d (c06pa) calculates the discrete Fourier transform of a sequence of real data values or of a Hermitian sequence of complex data values stored in compact form in a double array.
Syntax
Description
Given a sequence of
real data values
, for
,
nag_sum_fft_realherm_1d (c06pa) calculates their discrete Fourier transform (in the
forward direction) defined by
The transformed values
are complex, but they form a Hermitian sequence (i.e.,
is the complex conjugate of
), so they are completely determined by
real numbers (since
is real, as is
for
even).
Alternatively, given a Hermitian sequence of
complex data values
, this function calculates their inverse (
backward) discrete Fourier transform defined by
The transformed values
are real.
(Note the scale factor of in the above definitions.)
A call of nag_sum_fft_realherm_1d (c06pa) with followed by a call with will restore the original data.
nag_sum_fft_realherm_1d (c06pa) uses a variant of the fast Fourier transform (FFT) algorithm (see
Brigham (1974)) known as the Stockham self-sorting algorithm, which is described in
Temperton (1983).
The same functionality is available using the forward and backward transform function pair:
nag_sum_fft_real_2d (c06pv) and
nag_sum_fft_hermitian_2d (c06pw) on setting
. This pair use a different storage solution; real data is stored in a double array, while Hermitian data (the first unconjugated half) is stored in a complex array.
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:
– 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:
or .
- 2:
– double array
-
If
x is declared with bounds
in the function from which
nag_sum_fft_realherm_1d (c06pa) is called, then:
- if ,
must contain , for ;
-
if , and must contain the real and imaginary parts respectively of , for . (Note that for the sequence to be Hermitian, the imaginary part of , and of for even, must be zero.)
- 3:
– int64int32nag_int scalar
-
, the number of data values.
Constraint:
.
Optional Input Parameters
None.
Output Parameters
- 1:
– double array
-
- if and x is declared with bounds ,
and will contain the real and imaginary parts respectively of , for ;
- if and x is declared with bounds ,
will contain , for .
- 2:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
Constraint: .
-
-
is an invalid value of
direct.
-
-
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.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
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).
Further Comments
The time taken is approximately proportional to , but also depends on the factorization of . nag_sum_fft_realherm_1d (c06pa) is faster if the only prime factors of are , or ; and fastest of all if is a power of .
Example
This example reads in a sequence of real data values and prints their discrete Fourier transform (as computed by nag_sum_fft_realherm_1d (c06pa) with ), after expanding it from complex Hermitian form into a full complex sequence. It then performs an inverse transform using nag_sum_fft_realherm_1d (c06pa) with , and prints the sequence so obtained alongside the original data values.
Open in the MATLAB editor:
c06pa_example
function c06pa_example
fprintf('c06pa example results\n\n');
n = int64(7);
x = zeros(n+2,1);
x(1:n) = [0.34907; 0.5489; 0.74776; 0.94459;
1.13850; 1.3285; 1.51370];
direct = 'F';
[xt, ifail] = c06pa(direct, x, n);
zt = nag_herm2complex(n,xt);
disp('Discrete Fourier Transform of x:');
disp(transpose(zt));
direct = 'B';
[xr, ifail] = c06pa(direct, xt, n);
fprintf('Original sequence as restored by inverse transform\n\n');
fprintf(' Original Restored\n');
for j = 1:n
fprintf('%3d %7.4f %7.4f\n',j, x(j),xr(j));
end
function [z] = nag_herm2complex(n,x);
z(1) = complex(x(1));
for j = 1:floor(double(n)/2) + 1
z(j) = x(2*j-1) + i*x(2*j);
z(n-j+2) = x(2*j-1) - i*x(2*j);
end
c06pa example results
Discrete Fourier Transform of x:
2.4836 + 0.0000i
-0.2660 + 0.5309i
-0.2577 + 0.2030i
-0.2564 + 0.0581i
-0.2564 - 0.0581i
-0.2577 - 0.2030i
-0.2660 - 0.5309i
2.4836 + 0.0000i
Original sequence as restored by inverse transform
Original Restored
1 0.3491 0.3491
2 0.5489 0.5489
3 0.7478 0.7478
4 0.9446 0.9446
5 1.1385 1.1385
6 1.3285 1.3285
7 1.5137 1.5137
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015