[問題] 請問這樣使用fftw正確嗎??

看板C_and_CPP (C/C++)作者時間16年前 (2009/07/23 00:30), 編輯推噓4(4012)
留言16則, 3人參與, 最新討論串1/1
因為研究上的急需要用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
沒有意外的話,compile應該是指fftw3.cpp這類檔案才對,不是.h
07/23 00:45, 1F

07/23 00:46, , 2F
你用g++ -l就是在連結,連結到名字為fftw3的lib檔
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
他一定會有個 Makefile 的 找到你的平台的 Makefile 來 make
07/23 12:26, 6F

07/23 12:27, , 7F
(有的甚至會附 VS 的 proj 檔或是 sln 檔...不知 fftw 有無)
07/23 12:27, 7F

07/23 13:10, , 8F
沒用過什麼 fftw_malloc 不過你的 in 頂多拿來當一維陣列用,
07/23 13:10, 8F

07/23 13:10, , 9F
因為in的資料型態是double *,頂多讓你 cout << in[0];
07/23 13:10, 9F

07/23 13:11, , 10F
找不到就算了,那是出現連結錯誤的人才需要考慮
07/23 13:11, 10F

07/23 14:07, , 11F
謝謝 那請問in的形式該怎改?
07/23 14:07, 11F

07/23 14:23, , 12F
跟一般的 malloc 一樣, 先處理 double ** 的 array
07/23 14:23, 12F

07/23 14:25, , 13F
(double **) fftw_malloc(sizeof(double *) * a);
07/23 14:25, 13F

07/23 14:25, , 14F
再對每一個 malloc(sizeof(double)*b));
07/23 14:25, 14F

07/23 15:13, , 15F
上面這行是什麼意思 真的很不好意思><"
07/23 15:13, 15F

07/23 16:07, , 16F
看這篇: #1AFvltqI
07/23 16:07, 16F
文章代碼(AID): #1APpwYH0 (C_and_CPP)
文章代碼(AID): #1APpwYH0 (C_and_CPP)