FFTW: inverse direct fft not equal to the original function

I am trying to use FFTW to calculate fast sums, and I ran into a problem:

int numFreq3 = numFreq*numFreq*numFreq;

FFTW_complex* dummy_sq_fft = (FFTW_complex*)FFTW_malloc( sizeof(FFTW_complex)*numFreq3 );

FFTW_complex* dummy_sq = (FFTW_complex*)FFTW_malloc( sizeof(FFTW_complex)*numFreq3 );

FFTW_complex* orig = (FFTW_complex*)FFTW_malloc( sizeof(FFTW_complex)*numFreq3 );

FFTW_plan dummyPlan = FFTW_plan_dft_3d( numFreq, numFreq, numFreq,
                  orig, dummy_sq_fft,
                  FFTW_FORWARD, FFTW_MEASURE );

FFTW_plan dummyInvPlan = FFTW_plan_dft_3d( numFreq, numFreq, numFreq,
                      dummy_sq_fft, dummy_sq,
                      FFTW_BACKWARD, FFTW_MEASURE );

for(int i= 0; i < numFreq3; i++) {
  orig[ i ][ 0 ] = sparseProfile02[ 0 ][ i ][ 0 ];
  //img. part == 0
  orig[ i ][ 1 ]  = sparseProfile02[ 0 ][ i ] [ 1 ];
}

FFTW_execute(dummyPlan);
FFTW_execute(dummyInvPlan);

int count = 0; 
for(int i=0; i<numFreq3; i++) {
  double factor = dummy_sq[ i ][ 0 ]/sparseProfile02[ 0 ][ i ][ 0 ];

  if(factor < 0) {
    count++;
  }
}

std::cout<<"Count "<<count<<"\n";

FFTW_free(dummy_sq_fft);
FFTW_free(dummy_sq);
FFTW_destroy_plan(dummyPlan);
FFTW_destroy_plan(dummyInvPlan);

(Here sparseProfile02 [0] is of type FFTW_complex * and contains only positive real data.)

Since we have dummy_sq = IFFT (FFT (sparseProfile02 [0])), we should have dummy_sq = n ^ 3 * sparseProfile02. But this is true only at certain points in time; in fact, the values ​​in the dummy_sq grid are negative when the corresponding values ​​in the sparseProfile02 grid are zero (but not vice versa). Does anyone know why this is happening?

+3
source share
2 answers

, fftw (), , fftw , , 'n' .

.

+2

( ) , , , . , , ( ).

fabs(dummy_sq[i][0] - numFreq*numFreq*numFreq*sparseProfile02[0][i][0])

?

() 1D 2 :

ifft(fft([1e20, 1.0])) != [2e20, 2.0]

1.0 1e20 .

, NaN , sparseProfile02.

+1

Source: https://habr.com/ru/post/1764960/


All Articles