这个问题是针对任何数字食谱的粉丝或任何理解 FFT 的人。
谁能解释为什么实际分量是由 -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);
我假设数字配方必须使用一些三角标识?我似乎无法弄清楚,这本书根本没有解释。
代码在这里找到: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