473,395 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

optimize this Shifting code ?

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;
}
Jun 27 '08 #1
3 1160
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
// *********************************

As you said, the shifting with the delimiter in the middle is the one
you need.
That means you only need to do is to swap them.
Ex: the original Cycle: 012 345 .
Now swap(0,3),(1,4), (2,5), result is Cycle: 345 012
Jun 27 '08 #2
Matthias Pospiech wrote:
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.
You might consider using swap N/2 times, in place, instead of
allocating another array and doing so many loops:

for (int i = 0, half = N/2; i < half; ++i)
swap(A[i], A[i + half]);

Now, you didn't say what should happen if the array has an odd
number of elements, so please adjust the loop accordingly.
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #3
In article <fv**********@newsserver.rrzn.uni-hannover.de>, matthias79
@gmx.de says...
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);
}
If I understand your requirements correctly, std::swap_ranges should do
the job quite easily:

void QFFTW::Cycle(complex<double*A1, long N) {
complex<double*mid = A1+N/2;
std::swap_ranges(A1, mid, mid);
}

Since you're doing an FFT, I'd guess you don't care about the
possibility of N being odd.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: David Stockwell | last post by:
Hi, My background is c/c++ and java. I'm learning python at this point. My question is does python share java's peculiar mode of bit shifting, or does python adhere closer to c's bit shifting?...
9
by: GGG | last post by:
Noticed something odd in the way bit shifting was working today. As far as I have ever heard, shifting will shift in zeros(signed ints aside) However I foudn something odd when I am shifting...
0
by: Daniel | last post by:
Hi there, I recently came across an interesting option when right clicking on a project (Right click on the project -> properties -> Configuration Properties ->Build -> Optimize) There is an...
2
by: salsipius | last post by:
Can someone please help me clarify the below code. I think the shifting has to do with converting datatypes and/or loss of data but am not really clear on the details, could you help shed some...
18
by: richard_l | last post by:
Hello All, I am writing an application which receives a word which is a bitmap. I have created a word typedef which contains a bitfield defining each bit. however, I was wondering however if it...
10
by: krunalb | last post by:
Hi, I am trying to shift unsigned long long value by 64 bits and this is what i get #include <stdio.h> int main() { unsigned short shiftby= 64;
20
by: Charles Sullivan | last post by:
I understand different processor hardware may store the bits in a byte in different order. Does it make a difference in C insofar as bit-shifting unsigned char variables is concerned? E.g, if I...
4
by: Neil | last post by:
I previously posted about data shifting between records in my Access 2000 MDB with a SQL Server 7 back end, using ODBC linked tables. Every once in a while, data from one record mysteriously...
12
by: Boltar | last post by:
I seem to be having yet more wierd issue with bit shifting. It seems the following code doesnt do anything under gcc (ie it returns -1 as both results). Anyone know why? Is it another language...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.