- for(i=0;i<fourier->dim;i++) {
- if((fourier->data[i]=(t_complex *)malloc(sizeof(t_complex)*fourier->data_len[i]))==NULL) {
- fprintf(fourier->outfd,"[fourier] malloc for data dim %d failed\n",i);
- return F_MALLOC_ERROR;
+ return F_SUCCESS;
+}
+
+int fourier_dft_1d(t_fourier *fourier) {
+
+ int i,k,dim;
+ double arg;
+
+ if(fourier->type&FWD) {
+ for(dim=1;dim<=fourier->dim;dim++) {
+ for(k=0;k<fourier->data_len[dim];k++) {
+ fourier->ftdata[dim][k].r=0;
+ fourier->ftdata[dim][k].i=0;
+ for(i=0;i<fourier->data_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/=fourier->data_len[dim];
+ fourier->ftdata[dim][k].i/=fourier->data_len[dim];
+ }
+ }
+ }
+ else {
+ for(dim=1;dim<=fourier->dim;dim++) {
+ for(k=0;k<fourier->data_len[dim];k++) {
+ fourier->data[dim][k].r=0;
+ fourier->data[dim][k].i=0;
+ for(i=0;i<fourier->data_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);
+ }
+ }