This question is for any Numerical Recipes fan or anyone who understands FFT well.
Can someone explain why the real component is calculated at -2 * (sin (theta / 2)) ^ 2? I don’t seem to wrap my head around it. I saw other examples, such as a http://www.dspdimension.com/admin/dft-a-pied/ tutorial that simply accepts cos (theta) as real and -sin (theta) as imaginary. I also saw here at the base http://www.dspguide.com/ch12/3.htm , which lists it as cos (theta) as real and -sin (theta) as imaginary. I can come up with a few more resources that simply accept cos and -sin as real and imaginary.
cos(theta) = 1-2*(sin(theta/2))^2
if the above trigger value is true, then why doesn't it look like?
theta=isign*(6.28318530717959/mmax); wtemp=sin(0.5*theta); wpr = -2.0*wtemp*wtemp; wpi=sin(theta);
I assume Numericical Recipe should use some kind of trigger? I cannot understand this, and the book does not explain at all.
Code found here: http://ronispc.chem.mcgill.ca/ronis/chem593/sinfft.c.html
#define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr void four1(double *data,unsigned long nn,int isign) { unsigned long n,mmax,m,j,istep,i; double wtemp,wr,wpr,wpi,wi,theta; double tempr,tempi; n=nn << 1; j=1; for (i=1;i<n;i+=2) { if (j > i) { SWAP(data[j],data[i]); SWAP(data[j+1],data[i+1]); } m=n >> 1; while (m >= 2 && j > m) { j -= m; m >>= 1; } j += m; } mmax=2; while (n > mmax) { istep=mmax << 1; theta=isign*(6.28318530717959/mmax); wtemp=sin(0.5*theta); wpr = -2.0*wtemp*wtemp; wpi=sin(theta); wr=1.0; wi=0.0; for (m=1;m<mmax;m+=2) { for (i=m;i<=n;i+=istep) { j=i+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; } }
Mac
source share