Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > optimize this S...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 45809 of 45898
Post > Topic >>

optimize this Shifting code ?

by Matthias Pospiech <matthias79@[EMAIL PROTECTED] > May 8, 2008 at 02:23 PM

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[i];
		for (i=N-1;i>=del;i--) A1[i]=A1[i-del];
		for (i=0;i<del;i++)	A1[i]=D[i];
	}
	else if(del<0	&&	del > -N)
	{
		del=-del;
		for (i=0;i<del;i++)	D[i]=A1[i];
		for (i=0;i<N-del;i++) A1[i]=A1[i+del];
		for (i=N-del;i<N;i++) A1[i]=D[i-N+del];
	}
	delete [] D;
}




 6 Posts in Topic:
optimize this Shifting code ?
Matthias Pospiech <mat  2008-05-08 14:23:56 
Re: optimize this Shifting code ?
lunar_lty <penglu96@[E  2008-05-08 05:56:56 
Re: optimize this Shifting code ?
"Victor Bazarov"  2008-05-08 20:53:03 
Re: optimize this Shifting code ?
Jerry Coffin <jcoffin@  2008-05-08 19:07:22 
Re: optimize this Shifting code ?
"Steven G. Johnson&q  2008-05-08 21:45:11 
Re: optimize this Shifting code ?
Jerry Coffin <jcoffin@  2008-05-09 07:54:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 2:33:56 CDT 2008.