i'm getting strange glitch in fft graph white noise:
i've checked reference program , while noise file seems fine. bug in implementation?
void four1(float data[], int nn, int isign) { int n, mmax, m, j, istep, i; float wtemp, wr, wpr, wpi, wi, theta; float tempr, tempi; n = nn << 1; j = 1; (int = 1; < n; += 2) { if (j > i) { tempr = data[j]; data[j] = data[i]; data[i] = tempr; tempr = data[j + 1]; data[j + 1] = data[i + 1]; data[i + 1] = tempr; } m = n >> 1; while (m >= 2 && j > m) { j -= m; m >>= 1; } j += m; } mmax = 2; while (n > mmax) { istep = 2 * mmax; theta = twopi / (isign * mmax); wtemp = sin(0.5 * theta); wpr = -2.0 * wtemp * wtemp; wpi = sin(theta); wr = 1.0; wi = 0.0; (m = 1; m < mmax; m += 2) { (i = m; <= n; += istep) { j = + mmax; tempr = wr * data[j] - wi * data[j + 1]; tempi = wr * data[j + 1] + wi * data[j]; data[j] = data[i] - tempr; data[j + 1] = data[i + 1] - tempi; data[i] += tempr; data[i + 1] += tempi; } wr = (wtemp = wr) * wpr - wi * wpi + wr; wi = wi * wpr + wtemp * wpi + wi; } mmax = istep; } }
apart few minor changes, code appears taken out of 2nd edition of numerical recipes in c. documentation function (taken book) states:
replaces
data[1..2*nn]
discrete fourier transform, ifisign
input 1; or replacesdata[1..2*nn]
nn
times inverse discrete fourier transform, ifisign
input −1.data
complex array of lengthnn
or, equivalently, real array of length2*nn
.nn
must integer power of 2 (this not checked for!).
this implementation yields correct results, given input array 1-based indexing. can choose use same indexing convention allocating c array of size 2*nn+1
, filling array starting @ index 1. alternatively pass array of size 2*nn
has been fill starting @ index 0, calling four1(data-1, nn, isign)
(notice -1
offset on data
array).
Comments
Post a Comment