fast fourier transform in java


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: fast fourier transform in java

  1. #1
    Join Date
    May 2008
    Posts
    2

    fast fourier transform in java

    Hi!everybody. I'm unable to get correct fourier image of even a simple sinusoid with the following code. 'll appreciate help. Thankx.
    Code:
    void freq_spect(){
    
                           double F[][][];
                           double FX[][];
                           double f_r[];
                           double f_r1[];
                           double NNN[][];
                           double Four[][];
                           int fxy[][];
                           int wd=new_img.getWidth();
                           int ht=new_img.getHeight();
                           F=new double[wd][ht][2];
                           Four=new double[wd][ht];
                           FX=new double[wd][2];
                           f_r=new double[wd*ht];
                           f_r1=new double[wd*ht];
                           NNN=new double[wd][ht];                   img_fourier=newBufferedImage(new_img.getWidth(),new_img.getHeight(),BufferedImage.TYPE_BYTE_GRAY);
                       rstr_f=img_fourier.getRaster(); //writable raster
    
              for (int u=0;u<new_img.getWidth();u++)
                {
                    for (int v=0;v<new_img.getHeight();v++)
                    {    
                    NNN[u][v]=rstr.getSample(u,v,0); //rstr is the writable raster of the image. 
                    NNN[u][v]=NNN[u][v]* Math.pow(-1,(u+v));
                    F[u][v][0]=0;
                    F[u][v][1]=0;
                                 }
                }
      int vv=0;
              for (int u=0;u<new_img.getWidth();u++)
                {
    
                      FX[u][0]=0; //real array 
                      FX[u][1]=0;  //imaginary array
    
                 for (int a=0; a<new_img.getWidth();a++)
                    { 
                       for(int b=0;b<new_img.getHeight();b++)
                        {  
           FX[u][0]=FX[u][0]+(NNN[a][b])* Math.cos(Math.PI/180*( (6.28318*((u*a)/wd)));
           FX[u][1] =FX[u][1]-((NNN[a][b])* Math.sin(Math.PI/180*( (6.28318*((u*a)/wd))));
                           }
                     }
                                       }
                  
     vv=0;
    
                     for (int u=0;u<new_img.getWidth();u++)
                        {
                       for(int v=0;v<new_img.getHeight();v++)
                        {
                            for(int b=0;b<new_img.getHeight();b++)
                            {  
    
      F[u][v][0]=F[u][v][0]+(FX[u][0])* Math.cos(Math.PI/180*(6.28318*((v*b)/ht)))+(FX[u][1])* Math.sin(Math.PI/180*(6.28318*((v*b)/ht)));
      F[u][v][1] =F[u][v][1]+(FX[u][1])* Math.cos(Math.PI/180*(6.28318*((v*b)/ht)))-((FX[u][0])* Math.sin(Math.PI/180*(6.28318*((v*b)/ht))));
                               }
                        
                       double sum11=F[u][v][0]*F[u][v][0];
                       double sum22=F[u][v][1]*F[u][v][1];
                       Four[u][v]=(sum11+sum22);
                       f_r[vv]=Four[u][v];
                       f_r[vv]=Math.sqrt(f_r[vv]); //power spectrum
                      vv++;
                     }
                   }   
                    for (int a=0; a<new_img.getWidth();a++)
                       for(int b=0;b<new_img.getHeight();b++)
                         {
                          rstr_f.setSample(a,b,0,Four[a][b]);
                          }
    
                         repaint();
                         
    
                       }
    Last edited by Hack; 05-29-2008 at 08:18 AM. Reason: Added Code Tags

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Welcome to DevX
    Quote Originally Posted by smmustakim
    I'm unable to get correct fourier image
    What is "incorrect" about the image that you do get?

    (BTW: I added [code]your code goes here[/code] tags to your post to make reading your code a bit easier. )
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    May 2008
    Posts
    2
    Using my code, I'm getting the fourier tansforms of all valueas as zeoes. I used the image of a simple sinusoidal(foursmall.jpeg -attached). The fourier image I obtained is attached as Fourier.jpeg.The correct image that should be, is also attached as fourier_actual.jpg. Thanks.
    Attached Images Attached Images

Similar Threads

  1. Java book
    By Lou in forum Java
    Replies: 9
    Last Post: 09-19-2007, 05:58 AM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  3. learning c# very confusing.
    By Mike Tsakiris in forum .NET
    Replies: 11
    Last Post: 10-04-2002, 05:32 PM
  4. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center