void fun_fourier_transform_FFT_N_6(int N,std::complex<double> tab[])
{
//N=6
//author marcin matysek (r)ewertyn.PL
const double pi=3.141592653589793238462;
std::complex<double> tab2[6]={}; // tab2[]==N
std::complex<double> w1[1]={{1,0}};
std::complex<double> w2[1]={{1,0}};
std::complex<double> w3[1]={{1,0}};
std::complex<double> w4[1]={{1,0}};
std::complex<double> w5[1]={{1,0}};
std::complex<double> w6[1]={{1,0}};
std::complex<double> tmp=0;
double tmp5;
int k=0;
int n=0;
tmp5=2*pi/(N/1);
//stage 1
k=0,n=0;
w2[0].real()= cos(k*n*tmp5);
w2[0].imag()=-sin(k*n*tmp5);
w1[0].real()= cos(k*n*tmp5);
w1[0].imag()=-sin(k*n*tmp5);
tab2[0]=w1[0]*tab[0]+w2[0]*tab[3];
tab2[3]=w1[0]*tab[0]-w2[0]*tab[3];
w2[0].real()= cos(k*n*tmp5);
w2[0].imag()=-sin(k*n*tmp5);
w1[0].real()= cos(k*n*tmp5);
w1[0].imag()=-sin(k*n*tmp5);
tab2[1]=w1[0]*tab[1]+w2[0]*tab[4];
tab2[4]=w1[0]*tab[1]-w2[0]*tab[4];
w2[0].real()= cos(k*n*tmp5);
w2[0].imag()=-sin(k*n*tmp5);
w1[0].real()= cos(k*n*tmp5);
w1[0].imag()=-sin(k*n*tmp5);
tab2[2]=w1[0]*tab[2]+w2[0]*tab[5];
tab2[5]=w1[0]*tab[2]-w2[0]*tab[5];
////////////////////////////////////////////////
//stage 2 nb1
w1[0].real()= cos(0*tmp5);//0
w1[0].imag()=-sin(0*tmp5);//0
w2[0].real()= cos(0*tmp5);//0
w2[0].imag()=-sin(0*tmp5);//0
w5[0].real()= cos(0*tmp5);//0
w5[0].imag()=-sin(0*tmp5);//0
tab[0]=w1[0]*tab2[0]+w2[0]*tab2[1]+w5[0]*tab2[2];
w3[0].real()= cos(0*tmp5);//0
w3[0].imag()=-sin(0*tmp5);//0
w4[0].real()= cos(1*tmp5);//1
w4[0].imag()=-sin(1*tmp5);//1
w6[0].real()= cos(2*tmp5);//2
w6[0].imag()=-sin(2*tmp5);//2
tab[1]=w3[0]*tab2[0]-w4[0]*tab2[1]+w6[0]*tab2[2];
//or
//w3[0].real()= cos(0*tmp5);//0
//w3 [0].imag()=-sin(0*tmp5);//0
//w4[0].real()= cos(4*tmp5);//
//w4[0].imag()=-sin(4*tmp5);//
//w6[0].real()= cos(2*tmp5);//
//w6[0].imag()=-sin(2*tmp5);//
//tab[1]=w3[0]*tab2[0]+w4[0]*tab2[1]+w6[0]*tab2[2];
w1[0].real()= cos(0*tmp5);//0
w1[0].imag()=-sin(0*tmp5);//0
w2[0].real()= cos(2*tmp5);//2
w2[0].imag()=-sin(2*tmp5);//2
w5[0].real()= cos(4*tmp5);//4
w5[0].imag()=-sin(4*tmp5);//4
tab[2]=w1[0]*tab2[0]+w2[0]*tab2[1]+w5[0]*tab2[2];
//or
//w1[0].real()= cos(0*tmp5);//0
//w1[0].imag()=-sin(0*tmp5);//0
//w2[0].real()= cos(2*tmp5);//
//w2[0].imag()=-sin(2*tmp5);//
//w5[0].real()= cos(1*tmp5);//
//w5[0].imag()=-sin(1*tmp5);//
//tab[2]=w1[0]*tab2[0]+w2[0]*tab2[1]-w5[0]*tab2[2];
//stage 2 nb2
int n1=3;
w1[0].real()= cos(0*tmp5);//0
w1[0].imag()=-sin(0*tmp5);//0
w2[0].real()= cos(0*tmp5);//0
w2[0].imag()=-sin(0*tmp5);//0
w3[0].real()= cos(0*tmp5);//0
w3[0].imag()=-sin(0*tmp5);//0
tab[0+n1]=w1[0]*tab2[0+n1]+w2[0]*tab2[1+n1]-w3[0]*tab2[2+n1];
w3[0].real()= cos(0*tmp5);//0
w3[0].imag()=-sin(0*tmp5);//0
w4[0].real()= cos(1*tmp5);//1
w4[0].imag()=-sin(1*tmp5);//1
w6[0].real()= cos(2*tmp5);//2
w6[0].imag()=-sin(2*tmp5);//2
tab[1+n1]=w3[0]*tab2[0+n1]+w4[0]*tab2[1+n1]+w6[0]*tab2[2+n1];
w1[0].real()= cos(0*tmp5);//0
w1[0].imag()=-sin(0*tmp5);//0
w2[0].real()= cos(2*tmp5);//2
w2[0].imag()=-sin(2*tmp5);//2
w5[0].real()= cos(4*tmp5);//4
w5[0].imag()=-sin(4*tmp5);//4
tab[2+n1]=w1[0]*tab2[0+n1]-w2[0]*tab2[1+n1]+w5[0]*tab2[2+n1];
//inverse
tmp=tab[1];
tab[1]=tab[4];
tab[4]=tmp;
for(int j=0;j<N;j++)
{
tab[j].real() =tab[j].real()*2/N;
tab[j].imag() =tab[j].imag()*2/N;
}
}
void void fun_fourier_transform_FFT_N_6v2(int N,std::complex<double> tab[])
{
//N=6
//author marcin matysek (r)ewertyn.PL
const double pi=3.141592653589793238462;
std::complex<double> tab2[6]={}; // tab2[]==N
std::complex<double> w1[1]={{1,0}};
std::complex<double> w2[1]={{1,0}};
std::complex<double> w3[1]={{1,0}};
std::complex<double> w4[1]={{1,0}};
std::complex<double> w5[1]={{1,0}};
std::complex<double> w6[1]={{1,0}};
std::complex<double> tmp=0;
double tmp5;
int k=0;
int n=0;
tmp5=2*pi/(N/1);
//stage 1
k=0,n=0;
w2[0].real()= cos(k*n*tmp5);
w2[0].imag()=-sin(k*n*tmp5);
w1[0].real()= cos(k*n*tmp5);
w1[0].imag()=-sin(k*n*tmp5);
tab2[0]=w1[0]*tab[0]+w2[0]*tab[3];
tab2[3]=w1[0]*tab[0]-w2[0]*tab[3];
w2[0].real()= cos(k*n*tmp5);
w2[0].imag()=-sin(k*n*tmp5);
w1[0].real()= cos(k*n*tmp5);
w1[0].imag()=-sin(k*n*tmp5);
tab2[1]=w1[0]*tab[1]+w2[0]*tab[4];
tab2[4]=w1[0]*tab[1]-w2[0]*tab[4];
w2[0].real()= cos(k*n*tmp5);
w2[0].imag()=-sin(k*n*tmp5);
w1[0].real()= cos(k*n*tmp5);
w1[0].imag()=-sin(k*n*tmp5);
tab2[2]=w1[0]*tab[2]+w2[0]*tab[5];
tab2[5]=w1[0]*tab[2]-w2[0]*tab[5];
//stage 2 nb1
w1[0].real()= cos(0*tmp5);//0
w1[0].imag()=-sin(0*tmp5);//0
w2[0].real()= cos(0*tmp5);//0
w2[0].imag()=-sin(0*tmp5);//0
w5[0].real()= cos(0*tmp5);//0
w5[0].imag()=-sin(0*tmp5);//0
tab[0]=w1[0]*tab2[0]+w2[0]*tab2[1]+w5[0]*tab2[2];
w3[0].real()= cos(0*tmp5);//0
w3[0].imag()=-sin(0*tmp5);//0
w4[0].real()= cos(1*tmp5);//1
w4[0].imag()=-sin(1*tmp5);//1
w6[0].real()= cos(2*tmp5);//2
w6[0].imag()=-sin(2*tmp5);//2
tab[1]=w3[0]*tab2[0]-w4[0]*tab2[1]+w6[0]*tab2[2];
w1[0].real()= cos(0*tmp5);//0
w1[0].imag()=-sin(0*tmp5);//0
w2[0].real()= cos(2*tmp5);//2
w2[0].imag()=-sin(2*tmp5);//2
w5[0].real()= cos(4*tmp5);//4
w5[0].imag()=-sin(4*tmp5);//4
tab[2]=w1[0]*tab2[0]+w2[0]*tab2[1]+w5[0]*tab2[2];
int n1=3;
w1[0].real()= cos(0*tmp5);//0
w1[0].imag()=-sin(0*tmp5);//0
w2[0].real()= cos(0*tmp5);//0
w2[0].imag()=-sin(0*tmp5);//0
w3[0].real()= cos(0*tmp5);//0
w3[0].imag()=-sin(0*tmp5);//0
tab[0+n1]=w1[0]*tab2[0+n1]+w2[0]*tab2[1+n1]-w3[0]*tab2[2+n1];
w3[0].real()= cos(0*tmp5);//0
w3[0].imag()=-sin(0*tmp5);//0
w4[0].real()= cos(4*tmp5);//
w4[0].imag()=-sin(4*tmp5);//
w6[0].real()= cos(2*tmp5);//
w6[0].imag()=-sin(2*tmp5);//
tab[1+n1]=w3[0]*tab2[0+n1]-w4[0]*tab2[1+n1]+w6[0]*tab2[2+n1];
//or
// w3[0].real()= cos(0*tmp5);//0
// w3[0].imag()=-sin(0*tmp5);//0
// w4[0].real()= cos(2*tmp5);//
// w4[0].imag()=-sin(2*tmp5);//
// w6[0].real()= cos(4*tmp5);//
// w6[0].imag()=-sin(4*tmp5);//
// tab[1+n1]=w3[0]*tab2[0+n1]+w4[0]*tab2[1+n1]-w6[0]*tab2[2+n1];
w1[0].real()= cos(0*tmp5);//0
w1[0].imag()=-sin(0*tmp5);//0
w2[0].real()= cos(4*tmp5);//
w2[0].imag()=-sin(4*tmp5);//
w5[0].real()= cos(2*tmp5);//
w5[0].imag()=-sin(2*tmp5);//
tab[2+n1]=w1[0]*tab2[0+n1]+w2[0]*tab2[1+n1]-w5[0]*tab2[2+n1];
//inverse
tmp=tab[1];
tab[1]=tab[4];
tab[4]=tmp;
for(int j=0;j<N;j++)
{
tab[j].real() =tab[j].real()*2/N;
tab[j].imag() =tab[j].imag()*2/N;
}
}
Brak komentarzy:
Prześlij komentarz