CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

FFT_PIC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kaos



Joined: 03 May 2007
Posts: 4
Location: Spain

View user's profile Send private message

FFT_PIC
PostPosted: Sun May 06, 2007 5:18 am     Reply with quote

I have programmed a function "FFT_PIC" and I want to share the code to know if is possible to improve it.

Code:

//-----------------------------------------------------------------------------------------------------//
#define BYTES   4
#define PUNTOS  1<<BYTES
//-----------------------------------------------------------------------------------------------------//
const unsigned int Orden[] = { 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 } ;
const float u1d[] = { -1.000000, 0.000000, -1.000000, 0.707107, 0.000000, -0.707107, -1.000000, 0.923880, 0.707107, 0.382683, 0.000000, -0.382683, -0.707107, -0.923880, -1.000000 } ;
const float u2d[] = { 0.000000, -1.000000, 0.000000, -0.707107, -1.000000, -0.707107, 0.000000, -0.382683, -0.707107, -0.923880, -1.000000, -0.923880, -0.707107, -0.382683, -0.000000 } ;
//-----------------------------------------------------------------------------------------------------//
void FFT_PIC(float *x,float *y)
{
    int l,l1,i,l2,i1,j,cont;
   float u1,u2,t1,t2,temp;
    l2 = 1;
   cont = 0;
    for(l=0;l<BYTES;l++)
        {
        l1 = l2;
        l2 <<= 1;
        u1 = 1.0;
        u2 = 0.0;
        for(j=0;j<l1;j++)
            {
            for(i=j;i<PUNTOS;i+=l2)
                {
                i1 = i + l1;
            temp = x[Orden[i1]];
                t1   = (u1 * temp);
            temp = y[ Orden[i1] ];
            temp = (u2 * temp);
            t1   = t1 - temp;
            temp = y[ Orden[i1] ];
                t2   = (u1 * temp);
            temp = x[ Orden[i1] ];
            temp = (u2 * temp);
                t2   = t2 + temp;
            temp = x[ Orden[i] ];
            temp = temp - t1;
                x[Orden[i1]] = temp;
            temp = y[ Orden[i] ];
            temp = temp - t2;
                y[Orden[i1]] = temp;
                x[Orden[i]] += t1;
                y[Orden[i]] += t2;
                }
            cont++;
            u1 = u1d[cont];
            u2 = u2d[cont];
            }
        }
    for(i=0;i<PUNTOS;i++)
        {
        x[i] /= PUNTOS;
        y[i] /= PUNTOS;
        }
}
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sun May 06, 2007 10:26 am     Reply with quote

The issue probably will always be with the use of floats. The PIC is very capable when you avoid floating point. Floating point is a snail and at the end of the day whether the snail has racing stripes or not it will still have a snail's pace. Before there were computing machines human calculation was very very slow. Many algorithms based on finite differences (Ex Breshenham) were employed to gain speed. Finite differences use add and subtract with an occasional divide by 2 or multiply by 2. They are used today for fast graphic processing. There is an advantage to having a snail race a shorter distance ( reducing the number of float operations) but on a PIC float will still be a snail absent floating point hardware.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group