3
$\begingroup$

does anyone understand how to use the pocketfft by martin reinecke?

Link: https://gitlab.mpcdf.mpg.de/mtr/pocketfft

Basically it's just this snipped of code:

rfft_forward(rfft_plan plan, double c[], double fct);

I understood,

  1. that the plan needs to be created to the "internal" planning of the algorithm,

  2. the array c[] is input data and will be overwritten with output data, but what stands the double fct for?

I recorded some data with my embededd system (STM32f446RE with a sensor) and did a reference fft in python ( that one works ) which differs alot from the pocketfft and I dont understand why

Is my code maybe wrong somehow?

double resultD[SIZE];
for (i=0; i < SIZE; i++){                     
     resultD[i] = (double)result[i][1];
}

rfft_plan plan = make_rfft_plan(SIZE);
rfft_forward(plan, resultD, 1.);
destroy_rfft_plan(plan);

n = sprintf( buffer, "%s\n", "X" );
HAL_UART_Transmit(&huart2, buffer, n, 1000);

for(i = 0; i < SIZE; i++) {
n = sprintf( buffer, "%f\n", resultD[i] );
    HAL_UART_Transmit(&huart2, buffer, n, 1000);
}  
             

fft

In blue u can see the reference fft with python, in red the fft from the µC and the code above.

It differs in amplitude and it's shifted.

Therefor I think it's not about just a scaling factor

$\endgroup$
2
  • $\begingroup$ Thanks for adding the plot (please add it to your question by editing your question next time; it's not an "answer"). It looks like the Python (blue) plot is using an FFT size twice the length of the pocketfft one. Try changing rfft_plan plan = make_rfft_plan(SIZE); to rfft_plan plan = make_rfft_plan(2*SIZE); and see if they better align. $\endgroup$
    – Peter K.
    Aug 1, 2022 at 15:24
  • $\begingroup$ unfortunately playing with rfft_plan plan = make_rfft_plan(2*SIZE); did not help here. Is it maybe possible that two different ffts deliver such different results? $\endgroup$
    – jp21
    Aug 2, 2022 at 6:40

1 Answer 1

2
$\begingroup$

I'm the author of pocketfft. The fct parameter is simply a factor which is multiplied to the result of the transform call. You can use this to get normalized transforms (pocketfft will do unnormalized transforms if you use fct=1).

Concerning the results: the output format of pocketfft's rfft_forward call is a specific "half-complex" format which can be difficult to interpret. If you show me the part of the code that computes the Python reference FFT, I should be able to describe how the results can be matched.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.