I'm studying FFTW and My code was stopped on fftw_plan_dft_2d.
Here is my flow.
- I flattened my 2d complex array into 1d fftw_complex array.
- Hand over this array to 'FFT' which has fftw function.
- It is run okay When I run this with width : 10, height : 10.
But I got error when I run this with different width and height like width : 10, height : 12.
When I run this, it just stopped with -1073740940 CODE.
So run again with debug mode, it stopped in below line
forward = fftw_plan_dft_2d(width, height, fftData_in, fftData_out, FFTW_FORWARD, FFTW_ESTIMATE);
I think my code has no problem and also c2c has no problem with different nx,ny size.
Could you guys help me with your knowledge?
#include "fftw3.h"
#include <math.h>
#include <complex>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
fftw_complex* FFT(double** data_Y, int t_height, int t_width)
{
int i, j, height, width;
height = t_height;
width = t_width;
fftw_complex *fftData_in;
fftw_complex *fftData_out;
fftData_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * height*width); // input buffer
fftData_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * height*width); // output buffer
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
fftData_in[i*height + j][0] = data_Y[i][j];
fftData_in[i*height + j][1] = 0;
fftData_out[i*height + j][0] = 0;
fftData_out[i*height + j][1] = 0;
}
}
fftw_plan forward;
forward = fftw_plan_dft_2d(width, height, fftData_in, fftData_out, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(forward);
fftw_destroy_plan(forward);
fftw_free(fftData_in);
return fftData_out;
}
int main()
{
int m_height = 10;
int m_width = 5;
double ** data_Y = new double*[m_height];
for (int i = 0; i < m_height; i++) {
data_Y[i] = new double[m_width];
}
for (int i = 0; i < m_height; i++) {
for (int j = 0; j < m_width; j++) {
data_Y[i][j] = j + 1;
}
}
for (int i = 0; i < m_height; i++) {
for (int j = 0; j < m_width; j++) {
printf("[%f]",data_Y[i][j]);
}
printf("
");
}
//FFT
fftw_complex *fftData = FFT(data_Y, m_height, m_width);
printf("============================REAL=======================
");
for (int i = 0; i < m_height; i++) {
for (int j = 0; j < m_width; j++) {
printf("[%.5f]", fftData[i*m_height + j][0]);
}
printf("
");
}
printf("============================IMAG===========================
");
for (int i = 0; i < m_height; i++) {
for (int j = 0; j < m_width; j++) {
printf("[%.5f]", fftData[i*m_height + j][1]);
}
printf("
");
}
return 0;
}
question from:
https://stackoverflow.com/questions/66057889/error-when-executing-2d-dft-using-different-row-col-size-with-fftw 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…