📄 ocn_c06.h
字号:
printf("\nOriginal data values\n\n");
for (j = 0; j<m; ++j)
{
printf("Real");
for (i = 0; i<n; ++i)
{
printf("%10.4f", x[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\nImag");
for (i = 0; i<n; ++i)
{
printf("%10.4f", y[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\n\n");
}
nag_fft_init_trig(n, trig);
nag_fft_multiple_complex(m, n, x, y, trig);
printf("\nDiscrete Fourier transforms\n\n");
for (j = 0; j<m; ++j)
{
printf("Real");
for (i = 0; i<n; ++i)
{
printf("%10.4f", x[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\nImag");
for (i = 0; i<n; ++i)
{
printf("%10.4f", y[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\n\n");
}
nag_conjugate_complex(m*n, y);
nag_fft_multiple_complex(m, n, x, y, trig);
nag_conjugate_complex(m*n, y );
printf ("\nOriginal data as restored by inverse transform\n\n");
for (j = 0; j<m; ++j)
{
printf("Real");
for (i = 0; i<n; ++i)
{
printf("%10.4f", x[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\nImag");
for (i = 0; i<n; ++i)
{
printf("%10.4f", y[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\n\n");
}
}
The output is following:
m = 3 n = 6
Original data values
Real 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424
Imag 0.5417 0.2983 0.1181 0.7255 0.8638 0.8723
Real 0.9172 0.0644 0.6037 0.6430 0.0428 0.4815
Imag 0.9089 0.3118 0.3465 0.6198 0.2668 0.1614
Real 0.1156 0.0685 0.2060 0.8630 0.6967 0.2792
Imag 0.6214 0.8681 0.7060 0.8652 0.9190 0.3355
Discrete Fourier transforms
Real 1.0737 -0.5706 0.1733 -0.1467 0.0518 0.3625
Imag 1.3961 -0.0409 -0.2958 -0.1521 0.4517 -0.0321
Real 1.1237 0.1728 0.4185 0.1530 0.3686 0.0101
Imag 1.0677 0.0386 0.7481 0.1752 0.0565 0.1403
Real 0.9100 -0.3054 0.4079 -0.0785 -0.1193 -0.5314
Imag 1.7617 0.0624 -0.0695 0.0725 0.1285 -0.4335
Original data as restored by inverse transform
Real 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424
Imag 0.5417 0.2983 0.1181 0.7255 0.8638 0.8723
Real 0.9172 0.0644 0.6037 0.6430 0.0428 0.4815
Imag 0.9089 0.3118 0.3465 0.6198 0.2668 0.1614
Real 0.1156 0.0685 0.2060 0.8630 0.6967 0.2792
Imag 0.6214 0.8681 0.7060 0.8652 0.9190 0.3355
Return:
The function returns NAG error code or 0 if no error.
11: On entry, m must not be less than 1: m = _value_. On entry, n must not be less than 1: n = _value_.
139: Value of n and trig array are incompatible or trig array is not initialized.
73: Memory allocation failed.
successfully call of the nag_fft_multiple_complex function.
*/
int nag_fft_multiple_complex(
int m, //the number of sequences to be transformed.
int n, //the number of data values in each sequence.
double x[], // Input: the real parts of the complex data. Output: x is overwritten by the real part of the complex transforms.
double y[], // Input: the imaginary parts of the complex data. Output: y is overwritten by the imaginary part of the complex transforms.
const double trig[] //trigonometric coefficients are returned by a call of nag_fft_init_trig (c06gzc).
); // computes the discrete Fourier transforms of m sequences, each containing n complex data values.
/** c06fuc
computes the two-dimensional discrete Fourier transform of a bivariate sequence of complex data values
Example1:
Assume "Data1" Worksheet has 4 columns, the first two columns contain 15 data each. This piece
of code computes the two-dimensional discrete Fourier transform of a bivariate sequence of complex
data values. and put the result to the third column (real part) and the fourth column (imag part).
int m = 3, n = 5;
double trigm[5], trign[5];
//Attach four Datasets to these 4 columns
Dataset xx("data1",0);
Dataset yy("data1",1);
Dataset dx("data1",2);
Dataset dy("data1",3);
//Dataset cannot be the parameter of function, but vector can be.
vector x = xx, y = yy;
nag_fft_init_trig(m, trigm);
nag_fft_init_trig(n, trign);
nag_fft_2d_complex(m, n, x, y, trigm, trign);
//Put the result to worksheet "data1" the third and fourth column.
dx = x;
dy = y;
Example2:
This program 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.
void test_nag_ftt_2d_complex()
{
int i, j, m, n;
double trigm[12], trign[12];
double x[36] = {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};
double y[36] = {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};
m = 3;
n = 5;
printf("\nOriginal data values\n\n");
for (j = 0; j<m; ++j)
{
printf("Real");
for (i = 0; i<n; ++i)
{
printf("%10.4f", x[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\nImag");
for (i = 0; i<n; ++i)
{
printf("%10.4f", y[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\n\n");
}
nag_fft_init_trig(m, trigm);
nag_fft_init_trig(n, trign);
nag_fft_2d_complex(m, n, x, y, trigm, trign);
printf("\nComponents of discrete Fourier transforms\n\n");
for (j = 0; j<m; ++j)
{
printf("Real");
for (i = 0; i<n; ++i)
{
printf("%10.4f", x[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\nImag");
for (i = 0; i<n; ++i)
{
printf("%10.4f", y[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\n\n");
}
nag_conjugate_complex(m*n, y);
nag_fft_2d_complex(m, n, x, y,trigm, trign);
nag_conjugate_complex(m*n, y);
printf ("\nOriginal data as restored by inverse transform\n\n");
for (j = 0; j<m; ++j)
{
printf("Real");
for (i = 0; i<n; ++i)
{
printf("%10.4f", x[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\nImag");
for (i = 0; i<n; ++i)
{
printf("%10.4f", y[j*n + i]);
if(i % 6 == 5 && i != n-1 )
printf("\n " );
}
printf("\n\n");
}
}
The output is following:
m = 3 n = 5
Original data values
Real 1.0000 0.9990 0.9870 0.9360 0.8020
Imag 0.0000 -0.0400 -0.1590 -0.3520 -0.5970
Real 0.9940 0.9890 0.9630 0.8910 0.7310
Imag -0.1110 -0.1510 -0.2680 -0.4540 -0.6820
Real 0.9030 0.8850 0.8230 0.6940 0.4670
Imag -0.4300 -0.4660 -0.5680 -0.7200 -0.8840
Components of discrete Fourier transforms
Real 3.3731 0.4814 0.2507 0.0543 -0.4194
Imag -1.5187 -0.0907 0.1776 0.3188 0.4145
Real 0.4565 0.0549 0.0093 -0.0217 -0.0759
Imag 0.1368 0.0317 0.0389 0.0356 0.0045
Real -0.1705 -0.0375 -0.0423 -0.0377 -0.0022
Imag 0.4927 0.0584 0.0082 -0.0255 -0.0829
Original data as restored by inverse transform
Real 1.0000 0.9990 0.9870 0.9360 0.8020
Imag 0.0000 -0.0400 -0.1590 -0.3520 -0.5970
Real 0.9940 0.9890 0.9630 0.8910 0.7310
Imag -0.1110 -0.1510 -0.2680 -0.4540 -0.6820
Real 0.9030 0.8850 0.8230 0.6940 0.4670
Imag -0.4300 -0.4660 -0.5680 -0.7200 -0.8840
Return:
The function returns NAG error code or 0 if no error.
11: On entry, m must not be less than 1: m = _value_. On entry, n must not be less than 1: n = _value_.
139: Value of n and trign array are incompatible or trign array is not initialized. Value of m and trigm array are incompatible or trigm array is not initialized.
73: Memory allocation failed.
successfully call of the nag_fft_2d_complex function.
*/
int nag_fft_2d_complex(
int m, //the number of rows of the bivariate data sequence.
int n, //: the number of columns of the bivariate data sequence.
double x[], // Input: the real parts of the complex data. Output: the real part of the corresponding elements of the computed transform.
double y[], // Input: the imaginary parts of the complex data. Output: the imaginary part of the corresponding elements of the computed transform.
const double trigm[], //trigonometric coefficients are returned by calls of nag_fft_init_trig (c06gzc).
const double trign[] //trigonometric coefficients are returned by calls of nag_fft_init_trig (c06gzc).
); // computes the two-dimensional discrete Fourier transform of a bivariate sequence of complex data values.
/** c06gbc
forms the complex conjugate of a Hermitian sequence of n data values.
Example1:
Assume "Data1" Worksheet has 3 columns, the first column contain 7 data. This piece of code forms
the complex conjugate of a Hermitian sequence of 7 data values. and put the result to the second
column (real part) and the third column (imag part).
int j, n = 7, n2, nj;
//Attach three Datasets to these 3 columns
Dataset xx("data1",0);
Dataset aa("data1",1);
Dataset bb("data1",2);
//Dataset cannot be the parameter of function, but vector can be.
vector x = xx, a = aa, b = bb;
nag_fft_real(n, x);
nag_conjugate_hermitian(n, x);
a[0] = x[0];
b[0] = 0.0;
n2 = (n-1)/2;
for (j = 1; j<=n2; j++)
{
nj = n - j;
a[j] = x[j];
a[nj] = x[j];
b[j] = x[nj];
b[nj] = -x[nj];
}
if (n % 2==0)
{
a[n2+1] = x[n2+1];
b[n2+1] = 0.0;
}
//Put the result to the Worksheet "data1" the second and third column.
aa = a;
bb = b;
Example2:
This program reads in a sequence of real data values,cal ls nag fft real (c06eac) followed by
nag_conjugate_hermitian to compute their inverse discrete Fourier transform, and prints this after
expanding it from Hermitian form into a full complex sequence.
void test_nag_conjugate_hermitian()
{
#define NMAX 20
int j, n, n2, nj;
double a[20], b[20];
double x[20] = {0.34907, 0.54890, 0.74776, 0.94459,
1.13850, 1.32850, 1.51370};
n = 7;
nag_fft_real(n, x);
nag_conjugate_hermitian(n, x);
a[0] = x[0];
b[0] = 0.0;
n2 = (n-1)/2;
for (j = 1; j<=n2; j++)
{
nj = n - j;
a[j] = x[j];
a[nj] = x[j];
b[j] = x[nj];
b[nj] = -x[nj];
}
if (n % 2==0)
{
a[n2+1] = x[n2+1];
b[n2+1] = 0.0;
}
printf("\nComponents of inverse discrete Fourier transform\n");
printf("\n Real Imag \n\n");
for (j = 0; j<n; j++)
printf("%3ld %10.5f %10.5f\n", j, a[j], b[j]);
}
The output is following:
Components of inverse discrete Fourier transform
Real Imag
0 2.48361 0.00000
1 -0.26599 -0.53090
2 -0.25768 -0.20298
3 -0.25636 -0.05806
4 -0.25636 0.05806
5 -0.25768 0.20298
6 -0.26599 0.53090
Return:
The function returns NAG error code or 0 if no error.
11: On entry, n must not be less than 1: n = _value_.
successfully call of the nag_conjugate_hermitian function.
*/
int nag_conjugate_hermitian(
int n, // the number of data values.
double x[] // Input: the Hermitian sequence in Hermitian form. Output: the imaginary parts y[j] are negated. The real parts x[j] are not referenced.
); // forms the complex conjugate of a Hermitian sequence of n data values.
/** c06gcc
forms the complex conjugate of a sequence of n data values.
Example1:
Assume "Data1" Worksheet has 4 columns, the first two columns contain 7 data each.
This piece of code forms the complex conjugate of a sequence of 7 data values. and
put the result to the third column (real part) and the fourth column (imag part).
int j, n = 7;
//Attach four Datasets to these 4 columns
Dataset xx("data1",0);
Dataset yy("data1",1);
Dataset dx("data1",2);
Dataset dy("data1",3);
//Dataset cannot be the parameter of function, but vector can be.
vector x = xx;
nag_conjugate_complex(n, y);
nag_fft_complex(n, x, y);
nag_conjugate_complex(n, y);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -