C# code snippet below is an illustration of the Cooky-Turkey algorithm, the performance may suck when processing huge datasets, but you can use arrays of double instead of arrays of complex number structure to reduce the performance impact by object initializations and method invocations(overloaded operators).
Furthermore, you can use "Butterfly" computation(http://www.cmlab.csie.ntu.edu.tw/cml/dsp/training/coding/transform/fft.html) to gain a much better performance.

private Complex[] FFT(Complex[] input,bool invert)
{
    
if (input.Length == 1)
    {
        
return new Complex[] { input[0] };
    }
    
int length = input.Length;
    
int half = length / 2;
    Complex[] result 
= new Complex[length];
    
double fac = -2.0 * Math.PI / length;
    
if (invert)
    {
        fac 
= -fac;
    }

    Complex[] evens 
= new Complex[half];
    
for (int i = 0; i < half; i++)
    {
        evens[i] 
= input[2 * i];
    }
    Complex[] evenResult 
= FFT(evens,invert);

    Complex[] odds 
= evens;
    
for (int i = 0; i < half; i++)
    {
        odds[i] 
= input[2 * i + 1];
    }
    Complex[] oddResult 
= FFT(odds,invert);

    
for (int k = 0; k < half; k++)
    {
        
double fack = fac * k;
        Complex oddPart 
= oddResult[k] * new Complex(Math.Cos(fack), Math.Sin(fack));
        result[k] 
= evenResult[k] + oddPart;
        result[k 
+ half] = evenResult[k] - oddPart;
    }

    
return result;
}


Posted on 2007-08-10 15:30 Adrian H. 阅读(940) 评论(3)  编辑 收藏 所属分类: C#AlgorithmGraphics & Imaging

Feedback

#1楼    回复  引用    

2007-12-16 11:04 by zhoule [未注册用户]
hello
how do you do
I have some questions about fft algorithm ,can you give me
some guidance?Can you give an eMail?thank you
my qq is 99108558

#2楼    回复  引用    

2007-12-16 14:23 by AdrianHuang [未注册用户]
@zhoule
Hi, you can mail to me @ sanyuexx(at)hotmail.com

#3楼    回复  引用    

2007-12-17 10:38 by 周乐 [未注册用户]
@AdrianHuang
hello
I Have the note you left to me,and write a email to you ,if possible
can you leave me a qq number or your msn?I hope you can give
some guidance!thank you!my qq is 99108558!And msn is phoenix_2@live.cn!Waiting for your replay!

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      


相关链接: