⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ocn_c06.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 5 页
字号:
	//put the result Convolution to the worksheet "data1" third column and Correlation
	//to the fourth column.
	dxb = xa;
	dyb = xb;
	
		
Example2:
	This program 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_convolution_real). 
	In realistic computations the number of data values would be much larger.
	
void test_nag_convolution_real()
{
	int j, n;
	double xb[64], yb[64];
	double xa[64] = {1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0};
	double ya[64] = {0.5, 0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0};
	n = 9;
	
	for (j = 0; j<n; ++j)
	{
		xb[j]= xa[j];
		yb[j]= ya[j];
	}
	
	nag_convolution_real(Nag_Convolution, n, xa, ya);
	
	nag_convolution_real(Nag_Correlation, n, xb, yb);
	
	printf("\n Convolution Correlation\n\n");
	for (j = 0; j<n; ++j)
		printf("%5ld %13.5f %13.5f\n", j, xa[j], xb[j]);	
}

	The output is following:
	
	 	Convolution 	Correlation
	
	0 	0.50000 		2.00000
	1 	1.00000 		1.50000
	2 	1.50000 		1.00000
	3 	2.00000 		0.50000
	4 	2.00000 		0.00000
	5 	1.50000 		0.50000
	6 	1.00000 		1.00000
	7 	0.50000 		1.50000
	8 	0.00000 		2.00000

Return:
	The function returns NAG error code or 0 if no error.
	137: At least one of the prime factors of n is greater than 19.
	138: n has more than 20 prime factors.
	12:  On entry, n must not be less than or equal to 1: n = _value_.
	70:  On entry, parameter operation has an illegal value.

	successfully call of the nag_convolution_real function.	
*/

	int nag_convolution_real(
		Nag_VectorOp operation, //the computation to be performed.
		int n, // the number of values.
		double x[],// Input:the elements of one period of the vector x. Output:the corresponding elements of the discrete convolution or correlation
		double y[]  // Input:the elements of one period of the vector y. Output:the discrete Fourier transform of the convolution 
  ); // calculates the circular convolution or correlation of two real vectors of period n.


