[問題] FFT程式碼問題

看板C_and_CPP (C/C++)作者 (psallen)時間14年前 (2012/01/06 15:15), 編輯推噓2(205)
留言7則, 3人參與, 最新討論串1/1
小弟是C++新手,最近需要用到快速傅立葉轉換(FFT),上網google後有找到 以下的程式碼,但在Debug的時候在最後一行return(TRUE)顯示出 IntelliSense: 識別項 "True" 未定義,請問該如何修改?先謝謝大家了。 /* This computes an in-place complex-to-complex FFT x and y are the real and imaginary arrays of 2^m points. dir = 1 gives forward transform dir = -1 gives reverse transform */ short FFT(short int dir,long m,double *x,double *y) { long n,i,i1,j,k,i2,l,l1,l2; double c1,c2,tx,ty,t1,t2,u1,u2,z; /* Calculate the number of points */ n = 1; for (i=0;i<m;i++) n *= 2; /* Do the bit reversal */ i2 = n >> 1; j = 0; for (i=0;i<n-1;i++) { if (i < j) { tx = x[i]; ty = y[i]; x[i] = x[j]; y[i] = y[j]; x[j] = tx; y[j] = ty; } k = i2; while (k <= j) { j -= k; k >>= 1; } j += k; } /* Compute the FFT */ c1 = -1.0; c2 = 0.0; l2 = 1; for (l=0;l<m;l++) { l1 = l2; l2 <<= 1; u1 = 1.0; u2 = 0.0; for (j=0;j<l1;j++) { for (i=j;i<n;i+=l2) { i1 = i + l1; t1 = u1 * x[i1] - u2 * y[i1]; t2 = u1 * y[i1] + u2 * x[i1]; x[i1] = x[i] - t1; y[i1] = y[i] - t2; x[i] += t1; y[i] += t2; } z = u1 * c1 - u2 * c2; u2 = u1 * c2 + u2 * c1; u1 = z; } c2 = sqrt((1.0 - c1) / 2.0); if (dir == 1) c2 = -c2; c1 = sqrt((1.0 + c1) / 2.0); } /* Scaling for forward transform */ if (dir == 1) { for (i=0;i<n;i++) { x[i] /= n; y[i] /= n; } } return(TRUE); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.75.201 ※ 編輯: psallen 來自: 140.116.75.201 (01/06 15:18)

01/06 15:18, , 1F
你覺得 TRUE 是什麼東西?
01/06 15:18, 1F

01/06 15:19, , 2F
就程式結構而言,不知道要return給caller有什麼做用?
01/06 15:19, 2F

01/06 15:23, , 3F
我也不太清楚那個意思,我刪掉RETURN那行後他會顯示
01/06 15:23, 3F

01/06 15:23, , 4F
FFT需要傳回值
01/06 15:23, 4F

01/06 15:25, , 5F
可以查一下C/C++的書或網路資料,找"副程式"跟"回傳值"
01/06 15:25, 5F

01/06 15:27, , 6F
OK我查查看 感謝
01/06 15:27, 6F

01/07 00:01, , 7F
真的 沒有了
01/07 00:01, 7F
文章代碼(AID): #1F1f-KuB (C_and_CPP)
文章代碼(AID): #1F1f-KuB (C_and_CPP)