※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

/*
* test of self compiled fftw3
*
* @author maeda
* @date 2008/09/09
*/
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
 
#include "fftw3.h"
#pragma comment( lib, "fftw3.lib" )
 
#define SIZE 64
 
int main( void ){
 
	fftw_complex *in  = NULL;
	fftw_complex *out = NULL;
	fftw_plan p       = NULL;
	int i;
 
	size_t mem_size = sizeof(fftw_complex) * SIZE;
	in  = (fftw_complex*)fftw_malloc( mem_size );
	out = (fftw_complex*)fftw_malloc( mem_size );
 
	if( !in || !out ){
		fprintf( stderr, "failed to allocate %d[byte] memory(-.-)\n", (int)mem_size );
		return false;
	}
 
	p = fftw_plan_dft_1d( SIZE, in, out, FFTW_FORWARD, FFTW_ESTIMATE );
 
	// input data creation
	printf("----- INPUT -----\n");
	for( i=0; i<SIZE; i++ ){
		in[i][0] = 1 + 2*sin(2*M_PI*i/SIZE) + sin(4*M_PI*i/SIZE);
		in[i][1] = 0;
		printf("%d : %lf\n", i, in[i][0] );
	}
 
	fftw_execute(p);
 
	// output is DC exchanged and scaled.
	double scale = 1. / SIZE;
	printf("\n----- RESULT -----\n");
	for( i=0; i<SIZE; i++ ){
		printf("%d : %lf %lfi\n", i, out[i][0]*scale, out[i][1]*scale );
	}
 
	if( p   ) fftw_destroy_plan(p);
	if( in  ) fftw_free(in);
	if( out ) fftw_free(out);
 
	return true;
}