From: hackbard Date: Thu, 23 Sep 2004 14:26:21 +0000 (+0000) Subject: finished 1d-dft X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=024d1f9a04d8dd291883d1781e671a4eab7b4c9f;p=my-code%2Fapi.git finished 1d-dft --- diff --git a/fourier/fourier.c b/fourier/fourier.c index fca6d6a..255012b 100644 --- a/fourier/fourier.c +++ b/fourier/fourier.c @@ -8,7 +8,7 @@ int fourier_init(t_fourier *fourier,int outfd) { - fprintf(outfd,"[fourier] initializing fourier api ...\n"); + dprintf(outfd,"[fourier] initializing fourier api ...\n"); fourier->outfd=outfd; fourier->type=0; @@ -25,7 +25,7 @@ int fourier_alloc_data(t_fourier *fourier) { fourier->data[i]=(t_complex *)malloc(fourier->data_len[i]*sizeof(t_complex)); fourier->ftdata[i]=(t_complex *)malloc(fourier->data_len[i]*sizeof(t_complex)); if((fourier->data[i]==NULL)||(fourier->ftdata[i]==NULL)) { - fprintf(fourier->outfd,"[fourier] malloc failed\n"); + dprintf(fourier->outfd,"[fourier] malloc failed\n"); return F_ALLOC_FAIL; } } @@ -37,11 +37,11 @@ int fourier_shutdown(t_fourier *fourier) { int i; - fprintf(fourier->outfd,"[fourier] shutdown\n"); + dprintf(fourier->outfd,"[fourier] shutdown\n"); for(i=0;idim;i++) { - free(fourier->data[dim]); - free(fourier->ftdata[dim]); + free(fourier->data[i]); + free(fourier->ftdata[i]); } return F_SUCCESS; @@ -53,15 +53,15 @@ int fourier_dft_1d(t_fourier *fourier) { double arg; if(fourier->type&FWD) { - for(dim=1;dim<=fourier->dim;dim++) { + for(dim=0;dimdim;dim++) { for(k=0;kdata_len[dim];k++) { fourier->ftdata[dim][k].r=0; fourier->ftdata[dim][k].i=0; for(i=0;idata_len[dim];i++) { /* f(k) = 1/N sum(n=0-N) f(n) exp(-i*k*2*PI*n/N) */ arg=-1.0*k*M_PI*i/fourier->data_len[dim]; - fourier->ftdata[dim][k].r+=(cos(arg)*fourier->data[dim][i]-sin(arg)*fourier->data[dim][i].i); - fourier->ftdata[dim][k].i+=(sin(arg)*fourier->data[dim][i]+cos(arg)*fourier->data[dim][i].i); + fourier->ftdata[dim][k].r+=(cos(arg)*fourier->data[dim][i].r-sin(arg)*fourier->data[dim][i].i); + fourier->ftdata[dim][k].i+=(sin(arg)*fourier->data[dim][i].r+cos(arg)*fourier->data[dim][i].i); } fourier->ftdata[dim][k].r/=fourier->data_len[dim]; fourier->ftdata[dim][k].i/=fourier->data_len[dim]; @@ -75,8 +75,8 @@ int fourier_dft_1d(t_fourier *fourier) { fourier->data[dim][k].i=0; for(i=0;idata_len[dim];i++) { arg=1.0*k*M_PI*i/fourier->data_len[dim]; - fourier->data[dim][k].r+=(cos(arg)*fourier->ftdata[dim][i]-sin(arg)*fourier->ftdata[dim][i].i); - fourier->data[dim][k].i+=(sin(arg)*fourier->ftdata[dim][i]+cos(arg)*fourier->ftdata[dim][i].i); + fourier->data[dim][k].r+=(cos(arg)*fourier->ftdata[dim][i].r-sin(arg)*fourier->ftdata[dim][i].i); + fourier->data[dim][k].i+=(sin(arg)*fourier->ftdata[dim][i].r+cos(arg)*fourier->ftdata[dim][i].i); } } } @@ -85,9 +85,17 @@ int fourier_dft_1d(t_fourier *fourier) { return F_SUCCESS; } +int fourier_dft_2d(t_fourier *fourier) { + return 0; +} + +int fourier_dft_3d(t_fourier *fourier) { + return 0; +} + int fourier_calc(t_fourier *fourier) { - fprintf(fourier->outfd,"[fourier] %d dimensional %c-%cft calculation ...\n", + dprintf(fourier->outfd,"[fourier] %d dimensional %c-%cft calculation ...\n", fourier->dim, ((fourier->type&FWD)?'f':'b'), ((fourier->type&DFT)?'d':'f')); @@ -104,13 +112,13 @@ int fourier_calc(t_fourier *fourier) { fourier_dft_3d(fourier); break; default: - fprintf(fourier->outfd,"[fourier] dimension failure\n"); + dprintf(fourier->outfd,"[fourier] dimension failure\n"); return F_DIM_FAILURE; } return F_SUCCESS; } else { - fprintf(fourier->outfd,"[fourier] fft not supported by now\n"); + dprintf(fourier->outfd,"[fourier] fft not supported by now\n"); return F_NOT_SUPPORTED; } } diff --git a/fourier/fourier.h b/fourier/fourier.h index f3cab6b..39aee41 100644 --- a/fourier/fourier.h +++ b/fourier/fourier.h @@ -4,7 +4,10 @@ #define FOURIER_H /* includes */ +#define _GNU_SOURCE #include +#include +#include /* defines */ #define F_SUCCESS 1 @@ -36,6 +39,8 @@ typedef struct s_fourier { /* function prototypes */ int fourier_init(t_fourier *fourier,int outfd); int fourier_dft_1d(t_fourier *fourier); +int fourier_dft_2d(t_fourier *fourier); +int fourier_dft_3d(t_fourier *fourier); int fourier_calc(t_fourier *fourier); #endif