czwartek, 13 kwietnia 2017
fourier transform iFFT radix-4 for N=256 algorithm c++ source code implementation
//source:
//https://www.google.ch/patents/US6957241
//http://www.google.ch/patents/US20020083107
//https://www.beechwood.eu/fft-implementation-r2-dit-r4-dif-r8-dif/
//http://www.cmlab.csie.ntu.edu.tw/cml/dsp/training/coding/transform/fft.html
//http://dsp.stackexchange.com/questions/3481/radix-4-fft-implementation
//author marcin matysek (r)ewertyn.PL
//szybka transformacja fouriera iFFT radix-4 dla N=256 algorytm c++ kod źródłowy implementacja v2
//this is new in that method:
//when you want to have equal results that are in false modificator in normal FFT then change this:
/*
fun_fourier_transform_FFT_radix_4_N_256_official
{
for(int j=0;j<N;j++)
{
tab[j].real() =tab[j].real()*2/N;
tab[j].imag() =tab[j].imag()*2/N;
}
}
//and:
fun_inverse_fourier_transform_FFT_radix_4_N_256_official
{
for(int j=0;j<N;j++)
{
tab[j].real() =tab[j].real()*0.5;
tab[j].imag() =tab[j].imag()*0.5;
}
}
//for official modificator that is only in inverse FFT:
fun_fourier_transform_FFT_radix_4_N_256_official
{
}
fun_inverse_fourier_transform_FFT_radix_4_N_256_official
{
for(int i=0;i<N;i++)
{
tablica1[0][i]=tablica1[0][i]*1/(float)N;
tablica1[1][i]=tablica1[1][i]*1/(float)N;
}
}
*/
//haven't try it with other function that cos(x)+jsin(x)=sin(x+pi/2)+jsin(x)
//fourier transform iFFT radix-4 for N=256 algorithm c++ source code implementation v2
#include <iostream>
#include "conio.h"
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <time.h>
#include <complex>
#include <fstream>
using namespace std;
//complex number method:
void fun_inverse_bits_radix_4(int N,std::complex<double> tab[]);
void fun_fourier_transform_FFT_radix_4_N_256_official_v2(int N,std::complex<double> tab[]);
void fun_inverse_fourier_transform_FFT_radix_4_N_256_official_v2(int N,std::complex<double> tab[]);
void fun_fourier_transform_DFT_method5_full_complex(int N,std::complex<double> tab[]);
int fi=0;
static double diffclock(clock_t clock2,clock_t clock1)
{
double diffticks=clock1-clock2;
double diffms=(diffticks)/(CLOCKS_PER_SEC/1000);
return diffms;
}
int main()
{
int N;
//if N==period of signal in table tab[] then resolution = 1 Hz
N=256;
std::complex<double> tab2[256]={};
std::complex<double> tab3[256]={};
for(int i=0;i<N;i++)
{
tab2[i].real()=i;
tab2[i].imag()=N+i;
tab3[i].real()=i;
tab3[i].imag()=N+i;
}
double time2;
double zmienna=0;
cout<<"signal 1="<<endl;
for(int j=0;j<N;j++)
{
cout.precision(4);
cout<<round(tab2[j].real()*1000)/1000<<" ";
}
cout<<endl;
cout<<endl;
for(int j=0;j<N;j++)
{
cout.precision(4);
cout<<round(tab2[j].imag()*1000)/1000<<" ";
}
cout<<endl;
cout<<endl;
cout<<"signal 2="<<endl;
for(int j=0;j<N;j++)
{
cout.precision(4);
cout<<round(tab3[j].real()*1000)/1000<<" ";
}
cout<<endl;
cout<<endl;
for(int j=0;j<N;j++)
{
cout.precision(4);
cout<<round(tab3[j].imag()*1000)/1000<<" ";
}
cout<<endl;
cout<<endl;
clock_t start = clock();
fun_fourier_transform_DFT_method5_full_complex(N,tab3);
//////////////////////////////////////////////////////////
fun_fourier_transform_FFT_radix_4_N_256_official_v2(N,tab2);
fun_inverse_bits_radix_4(N,tab2);
///////////////////////////////////////////////////////////
time2=diffclock( start, clock() );
cout<<"frequency Hz radix-4"<<endl;
for(int j=0;j<N;j++)
{
cout.precision(4);
cout<<round(tab2[j].real()*1000)/1000<<" ";
}
cout<<endl;
cout<<endl;
for(int j=0;j<N;j++)
{
cout.precision(4);
cout<<round(tab2[j].imag()*1000)/1000<<" ";
}
cout<<endl;
cout<<endl;
cout<<"frequency Hz DFT"<<endl;
for(int j=0;j<N;j++)
{
cout.precision(4);
cout<<round(tab3[j].real()*1000)/1000<<" ";
}
cout<<endl;
cout<<endl;
for(int j=0;j<N;j++)
{
cout.precision(4);
cout<<round(tab3[j].imag()*1000)/1000<<" ";
}
cout<<endl;
cout<<endl;
cout<<"if radix-4 == DFT tab2[j].real(): "<<endl;system("pause");
for(int j=0;j<N;j++)
{
if(((tab3[j].real()-tab2[j].real()>=-0.03)&&(tab3[j].real()-tab2[j].real()<=0.03)))
{
cout.precision(4);
cout<<round(tab2[j].real()*1000)/1000<<" ";//system("pause");
}
else {
cout<<-1<<" . ";
}
}
system("pause");
cout<<endl;
/////////////////////////////////////////////////////////////////
fun_inverse_fourier_transform_FFT_radix_4_N_256_official_v2(N,tab2);
fun_inverse_bits_radix_4(N,tab2);
////////////////////////////////////////////////////////////////
cout<<"inverse/signal="<<endl;
for(int j=0;j<N;j++)
{
cout.precision(4);
cout<<round(tab2[j].real()*1000)/1000<<" ";
}
cout<<endl;
cout<<endl;
for(int j=0;j<N;j++)
{
cout.precision(4);
cout<<round(tab2[j].imag()*1000)/1000<<" ";
}
cout<<endl;
cout<<endl;
cout<<endl;
system("pause");
return 0;
}
void fun_inverse_bits_radix_4(int N,std::complex<double> tab[])
{
//code by Sidney Burrus
//http://dsp.stackexchange.com/questions/3481/radix-4-fft-implementation
std::complex<double> t;
//N=4^a;
// Radix-4 bit-reverse
double T;
int j = 0;
int N2 = N>>2;
int N1=0;
for (int i=0; i < N-1; i++) {
if (i < j) {
t = tab[i];
tab[i] = tab[j];
tab[j] = t;
}
N1 = N2;
while ( j >= 3*N1 ) {
j -= 3*N1;
N1 >>= 2;
}
j += N1;
}
}
///////////////
void fun_fourier_transform_DFT_method5_full_complex(int N,std::complex<double> tab[])
{
const double pi=3.141592653589793238462;
std::complex<double> tab2[4096]={}; // tab2[]==N
std::complex<double> w[1]={{1,1}};
double zmienna1=2*pi/(float)N;
double fi2=fi;
for (int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
//complex number method:
w[0].real()=cos(i*j*zmienna1+fi2);
w[0].imag()=(-sin(i*j*zmienna1+fi2));
tab2[i]=tab2[i]+tab[j]*w[0];
}
}
for(int j=0;j<N;j++)
{
tab[j].real() =tab2[j].real()*2/N;
tab[j].imag() =tab2[j].imag()*2/N;
}
}
//////////////////
void fun_inverse_fourier_transform_FFT_radix_4_N_256_official_v2(int N,std::complex<double> tab[])
{
const double pi=3.141592653589793238462;
std::complex<double> tab2[256]={}; // tab2[]==N
std::complex<double> w1[1]={{1,1}};
std::complex<double> w2[1]={{1,1}};
std::complex<double> w3[1]={{1,1}};
std::complex<double> w4[1]={{1,1}};
std::complex<double> w5[1]={{1,1}};
std::complex<double> tmp1,tmp2,tmp3,tmp4;
double tmp5;
int flag=0;
//radix-4
//stage 1
tmp5=2*pi/(N/1);
for(int i=0;i<(N/4);i++)//64
{
w1[0].real()=cos(0*tmp5);
w1[0].imag()=sin(0*tmp5);
w2[0].real()=cos(0*tmp5);
w2[0].imag()=sin(0*tmp5);
w3[0].real()=cos(0*tmp5);
w3[0].imag()=sin(0*tmp5);
w4[0].real()=cos(0*tmp5);
w4[0].imag()=sin(0*tmp5);
tmp1=w1[0]*tab[i+0];
tmp2=w2[0]*tab[i+N/4];
tmp3=w3[0]*tab[i+N/2];
tmp4=w4[0]*tab[i+3*N/4];
tab2[i] =tmp1+tmp2+tmp3+tmp4;
w5[0].real()=0;
w5[0].imag()=1;
tab2[i+N/4] =tmp1-tmp3+w5[0]*(tmp2-tmp4);
tab2[i+N/2] =tmp1-tmp2+tmp3-tmp4;
w5[0].real()=0;
w5[0].imag()=-1;
tab2[i+3*N/4] =tmp1-tmp3+w5[0]*(tmp2-tmp4);
}
///////////////////////////////////
//stage 2
for(int k=0;k<N;k++)
{
tab[k]={0,0};
}
tmp5=2*pi/(N/1);
for(int i=0;i<(N/64);i++)//4
{
for(int j=0;j<(N/16);j++)//16
{
w1[0].real()=cos((0*i+i*j)*tmp5);
w1[0].imag()=sin((0*i+i*j)*tmp5);
w2[0].real()=cos((1*16*i+i*j)*tmp5);
w2[0].imag()=sin((1*16*i+i*j)*tmp5);
w3[0].real()=cos((2*16*i+i*j)*tmp5);
w3[0].imag()=sin((2*16*i+i*j)*tmp5);
w4[0].real()=cos((3*16*i+i*j)*tmp5);
w4[0].imag()=sin((3*16*i+i*j)*tmp5);
tmp1=w1[0]*tab2[0+j+N/(4*1)*i];
tmp2=w2[0]*tab2[N/(16*1)+j+N/(4*1)*i];
tmp3=w3[0]*tab2[N/(8*1) +j+N/(4*1)*i];
tmp4=w4[0]*tab2[3*N/(16*1)+j+N/(4*1)*i];
tab[0+j+N/(4*1)*i] =tmp1+tmp2+ tmp3+tmp4;
w5[0].real()=0;
w5[0].imag()=1;
tab[N/(16*1)+j+N/(4*1)*i] =tmp1-tmp3+w5[0]*(tmp2-tmp4);
tab[N/(8 *1)+j+N/(4*1)*i] =tmp1-tmp2+ tmp3-tmp4;
w5[0].real()=0;
w5[0].imag()=-1;
tab[3*N/(16*1)+j+N/(4*1)*i]=tmp1-tmp3+w5[0]*(tmp2-tmp4);
}
}
//////////////////////////////
//stage 3
int tab4[256]={0};
for(int k=0;k<N;k++)
{
tab2[k]={0,0};
}
tmp5=2*pi/(N/1);
for(int i=0;i<(N/16);i++)//16
{
for(int j=0;j<4;j++)
{
w1[0].real()=cos((i-4*flag)*(16*0+4*j)*tmp5);
w1[0].imag()=sin((i-4*flag)*(16*0+4*j)*tmp5);
w2[0].real()=cos((i-4*flag)*(1*16+4*j)*tmp5);
w2[0].imag()=sin((i-4*flag)*(1*16+4*j)*tmp5);
w3[0].real()=cos((i-4*flag)*(2*16+4*j)*tmp5);
w3[0].imag()=sin((i-4*flag)*(2*16+4*j)*tmp5);
w4[0].real()=cos((i-4*flag)*(3*16+4*j)*tmp5);
w4[0].imag()=sin((i-4*flag)*(3*16+4*j)*tmp5);
tmp1=w1[0]*tab[0+j+N/(4*4)*i];
tmp2=w2[0]*tab[N/(16*4)+j+N/(4*4)*i];
tmp3=w3[0]*tab[N/(8*4) +j+N/(4*4)*i];
tmp4=w4[0]*tab[3*N/(16*4)+j+N/(4*4)*i];
tab2[0+j+N/(4*4)*i] =tmp1+tmp2+ tmp3+tmp4;
w5[0].real()=0;
w5[0].imag()=1;
tab2[N/(16*4)+j+N/(4*4)*i] =tmp1-tmp3+w5[0]*(tmp2-tmp4);
tab2[N/(8*4)+j+N/(4*4)*i] =tmp1-tmp2+ tmp3-tmp4;
w5[0].real()=0;
w5[0].imag()=-1;
tab2[3*N/(16*4)+j+N/(4*4)*i]=tmp1-tmp3+w5[0]*(tmp2-tmp4);
//tab4[0+j+N/(4*4)*i] =(i-4*flag)*(16*0+4*j);
//tab4[N/(16*4)+j+N/(4*4)*i] =(i-4*flag)*(1*16+4*j);
//tab4[N/(8*4)+j+N/(4*4)*i]=(i-4*flag)*(2*16+4*j);
//tab4[3*N/(16*4)+j+N/(4*4)*i]=(i-4*flag)*(3*16+4*j);
}
if((i+1)%4==0){flag++;}
}
/*
for(int i2=0;i2<256;i2++)
{
cout<<tab4[i2]<<endl;
if((i2+1)%16==0){system("pause");}
}
*/
///////////////////////////
//stage 4
for(int k=0;k<N;k++)
{
tab[k]={0,0};
}
tmp5=2*pi/(N/1);
for(int i=0;i<(N/16);i++)//16
{
for(int j=0;j<4;j++)
{
w1[0].real()=cos(0*16*j*tmp5);
w1[0].imag()=sin(0*16*j*tmp5);
w2[0].real()=cos(1*16*j*tmp5);
w2[0].imag()=sin(1*16*j*tmp5);
w3[0].real()=cos(2*16*j*tmp5);
w3[0].imag()=sin(2*16*j*tmp5);
w4[0].real()=cos(3*16*j*tmp5);
w4[0].imag()=sin(3*16*j*tmp5);
tmp1=w1[0]*tab2[N/(4*4)*i+0+4*j];
tmp2=w2[0]*tab2[N/(4*4)*i+1+4*j];
tmp3=w3[0]*tab2[N/(4*4)*i+2+4*j];
tmp4=w4[0]*tab2[N/(4*4)*i+3+4*j];
tab[N/(4*4)*i+0+4*j]=tmp1+tmp2+ tmp3+tmp4;
w5[0].real()=0;
w5[0].imag()=1;
tab[N/(4*4)*i+1+4*j]=tmp1-tmp3+w5[0]*(tmp2-tmp4);
tab[N/(4*4)*i+2+4*j]=tmp1-tmp2+ tmp3-tmp4;
w5[0].real()=0;
w5[0].imag()=-1;
tab[N/(4*4)*i+3+4*j]=tmp1-tmp3+w5[0]*(tmp2-tmp4);
//tab4[N/(4*4)*i+0+4*j] =0*16*j;
//tab4[N/(4*4)*i+1+4*j] =1*16*j;
//tab4[N/(4*4)*i+2+4*j]=2*16*j;
//tab4[N/(4*4)*i+3+4*j]=3*16*j;
}
}
/*
for(int i2=0;i2<256;i2++)
{
cout<<tab4[i2]<<endl;
if((i2+1)%16==0){system("pause");}
}
*/
for(int j=0;j<N;j++)
{
tab[j].real() =tab[j].real()*0.5;
tab[j].imag() =tab[j].imag()*0.5;
}
}
//////////////////////////////
//////////////////////////////
void fun_fourier_transform_FFT_radix_4_N_256_official_v2(int N,std::complex<double> tab[])
{
const double pi=3.141592653589793238462;
std::complex<double> tab2[256]={}; // tab2[]==N
std::complex<double> w1[1]={{1,1}};
std::complex<double> w2[1]={{1,1}};
std::complex<double> w3[1]={{1,1}};
std::complex<double> w4[1]={{1,1}};
std::complex<double> w5[1]={{1,1}};
std::complex<double> tmp1,tmp2,tmp3,tmp4;
double tmp5;
int flag=0;
int flag2=0;
int flag3=0;
int flag4=0;
int flg=0;
int tab4[256]={0};
int tab5[256]={0};
//radix-4
//stage 1
tmp5=2*pi/(N/1);
for(int i=0;i<(N/4);i++)//64
{
w1[0].real()=cos(0*tmp5);
w1[0].imag()=-sin(0*tmp5);
w2[0].real()=cos(0*tmp5);
w2[0].imag()=-sin(0*tmp5);
w3[0].real()=cos(0*tmp5);
w3[0].imag()=-sin(0*tmp5);
w4[0].real()=cos(0*tmp5);
w4[0].imag()=-sin(0*tmp5);
tmp1=w1[0]*tab[i+0];
tmp2=w2[0]*tab[i+N/4];
tmp3=w3[0]*tab[i+N/2];
tmp4=w4[0]*tab[i+3*N/4];
tab2[i] =tmp1+tmp2+tmp3+tmp4;
w5[0].real()=0;
w5[0].imag()=-1;
tab2[i+N/4] =tmp1-tmp3+w5[0]*(tmp2-tmp4);
tab2[i+N/2] =tmp1-tmp2+tmp3-tmp4;
w5[0].real()=0;
w5[0].imag()=1;
tab2[i+3*N/4] =tmp1-tmp3+w5[0]*(tmp2-tmp4);
}
///////////////////////////////////
flag2=0;
flag3=0;
flag=0;
flg=0;
//stage 2
for(int k=0;k<N;k++)
{
tab[k]={0,0};
}
tmp5=2*pi/(N/1);
for(int i=0;i<(N/64);i++)//4
{
for(int j=0;j<(N/16);j++)//16
{
w1[0].real()=cos((0*i+i*j)*tmp5);
w1[0].imag()=-sin((0*i+i*j)*tmp5);
w2[0].real()=cos((1*16*i+i*j)*tmp5);
w2[0].imag()=-sin((1*16*i+i*j)*tmp5);
w3[0].real()=cos((2*16*i+i*j)*tmp5);
w3[0].imag()=-sin((2*16*i+i*j)*tmp5);
w4[0].real()=cos((3*16*i+i*j)*tmp5);
w4[0].imag()=-sin((3*16*i+i*j)*tmp5);
tmp1=w1[0]*tab2[0+j+N/(4*1)*i];
tmp2=w2[0]*tab2[N/(16*1)+j+N/(4*1)*i];
tmp3=w3[0]*tab2[N/(8*1) +j+N/(4*1)*i];
tmp4=w4[0]*tab2[3*N/(16*1)+j+N/(4*1)*i];
tab[0+j+N/(4*1)*i] =tmp1+tmp2+ tmp3+tmp4;
w5[0].real()=0;
w5[0].imag()=-1;
tab[N/(16*1)+j+N/(4*1)*i] =tmp1-tmp3+w5[0]*(tmp2-tmp4);
tab[N/(8 *1)+j+N/(4*1)*i] =tmp1-tmp2+ tmp3-tmp4;
w5[0].real()=0;
w5[0].imag()=1;
tab[3*N/(16*1)+j+N/(4*1)*i]=tmp1-tmp3+w5[0]*(tmp2-tmp4);
/*
tab4[0+j+N/(4*1)*i]=(0*i+i*j);
tab4[N/(16*1)+j+N/(4*1)*i]=(1*16*i+i*j);
tab4[N/(8 *1)+j+N/(4*1)*i]=(2*16*i+i*j);
tab4[3*N/(16*1)+j+N/(4*1)*i]=(3*16*i+i*j);
*/
if((j+1)%16==0){flag++;}
if((j+1)%16==0){flag2++;}
}
if((i+1)%4==0){flag3++;}
}
/*
for(int m=0;m<1;m++)//stage 2
{
for(int i=0;i<4;i++)
{
for(int j=0;j<16;j++)
{
tab5[0*N/(4*4)+N/(4)*i+j]=1*0*i*(j+16*0)+1*1*i*j;
tab5[1*N/(4*4)+N/(4)*i+j]=1*1*i*(j+16*1)+1*0*i*j;
tab5[2*N/(4*4)+N/(4)*i+j]=1*2*i*(j+16*1)-1*1*i*j;
tab5[3*N/(4*4)+N/(4)*i+j]=1*3*i*(j+16*1)-1*2*i*j;
}
}
}
for(int i2=0;i2<256;i2++)
{
cout<<"i2= "<<i2<<" tb4= "<<tab4[i2]<<" =tb5 "<<tab5[i2];
if(tab4[i2]==tab5[i2])cout<<" O..K ";
cout<<endl;
if((i2+1)%16==0){
system("pause");
}
}
*/
//////////////////////////////
flag=0;
flag2=0;
//stage 3
for(int k=0;k<N;k++)
{
tab2[k]={0,0};
}
tmp5=2*pi/(N/1);
for(int i=0;i<(N/16);i++)//16
{
for(int j=0;j<4;j++)
{
w1[0].real()=cos((i-4*flag)*(16*0+4*j)*tmp5);
w1[0].imag()=-sin((i-4*flag)*(16*0+4*j)*tmp5);
w2[0].real()=cos((i-4*flag)*(1*16+4*j)*tmp5);
w2[0].imag()=-sin((i-4*flag)*(1*16+4*j)*tmp5);
w3[0].real()=cos((i-4*flag)*(2*16+4*j)*tmp5);
w3[0].imag()=-sin((i-4*flag)*(2*16+4*j)*tmp5);
w4[0].real()=cos((i-4*flag)*(3*16+4*j)*tmp5);
w4[0].imag()=-sin((i-4*flag)*(3*16+4*j)*tmp5);
tmp1=w1[0]*tab[0+j+N/(4*4)*i];
tmp2=w2[0]*tab[N/(16*4)+j+N/(4*4)*i];
tmp3=w3[0]*tab[N/(8*4) +j+N/(4*4)*i];
tmp4=w4[0]*tab[3*N/(16*4)+j+N/(4*4)*i];
tab2[0+j+N/(4*4)*i] =tmp1+tmp2+ tmp3+tmp4;
w5[0].real()=0;
w5[0].imag()=-1;
tab2[N/(16*4)+j+N/(4*4)*i] =tmp1-tmp3+w5[0]*(tmp2-tmp4);
tab2[N/(8*4)+j+N/(4*4)*i] =tmp1-tmp2+ tmp3-tmp4;
w5[0].real()=0;
w5[0].imag()=1;
tab2[3*N/(16*4)+j+N/(4*4)*i]=tmp1-tmp3+w5[0]*(tmp2-tmp4);
/*
tab4[0+j+N/(4*4)*i] =(i-4*flag)*(16*0+4*j);
tab4[N/(16*4)+j+N/(4*4)*i] =(i-4*flag)*(1*16+4*j);
tab4[N/(8*4)+j+N/(4*4)*i]=(i-4*flag)*(2*16+4*j);
tab4[3*N/(16*4)+j+N/(4*4)*i]=(i-4*flag)*(3*16+4*j);
tab5[0*N/(16*4)+N/(4*4)*i+j]=4*0*(N/(16*4)*(i-4*flag))+4*(i-4*flag)*j;
tab5[1*N/(16*4)+N/(4*4)*i+j]=4*1*(N/(16*4)*(i-4*flag))+4*(i-4*flag)*j;
tab5[2*N/(16*4)+N/(4*4)*i+j]=4*2*(N/(16*4)*(i-4*flag))+4*(i-4*flag)*j;
tab5[3*N/(16*4)+N/(4*4)*i+j]=4*3*(N/(16*4)*(i-4*flag))+4*(i-4*flag)*j;
tab5[0*N/(4*4*4)+N/(4*4)*i+j]=(4*0*(N/(4*4*4)*i)+4*i*j)-0*N/(4)*flag-1*N/(4*4)*j*flag;
tab5[1*N/(4*4*4)+N/(4*4)*i+j]=(4*1*(N/(4*4*4)*i)+4*i*j)-1*N/(4)*flag-1*N/(4*4)*j*flag;
tab5[2*N/(4*4*4)+N/(4*4)*i+j]=(4*2*(N/(4*4*4)*i)+4*i*j)-2*N/(4)*flag-1*N/(4*4)*j*flag;
tab5[3*N/(4*4*4)+N/(4*4)*i+j]=(4*3*(N/(4*4*4)*i)+4*i*j)-3*N/(4)*flag-1*N/(4*4)*j*flag;
tab5[0*N/(4*4*4)+N/(4*4)*i+j]=(4*0*(N/(4*4*4)*(i-4*flag))+4*N/(4*4)*j*(i-4*flag))-1*4*15*(i-4*flag)*j;
tab5[1*N/(4*4*4)+N/(4*4)*i+j]=(4*1*(N/(4*4*4)*(i-4*flag))+4*N/(4*4)*j*(i-4*flag))-1*4*15*(i-4*flag)*j;
tab5[2*N/(4*4*4)+N/(4*4)*i+j]=(4*2*(N/(4*4*4)*(i-4*flag))+4*N/(4*4)*j*(i-4*flag))-1*4*15*(i-4*flag)*j;
tab5[3*N/(4*4*4)+N/(4*4)*i+j]=(4*3*(N/(4*4*4)*(i-4*flag))+4*N/(4*4)*j*(i-4*flag))-1*4*15*(i-4*flag)*j;
tab5[0*N/(4*4*4)+N/(4*4)*i+j]=4*0*(i-4*flag)*(j+4*0)+4*(i-4*flag)*j;
tab5[1*N/(4*4*4)+N/(4*4)*i+j]=4*1*(i-4*flag)*(j+4*1);
tab5[2*N/(4*4*4)+N/(4*4)*i+j]=4*2*(i-4*flag)*(j+4*1)-4*(i-4*flag)*j;
tab5[3*N/(4*4*4)+N/(4*4)*i+j]=4*3*(i-4*flag)*(j+4*1)-4*2*(i-4*flag)*j;
*/
}
if((i+1)%4==0){flag++;}
}
/*
for(int m=0;m<4;m++)//stage 3
{
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
tab5[0*N/(4*4*4)+N/(4*4)*i+N/(4)*m+j]=4*0*i*(j+4*0)+4*1*i*j;
tab5[1*N/(4*4*4)+N/(4*4)*i+N/(4)*m+j]=4*1*i*(j+4*1)+4*0*i*j;
tab5[2*N/(4*4*4)+N/(4*4)*i+N/(4)*m+j]=4*2*i*(j+4*1)-4*1*i*j;
tab5[3*N/(4*4*4)+N/(4*4)*i+N/(4)*m+j]=4*3*i*(j+4*1)-4*2*i*j;
}
}
}
for(int i2=0;i2<256;i2++)
{
cout<<i2<<" "<<tab4[i2]<<"="<<tab5[i2];
if(tab4[i2]==tab5[i2])cout<<" OK ";
cout<<endl;
if((i2+1)%16==0){
system("pause");
}
}
*/
///////////////////////////
flag=0;
//stage 4
for(int k=0;k<N;k++)
{
tab[k]={0,0};
}
tmp5=2*pi/(N/1);
for(int i=0;i<(N/16);i++)//16
{
for(int j=0;j<4;j++)
{
w1[0].real()=cos(0*16*j*tmp5);
w1[0].imag()=-sin(0*16*j*tmp5);
w2[0].real()=cos(1*16*j*tmp5);
w2[0].imag()=-sin(1*16*j*tmp5);
w3[0].real()=cos(2*16*j*tmp5);
w3[0].imag()=-sin(2*16*j*tmp5);
w4[0].real()=cos(3*16*j*tmp5);
w4[0].imag()=-sin(3*16*j*tmp5);
tmp1=w1[0]*tab2[N/(4*4)*i+0+4*j];
tmp2=w2[0]*tab2[N/(4*4)*i+1+4*j];
tmp3=w3[0]*tab2[N/(4*4)*i+2+4*j];
tmp4=w4[0]*tab2[N/(4*4)*i+3+4*j];
tab[N/(4*4)*i+0+4*j]=tmp1+tmp2+ tmp3+tmp4;
w5[0].real()=0;
w5[0].imag()=-1;
tab[N/(4*4)*i+1+4*j]=tmp1-tmp3+w5[0]*(tmp2-tmp4);
tab[N/(4*4)*i+2+4*j]=tmp1-tmp2+ tmp3-tmp4;
w5[0].real()=0;
w5[0].imag()=1;
tab[N/(4*4)*i+3+4*j]=tmp1-tmp3+w5[0]*(tmp2-tmp4);
tab4[N/(4*4)*i+0+4*j] =0*16*j;
tab4[N/(4*4)*i+1+4*j] =1*16*j;
tab4[N/(4*4)*i+2+4*j]=2*16*j;
tab4[N/(4*4)*i+3+4*j]=3*16*j;
//tab5[N/(4*4)*i+0+4*j]=16*0*(i-4*flag+j)-0*16*flag2;
//tab5[N/(4*4)*i+1+4*j]=16*1*(i-4*flag+j)-1*16*flag2;
//tab5[N/(4*4)*i+2+4*j]=16*2*(i-4*flag+j)-2*16*flag2;
//tab5[N/(4*4)*i+3+4*j]=16*3*(i-4*flag+j)-3*16*flag2;
//tab99[N/(4*4)*i+0+4*j]=4*0*(N/(4*4)*(i-4*flag)+0+4*(j-4*flag2));
//tab99[N/(4*4)*i+1+4*j]=4*1*(N/(4*4)*(i-4*flag)+0+4*(j-4*flag2));
//tab99[N/(4*4)*i+2+4*j]=4*2*(N/(4*4)*(i-4*flag)+0+4*(j-4*flag2));
//tab99[N/(4*4)*i+3+4*j]=4*3*(N/(4*4)*(i-4*flag)+0+4*(j-4*flag2));
}
if((i+1)%4==0){flag++;}
flag2++;
if((i+1)%4==0){flag2=0;}
}
/////////////////////////
//stage 4 bis
/*
flag=0;
flag3=0;
for(int i=0;i<(N/16);i++)//64
{
for(int j=0;j<1;j++)
{
tab5[0*N/(4*4*4*4)+N/(4*4*4)*i+j]=16*0*(N/(4*4*4*4)*(i-4*flag))+16*(i-4*flag)*j;
tab5[1*N/(4*4*4*4)+N/(4*4*4)*i+j]=16*1*(N/(4*4*4*4)*(i-4*flag))+16*(i-4*flag)*j;
tab5[2*N/(4*4*4*4)+N/(4*4*4)*i+j]=16*2*(N/(4*4*4*4)*(i-4*flag))+16*(i-4*flag)*j;
tab5[3*N/(4*4*4*4)+N/(4*4*4)*i+j]=16*3*(N/(4*4*4*4)*(i-4*flag))+16*(i-4*flag)*j;
tab5[0*N/(4*4*4*4)+N/(4*4*4)*i+j]=(16*0*(N/(4*4*4*4)*(i-4*flag))+16*N/(4*4*4)*j*(i-4*flag))-1*16*15*(i-4*flag)*j;
tab5[1*N/(4*4*4*4)+N/(4*4*4)*i+j]=(16*1*(N/(4*4*4*4)*(i-4*flag))+16*N/(4*4*4)*j*(i-4*flag))-1*16*15*(i-4*flag)*j;
tab5[2*N/(4*4*4*4)+N/(4*4*4)*i+j]=(16*2*(N/(4*4*4*4)*(i-4*flag))+16*N/(4*4*4)*j*(i-4*flag))-1*16*15*(i-4*flag)*j;
tab5[3*N/(4*4*4*4)+N/(4*4*4)*i+j]=(16*3*(N/(4*4*4*4)*(i-4*flag))+16*N/(4*4*4)*j*(i-4*flag))-1*16*15*(i-4*flag)*j;
//tab5[0*N/(4*4*4*4)+N/(4*4*4)*i+j]=16*0*(i-4*flag3)*(j+16*0)+16*1*(i-4*flag3)*j;
//tab5[1*N/(4*4*4*4)+N/(4*4*4)*i+j]=16*1*(i-4*flag3)*(j+16*1);
//tab5[2*N/(4*4*4*4)+N/(4*4*4)*i+j]=16*2*(i-4*flag3)*(j+16*1)-16*1*(i-4*flag3)*j;
//tab5[3*N/(4*4*4*4)+N/(4*4*4)*i+j]=16*3*(i-4*flag3)*(j+16*1)-16*2*(i-4*flag3)*j;
//cout<<0*N/(4*4*4*4)+N/(4*4*4)*i+j<<endl;
//system("pause");
}
if((i+1)%4==0){flag++;}
}
*/
/*
for(int m=0;m<16;m++)//stage 4
{
for(int i=0;i<4;i++)
{
for(int j=0;j<1;j++)
{
tab5[0*N/(4*4*4*4)+N/(4*4*4)*i+N/(4*4)*m+j]=16*0*i*(j+1*0)+16*1*i*j;
tab5[1*N/(4*4*4*4)+N/(4*4*4)*i+N/(4*4)*m+j]=16*1*i*(j+1*1)+16*0*i*j;
tab5[2*N/(4*4*4*4)+N/(4*4*4)*i+N/(4*4)*m+j]=16*2*i*(j+1*1)-16*1*i*j;
tab5[3*N/(4*4*4*4)+N/(4*4*4)*i+N/(4*4)*m+j]=16*3*i*(j+1*1)-16*2*i*j;
}
}
}
for(int i2=0;i2<256;i2++)
{
cout<<tab4[i2]<<"="<<tab5[i2];
if(tab4[i2]==tab5[i2])cout<<" O1K ";
cout<<endl;
if((i2+1)%16==0){
system("pause");
}
}
*/
for(int j=0;j<N;j++)
{
tab[j].real() =tab[j].real()*2/N;
tab[j].imag() =tab[j].imag()*2/N;
}
}
Subskrybuj:
Komentarze do posta (Atom)
Brak komentarzy:
Prześlij komentarz