M
Matthias Pospiech
In FFT one usually needs to shift/cycle the values in an array.
Typically the entries are shifted in the way:
012 345 to 345 012
The following code does this, but I wonder if there are possibilites to
optimize it? It is very generall, but the shifting with the delimiter in
the middle is the only one that I need.
// *********************************
// Cycle changes 012 345 to 345 012
// *********************************
void QFFTW::Cycle(complex<double> *A1,long N)
{
Cycle(A1,N,N/2);
}
void QFFTW::Cycle(complex<double> *A1,long N,long del)
{
long i;
complex<double> *D;
D=new complex<double>[N];
if (del>=N) del-=N;
if (del<=-N) del+=N;
if(del>0 && del<N)
{
for (i=N-del;i<N;i++) D[i-N+del]=A1;
for (i=N-1;i>=del;i--) A1=A1[i-del];
for (i=0;i<del;i++) A1=D;
}
else if(del<0 && del > -N)
{
del=-del;
for (i=0;i<del;i++) D=A1;
for (i=0;i<N-del;i++) A1=A1[i+del];
for (i=N-del;i<N;i++) A1=D[i-N+del];
}
delete [] D;
}
Typically the entries are shifted in the way:
012 345 to 345 012
The following code does this, but I wonder if there are possibilites to
optimize it? It is very generall, but the shifting with the delimiter in
the middle is the only one that I need.
// *********************************
// Cycle changes 012 345 to 345 012
// *********************************
void QFFTW::Cycle(complex<double> *A1,long N)
{
Cycle(A1,N,N/2);
}
void QFFTW::Cycle(complex<double> *A1,long N,long del)
{
long i;
complex<double> *D;
D=new complex<double>[N];
if (del>=N) del-=N;
if (del<=-N) del+=N;
if(del>0 && del<N)
{
for (i=N-del;i<N;i++) D[i-N+del]=A1;
for (i=N-1;i>=del;i--) A1=A1[i-del];
for (i=0;i<del;i++) A1=D;
}
else if(del<0 && del > -N)
{
del=-del;
for (i=0;i<del;i++) D=A1;
for (i=0;i<N-del;i++) A1=A1[i+del];
for (i=N-del;i<N;i++) A1=D[i-N+del];
}
delete [] D;
}