473,769 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Diggins PDP #4 : FFT (Fast Fourier Transform)

// The Diggins PDP (Public Domain Post) #4
// public domain code for computing the FFT
// contributed by Christopher Diggins, 2005

template<int N>
unsigned int bit_reverse(uns igned int x) {
int n = 0;
int mask = 0x1;
for (int i=0; i < N; i++) {
n <<= 1;
n |= (x & 1);
x >>= 1;
}
return n;
}

const double pi = 3.1415926535897 ;

template<int Log2_N, class Iter_T>
void fft(Iter_T a, Iter_T A)
{
typedef std::iterator_t raits<Iter_T>:: value_type complex;
const int N = 1 << Log2_N;
for (unsigned int i=0; i<N; ++i) {
A[bit_reverse<Log 2_N>(i)] = a[i];
}
for (int s = 1; s <= Log2_N; ++s) {
int m = 1 << s;
complex w(1, 0);
complex wm(cos(2 * pi / m), sin(2 * pi / m));
for (int j=0; j < m/2; ++j) {
for (int k=j; k < N; k += m) {
complex t = w * A[k + m/2];
complex u = A[k];
A[k] = u + t;
A[k + m/2] = u - t;
}
w *= wm;
}
}
}

--
Christopher Diggins
http://www.cdiggins.com
Jul 23 '05 #1
0 1982

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

Similar topics

2
2844
by: Matthew | last post by:
Hello, For a few days now, I have tried a number of methods that are supposed to provide the a(k) and b(k) coefficients for a Fourier series. These methods are listed at the end of this post (in Java). However, not one of these methods seems to provide the correct coefficients for the following function; f(x) = 2 - 2 * cos(x)
3
7895
by: Johannes Ahl-mann | last post by:
hi, i've been looking all around the net (google is my friend ;-) for a module to apply fourier transformations on images. the different ones in numerical python and scientific python seem all to be operating on sequences and therefore seem to be 1D fourier transform. anyone know a library/module to do 2D image FFT in a simple manner. or am i just too dumb to see how this is supposed to work with the 1D
4
3662
by: SC | last post by:
I couldn't write a program that make fourier transform in one and two dimens in C++. I couldn't solve correctly determinant of 3*3 matrix ic C++ too. Can you help me about that?? Thanks!
4
2739
by: christopher diggins | last post by:
Welcome to the first installment of the Diggins Public Domain Posts (PDP). There is a significant dearth of good public domain C++ code. All of it seems to come with one kind of a license or another, and even though I understand the motivations, I believe code is like mathematics and no one can really own it. Rather than stand on a pulpit, or debate the philosophical merits of the various licenses, I have decided instead to post as much...
1
1384
by: christopher diggins | last post by:
// meta_binder.hpp // The Diggins PDP (Public Domain Post) #2 // Public Domain code by Christopher Diggins, May 22, 2005 // // Description: // A meta-binder binds function objects to function objects // // Motivation: // lack of a logical_xor in the standard library, and no way to construct one using the
0
1082
by: christopher diggins | last post by:
// big_int.hpp // The Diggins PDP (Public Domain Post) #3 // Public Domain code by Christopher Diggins, May 22, 2005 // // Description: // A naively implemented unsigned integer type for arbitrarily large // values. Implemented using vector<bool> #ifndef BIG_INT_HPP #define BIG_INT_HPP
4
6738
by: Charles | last post by:
I am doing a Digital signal processing project using VB.net and need advance maths function and also signal processing function such as fast fourier transform. Can anyone advice me on how do I get a FFT function? Thanks for any reply.
2
10294
by: IdlePhaedrus | last post by:
Hi, I have a FFT routine that I converted from C++ to VB in a module as follows: Const M_PI = 3.1415926535897931 ' Fast Fourier Transform Public Sub FFT(ByRef rex() As Single, ByRef imx() As Single, ByVal N As UShort) Dim nm1 As UShort = CUShort(N - 1)
0
1530
by: pmclinn | last post by:
I'm looking for the complex discrete fourier Transform of this EQ impulse response array. I know the output for the first 3 values: EQ.DFT MAG(floating)) should be 1.066769, 1.040460, 1.063209.... EQ. DFT MAG(Db) .561411,.344507,.532374.... CH Resp mag(dB) -.608192, .845447,2.019220.... I can for the life me not get this to balance against the returns below. Any help would be greatly appreciated? Dim real(23) As Double
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10050
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.