A bit-code inversion algorithm in fast Fourier transform

Source: Internet
Author: User

Recently has been looking at the Fourier transform, see FFT algorithm, in fact, one of the key algorithm, butterfly operations, as long as the understanding, coding implementation is not difficult. But it is one of the steps in reverse, it is easy to see, but the code implementation is not so easy. In the online reference to a lot of information, decided to share the following algorithm to everyone, here to thank Baidu Library user letsgotoyy123 "Fast Fourier transform FFT and its Application" article (http://wenku.baidu.com/view/ 7E9F6E6EA1C7AA00B42ACB84) also want to thank the stars classmate, in some basic knowledge of the guidance, thank you.

#include <iostream>
#include <cmath>
using namespace Std;
const int n=16;

int main ()
{
int src[n]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
cout<< "original array:" <<endl;
for (int i=0;i<n;i++)
{
cout<<src[i]<< "";
}
cout<<endl;
int k;
Int J;
int count=0;

I and J are the indexes of the array elements that need to be exchanged
I was added from the second element to the penultimate element
The key is to ask J
Swap when i<j to avoid duplication of exchange.
for (i=1,j=n/2;i<=n-2;i++)
{
if (I<J)
{
Exchange
int T=SRC[J];
Src[j]=src[i];
src[i]=t;
}
K=N/2;
cout<< "i=" <<i<< ", j=" <<j<< ", k=" <<k<<endl;

Ask for the next J
while (K<=J)
{
J=j-k;
K=K/2;
}
This is the next J.
J=j+k;


Output the array after each swap
cout<< "<<++count<<" after the second transformation of the array: "<<endl;
for (int m=0;m<n;m++)
{
cout<<src[m]<< "";
}
cout<<endl;
}
cout<< "bit code after the reverse array is:" <<endl;
for (int n=0;n<n;n++)
{
cout<<src[n]<< "";
}
cout<<endl;
return 0;

}

/*****

The key in the code is to calculate the value of the next J, which can be easily understood. K=N/2 is the center point, J is the offset, when k<=j, to re-compute the point K and the value of the offset J, is J-K;K=K/2, know that the k<=j is not satisfied. Then, adding the new center point K and the offset J together is the next J. As for why this is the index to exchange, I really do not understand, but also hope that the great God to explain. *********/

A bit-code inversion algorithm in fast Fourier transform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.