/**	c06fpc
		computes the discrete Fourier transforms of m sequences, and each contains n real data values.

Example1:
	Assume "Data1" Worksheet has 2 columns, the first column contain 18 data. This piece of code 
	computes the discrete Fourier transforms of 3 sequences and each contains 6 data values.  The
	result will be put in the second column (Discrete Fourier transforms in Hermitian format). 
	
	double trig[40];
	int m = 3, n = 6;
	//Attach two Datasets to these 2 columns
	Dataset xx("data1",0);
	Dataset yy("data1",1);
	//Dataset cannot be the parameter of function, but vector can be.
	vector x = xx;	
	nag_fft_init_trig(n, trig); 
	nag_fft_multiple_real(m, n, x, trig);
	//put the result to worksheet "data1" the second column.	
	yy = x;

Example2:
	This program reads in sequences of real data values and prints their discrete Fourier
	transforms (as computed by nag_fft_multiple real). The Fourier transforms are expanded
	into full complex form using nag_multiple_hermitian to complex (c06gsc) and printed. Inverse
	transforms are then calculated by calling nag_multiple _conjugate_hermitian (c06gqc) followed by
	nag_fft_multiple_hermitian (c06fqc) showing that the original sequences are restored.
	
void test_nag_fft_multiple_real()
{
	#define MMAX 5
	#define NMAX 20
	double trig[40];
	int i, j, m, n;
	double u[100], v[100];
	double x[100] = {0.3854, 0.6772, 0.1138, 0.6751, 0.6362, 0.1424,
					 0.5417, 0.2983, 0.1181, 0.7255, 0.8638, 0.8723,
					 0.9172, 0.0644, 0.6037, 0.6430, 0.0428, 0.4815};
	m =3;
	n =6;

	for (j = 0; j<m; ++j)
	{
		printf(" ");
		for (i = 0; i<n; ++i)
		{
			printf("%10.4f", x[j*n + i]);
		 	if((i % 6 )== 5 && (i != n-1 ))
		 		printf("\n " );
		}
		printf("\n");
	}
	
	nag_fft_init_trig(n, trig); 

	nag_fft_multiple_real(m, n, x, trig);
	printf("\nDiscrete Fourier transforms in Hermitian format\n\n");
	
	for (j = 0; j<m; ++j)
	{
		printf(" ");
		for (i = 0; i<n; ++i)
		{
			printf("%10.4f", x[j*n + i]);
		 	if(i % 6 == 5 && i != n-1 )
		 		printf("\n " );
		}
		printf("\n");
	}
	
	nag_multiple_hermitian_to_complex(m, n, x, u, v);
	printf("\nFourier transforms in full complex form\n\n");
	for (j = 0; j<m; ++j)
	{
		printf("Real");
		for (i = 0; i<n; ++i)
		{
			printf("%10.4f", u[j*n + i]);
		 	if(i % 6 == 5 && i != n-1 )
		 		printf("\n " );
		}				
		printf("\nImag");
		for (i = 0; i<n; ++i)
		{
			printf("%10.4f", v[j*n + i]);
		 	if(i % 6 == 5 && i != n-1 )
		 		printf("\n " );
		}
		printf("\n\n");
	}

	nag_multiple_conjugate_hermitian(m, n, x);
	nag_fft_multiple_hermitian(m, n, x, trig);
	printf ("\nOriginal data as restored by inverse transform\n\n");
	for (j = 0; j<m; ++j)
	{
		printf(" ");
		for (i = 0; i<n; ++i)
		{
			printf("%10.4f", x[j*n + i]);
		 	if(i % 6 == 5 &&  i!= n-1 )
		 		printf("\n " );
		}
		printf("\n");
	}
}

	The output is following:
	
	m = 3 n = 6
	
	Original data values
	
			0.3854 	  0.6772 	 0.1138 	 0.6751 	 0.6362 	 0.1424
			0.5417 	  0.2983 	 0.1181 	 0.7255 	 0.8638 	 0.8723
			0.9172 	  0.0644 	 0.6037 	 0.6430 	 0.0428 	 0.4815
	
	Discrete Fourier transforms in Hermitian format
	
			1.0737 	 -0.1041 	 0.1126 	-0.1467 	-0.3738 	-0.0044
			1.3961 	 -0.0365 	 0.0780 	-0.1521 	-0.0607 	 0.4666
			1.1237 	  0.0914 	 0.3936 	 0.1530 	 0.3458 	-0.0508
			
	Fourier transforms in full complex form
	
	Real 	1.0737 	 -0.1041 	 0.1126 	-0.1467 	 0.1126 	-0.1041
	Imag 	0.0000 	 -0.0044 	-0.3738 	 0.0000 	 0.3738  	 0.0044
	
	Real 	1.3961 	 -0.0365 	 0.0780 	-0.1521 	 0.0780 	-0.0365
	Imag 	0.0000 	  0.4666 	-0.0607 	 0.0000 	 0.0607 	-0.4666
	
	Real 	1.1237 	  0.0914 	 0.3936 	 0.1530 	 0.3936 	 0.0914
	Imag 	0.0000 	 -0.0508 	 0.3458 	 0.0000  	-0.3458 	 0.0508
	
	Original data as restored by inverse transform
	
			0.3854 	  0.6772 	 0.1138 	 0.6751 	 0.6362 	 0.1424
			0.5417 	  0.2983 	 0.1181 	 0.7255 	 0.8638 	 0.8723
			0.9172 	  0.0644 	 0.6037 	 0.6430 	 0.0428 	 0.4815

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_real function.	
*/
	
	int nag_fft_multiple_real(
		int m, // the number of sequences to be transformed.
		int n, // the number of real values in each sequence.
		double x[],// Input:the m data sequences must be stored in x consecutively.  Output: the m discrete Fourier transforms in Hermitian form, stored consecutively, overwrite the corresponding original sequences. 
		const double trig[]	//trigonometric coefficients are returned by a call of nag_fft_init_trig (c06gzc).
  ); // Given m sequences of n real data values x[p][j], for j = 0, 1, . . . , n - 1; p = 1, 2, . . .,m, this function simultaneously calculates the Fourier transforms of all the sequences.
 
  
