Skip to content

Instantly share code, notes, and snippets.

@Ben-0-mad
Created August 7, 2021 14:06
Show Gist options
  • Save Ben-0-mad/92c87bbbf72579410c185cef8dda3a18 to your computer and use it in GitHub Desktop.
Save Ben-0-mad/92c87bbbf72579410c185cef8dda3a18 to your computer and use it in GitHub Desktop.
FFT of (0,1,2,3,4,5,6,7) using FFTW3
#include <fftw3.h>
#include <iostream>
int main()
{
int numOfPoints = 8;
fftw_complex* input = new fftw_complex[numOfPoints];
fftw_complex* output = new fftw_complex[numOfPoints];
for (int i = 0; i <numOfPoints; i++){
input[i][0] = i;
input[i][1] = 0;
}
fftw_plan plan = fftw_plan_dft_1d(numOfPoints,
input,
output,
FFTW_FORWARD,
FFTW_ESTIMATE);
fftw_execute(plan);
fftw_destroy_plan(plan);
for (int i = 0; i < numOfPoints; i++){
std::cout << output[i][0] << " + i*" << output[i][1] << std::endl;
}
fftw_free(input);
fftw_free(output);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment