有人能解释一下为什么实部通过 -2*(sin(theta/2))^2 计算吗?我似乎无法理解它。我看过其他的例子,比如 http://www.dspdimension.com/admin/dft-a-pied/ 教程,它将 cos(theta) 作为实部,-sin(theta) 作为虚部。我还在这里看到了基本的 http://www.dspguide.com/ch12/3.htm,其中将 cos(theta) 列为实部,-sin(theta) 列为虚部。我可以想到更多的资源,它们只是将 cos 和 -sin 视为实部和虚部。
cos(theta) = 1-2*(sin(theta/2))^2
如果上述三角恒等式是正确的,那么为什么这个结论不成立?
theta=isign*(6.28318530717959/mmax);
wtemp=sin(0.5*theta);
wpr = -2.0*wtemp*wtemp;
wpi=sin(theta);
我假设Numerical Recipe必须使用某些三角恒等式?我似乎无法弄清楚,而且这本书根本没有解释。
代码在这里: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;
}
}
#undef SWAP