/**	c06fqc
		computes the discrete Fourier transforms of m Hermitian sequences, each containing n complex data values.

Example1:
	Assume "Data1" Worksheet has 2 columns, the first column contain 18 data. This piece of code 
	computes the discrete Fourier transforms of 3 sequences and each contains 6 data values.  The
	result will be put in the second column (Discrete Fourier transforms in Hermitian format). 
	
	double trig[40], u[40], v[40];
	int m = 3, n = 6;
	//Attach two Datasets to these 2 columns
	Dataset xx("data1",0);
	Dataset yy("data1",1);
	//Dataset cannot be the parameter of function, but vector can be.
	vector x = xx;
	//expand the sequences into full complex form.	
	nag_multiple_hermitian_to_complex(m, n, x, u, v);
	nag_fft_init_trig(n, trig);
	nag_fft_multiple_hermitian(m, n, x, trig);
	//put the result to worksheet "data1" the second column.
	yy = x;
		
Example2:
	This program reads in sequences of real data values which are assumed to be Hermitian sequences
	of complex data stored in Hermitian form. The sequences are expanded into full complex form
	using nag_multiple_hermitian_to_complex (c06gsc) and printed. The discrete Fourier transforms
	are then computed (using nag_fft_multiple_hermitian) and printed out. Inverse transforms are then
	calculated by calling nag_fft_multiple_real (c06fpc) followed by nag_multiple_conjugate_hermitian
	(c06gqc) showing that the original sequences are restored.
	
void test_nag_fft_multiple_hermitian()
{
	#define MMAX 5
	#define NMAX 20
	double trig[40];
	int i, j, m, n;
	double u[100], v[100];
	double x[100] = {0.3854, 0.6772, 0.1138, 0.6751, 0.6362, 0.1424,
					 0.5417, 0.2983, 0.1181, 0.7255, 0.8638, 0.8723,
					 0.9172, 0.0644, 0.6037, 0.6430, 0.0428, 0.4815};
	m = 3;
	n = 6;
	
	for (j = 0; j<m; ++j)
	{
		printf(" ");
		for (i = 0; i<n; ++i)
		{
			printf("%10.4f", x[j*n + i]);
		 	if((i % 6 )== 5 && (i != n-1 ))
		 		printf("\n " );
		}
		printf("\n");
	}
	nag_multiple_hermitian_to_complex(m, n, x, u, v);
	printf("\nOriginal data written in full complex form\n\n");
	for (j = 0; j<m; ++j)
	{
		printf("Real");
		for (i = 0; i<n; ++i)
		{
			printf("%10.4f", u[j*n + i]);
		 	if(i % 6 == 5 && i != n-1 )
		 		printf("\n " );
		}		
		printf("\nImag");
		for (i = 0; i<n; ++i)
		{
			printf("%10.4f", v[j*n + i]);
		 	if(i % 6 == 5 && i != n-1 )
		 		printf("\n " );
		}
		printf("\n\n");
	}

	nag_fft_init_trig(n, trig);
	nag_fft_multiple_hermitian(m, n, x, trig);
	printf ("\nDiscrete Fourier transforms (real values)\n\n");
	for (j = 0; j<m; ++j)
	{
		printf(" ");
		for (i = 0; i<n; ++i)
		{
			printf("%10.4f", x[j*n + i]);
		 	if(i % 6 == 5 &&  i!= n-1 )
		 		printf("\n " );
		 }
		printf("\n");
	}	
	
	nag_fft_multiple_real(m, n, x, trig);
	nag_multiple_conjugate_hermitian(m, n, x);
	printf ("\nOriginal data as restored by inverse transform\n\n");
	for (j = 0; j<m; ++j)
	{
		printf(" ");
		for (i = 0; i<n; ++i)
		{
			printf("%10.4f", x[j*n + i]);
		 	if(i % 6 == 5 &&  i!= n-1 )
		 		printf("\n " );
		}
		printf("\n");
	}	
}

	The output is following:
	
	m = 3 n = 6
	
	Original data values
	
			0.3854 		0.6772 		0.1138 		0.6751 		0.6362 	 	 0.1424
			0.5417 		0.2983 		0.1181 		0.7255 		0.8638 	 	 0.8723
			0.9172 		0.0644 		0.6037 		0.6430 		0.0428 	 	 0.4815
			
	Original data written in full complex form
	
	Real 	0.3854 		0.6772 		0.1138 		0.6751		0.1138 	 	 0.6772
	Imag 	0.0000 		0.1424 		0.6362 		0.0000	   -0.6362  	-0.1424
	Real 	0.5417 		0.2983 		0.1181 		0.7255		0.1181 	 	 0.2983
	Imag 	0.0000 		0.8723 		0.8638 		0.0000	   -0.8638 		-0.8723
	Real 	0.9172 		0.0644 		0.6037 		0.6430		0.6037 	 	 0.0644
	Imag 	0.0000 		0.4815 		0.0428 		0.0000	   -0.0428 		-0.4815
	
	Discrete Fourier transforms (real values)
	
			1.0788 		0.6623 	   -0.2391 	   -0.5783 	  	0.4592 		-0.4388
			0.8573 		1.2261 		0.3533 	   -0.2222 	 	0.3413 		-1.2291
			1.1825 		0.2625 		0.6744 		0.5523  	0.0540 		-0.4790
			
	Original data as restored by inverse transform
	
			0.3854 		0.6772 		0.1138 		0.6751 		0.6362 		 0.1424
			0.5417 		0.2983 		0.1181 		0.7255 		0.8638 		 0.8723
			0.9172 		0.0644 		0.6037 		0.6430 		0.0428 		 0.4815
			
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_hermitian function.	
*/

	int nag_fft_multiple_hermitian(
		int m, //the number of sequences to be transformed
		int n, //the number of data values in each sequence
		double x[],	// Input: the m Hermitian sequences must be stored consecutively in x in Hermitian form.  Output: the components of the m discrete Fourier transforms, are stored consecutively.
		const double trig[]	//trigonometric coefficients are returned by a call of nag_fft_init_trig (c06gzc).
); // computes the discrete Fourier transforms of m Hermitian sequences, each contains n complex data values.


