[問題] 請問這樣使用fftw正確嗎??
因為研究上的急需要用fft
但是我本身程式基礎不夠
碰到了一點問題不知之怎麼解決
希望大家幫我解惑
拜託了><
我需要做的是input 2D 的 real data
作fft以後作一些運算在轉回來
於是我先做了以下簡單測試
--
#include <complex>
#include <iostream>
#include <fftw3.h>
//g++ test.cpp -lfftw3 -lm
using namespace std;
int main()
{
double *in;
fftw_complex *out;
int a=4,b=4;
int c=b/2+1;
int N1=a*b,N2=a*c;
fftw_plan p;
in= (double*) fftw_malloc(sizeof(double) * N1);
out= (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N2);
for (int i=0; i<a; i++){
for (int j=0; j<b; j++){
in[i][j] = i+j;
cout << in[i][j] <<" "; //問題在以上兩行
}
cout<<endl;
}
p = fftw_plan_dft_r2c_2d(a, b, in, out, FFTW_ESTIMATE);
fftw_execute(p);
for (int i=0; i<a; i++){
for (int j=0; j<c; j++){
cout << out[i][j] <<" ";
}
cout<<endl;
}
fftw_destroy_plan(p);
fftw_free(in); fftw_free(out);
return 0;
}
--
會跑出下列訊息
test.cpp:26: 錯誤:「double[int]」 做為陣列下標類型無效
test.cpp:27: 錯誤:「double[int]」 做為陣列下標類型無效
另外還有個問題
fftw的網站上有一個FAQ
--
Question 3.14. I included your header, but linking still fails.
You're a C++ programmer, aren't you? You have to compile the FFTW library and
link it into your program, not just #include <fftw3.h>.
--
我照他說的 compile fftw3.h
於是產生了一個檔案:fftw3.h.gch
但是我不太懂"link it into your program"是甚麼意思
先感謝大家的回答!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.166.196.85
推
07/23 00:45, , 1F
07/23 00:45, 1F
→
07/23 00:46, , 2F
07/23 00:46, 2F
※ 編輯: peter74123 來自: 118.166.196.161 (07/23 01:12)
→
07/23 10:13, , 3F
07/23 10:13, 3F
→
07/23 10:31, , 4F
07/23 10:31, 4F
→
07/23 10:32, , 5F
07/23 10:32, 5F
推
07/23 12:26, , 6F
07/23 12:26, 6F
→
07/23 12:27, , 7F
07/23 12:27, 7F
推
07/23 13:10, , 8F
07/23 13:10, 8F
→
07/23 13:10, , 9F
07/23 13:10, 9F
→
07/23 13:11, , 10F
07/23 13:11, 10F
→
07/23 14:07, , 11F
07/23 14:07, 11F
→
07/23 14:23, , 12F
07/23 14:23, 12F
→
07/23 14:25, , 13F
07/23 14:25, 13F
→
07/23 14:25, , 14F
07/23 14:25, 14F
→
07/23 15:13, , 15F
07/23 15:13, 15F
推
07/23 16:07, , 16F
07/23 16:07, 16F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章