/**	c06frc
		computes the discrete Fourier transforms of m sequences, each containing n complex data values.
	
Example1:
	Assume "Data1" Worksheet has 4 columns, the first two columns contain 18 data each.  This piece 
	of code computes the discrete Fourier transforms of 3 sequences, each containing 6 complex data 
	values. and put the result to the third column (real part) and the fourth column (imag part).
	
	double trig[40];
	int m = 3, n = 6;
	//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(n, trig);	
	nag_fft_multiple_complex(m, n, x, y, trig);
	//Put the result to worksheet "data1" the third and fourth column.
	dx = x;
	dy = y;
	
	
Example2:
	This program reads in sequences of complex data values and prints their discrete Fourier
	transforms (as computed by nag_fft_multiple_complex). Inverse transforms are then calculated
	using nag_conjugate_complex (c06gcc) and nag_fft_multiple_complex and printed out, showing that
	the original sequences are restored.

void test_nag_fft_multiple_complex()
{
	#define MMAX 5
	#define NMAX 20
	double trig[40];
	int i, j, m, n;
	double x[100] = {0.3854, 0.6772, 0.1138, 0.6751, 0.6362, 0.1424,
	 				 0.9172, 0.0644, 0.6037, 0.6430, 0.0428, 0.4815,
	 				 0.1156, 0.0685, 0.2060, 0.8630, 0.6967, 0.2792};
	
	double y[100] = {0.5417, 0.2983, 0.1181, 0.7255, 0.8638, 0.8723,
					 0.9089, 0.3118, 0.3465, 0.6198, 0.2668, 0.1614,
					 0.6214, 0.8681, 0.7060, 0.8652, 0.9190, 0.3355};
	m = 3;
	n = 6;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -