<< Chapter < Page Chapter >> Page >

This Appendix contains source code listings corresponding to the FFT implementations with precomputed coefficients in Implementation details .

#include <math.h>#include <complex.h>#include <stdio.h>#include <stdlib.h>  typedef complex float data_t;  #define W(N,k) (cexp(-2.0f * M_PI * I * (float)k / (float)N))  data_t *LUT;  void ditfft2(data_t *in, data_t *out, int log2stride, int stride, int N) {if(N == 2) { out[0]   = in[0] + in[stride]; out[N/2] = in[0] - in[stride]; }else{ditfft2(in, out, log2stride+1, stride << 1, N >> 1); ditfft2(in+stride, out+N/2, log2stride+1, stride << 1, N >> 1);{  /* k=0 -> no multiplication */ data_t Ek = out[0]; data_t Ok = out[N/2]; out[0]   = Ek + Ok; out[N/2] = Ek - Ok; }  int k;for(k=1;k<N/2;k++) { data_t Ek = out[k]; data_t Ok = out[(k+N/2)]; data_t w = LUT[k<<log2stride];out[k]        = Ek + w * Ok;out[(k+N/2) ] = Ek - w * Ok;} }}  void fft_init(int N) { LUT = malloc(N/2 * sizeof(data_t));int i; for(i=0;i<N/2;i++) LUT[i] = W(N,i);}
Simple radix-2 FFT with precomputed LUT
#include <complex.h>#include <stdio.h>#include <stdlib.h>  typedef complex float data_t;  #define W(N,k) (cexp(-2.0f * M_PI * I * (float)k / (float)N))data_t *LUT1; data_t *LUT3;  void splitfft(data_t *in, data_t *out, int log2stride, int stride, int N) {if(N == 1) { out[0] = in[0];}else if(N == 2) { out[0]   = in[0] + in[stride]; out[N/2] = in[0] - in[stride]; }else{splitfft(in, out, log2stride+1, stride << 1, N >> 1); splitfft(in+stride, out+N/2, log2stride+2, stride << 2, N >> 2);   splitfft(in+3*stride, out+3*N/4, log2stride+2, stride << 2, N >> 2);{ data_t Uk  = out[0]; data_t Zk  = out[0+N/2]; data_t Uk2 = out[0+N/4]; data_t Zdk = out[0+3*N/4]; out[0]       = Uk  + (Zk + Zdk); out[0+N/2]   = Uk  - (Zk + Zdk); out[0+N/4]   = Uk2 - I*(Zk - Zdk); out[0+3*N/4] = Uk2 + I*(Zk - Zdk); }int k; for(k=1;k<N/4;k++) { data_t Uk  = out[k]; data_t Zk  = out[k+N/2]; data_t Uk2 = out[k+N/4]; data_t Zdk = out[k+3*N/4]; data_t w1 = LUT1[k<<log2stride];data_t w3 = LUT3[k<<log2stride];out[k]       = Uk  + (w1*Zk + w3*Zdk);out[k+N/2]   = Uk  - (w1*Zk + w3*Zdk);out[k+N/4]   = Uk2 - I*(w1*Zk - w3*Zdk);out[k+3*N/4] = Uk2 + I*(w1*Zk - w3*Zdk);} }}  void fft_init(int N) { LUT1 = malloc(N/4 * sizeof(data_t));LUT3 = malloc(N/4 * sizeof(data_t)); int i;for(i=0;i<N/4;i++) LUT1[i] = W(N,i);for(i=0;i<N/4;i++) LUT3[i] = W(N,3*i);}
Simple split-radix FFT with precomputed LUT
#include <math.h>#include <complex.h>#include <stdio.h>#include <stdlib.h>  typedef complex float data_t;  #define W(N,k) (cexp(-2.0f * M_PI * I * (float)k / (float)N))data_t *LUT;  void conjfft(data_t *base, int TN, data_t *in, data_t *out, int log2stride, int stride, int N) {if(N == 1) { if(in < base) in += TN; out[0] = in[0];}else if(N == 2) { data_t *i0 = in, *i1 = in + stride;if(i0 < base) i0 += TN; if(i1 < base) i1 += TN; out[0]   = *i0 + *i1; out[N/2] = *i0 - *i1; }else{conjfft(base, TN, in, out, log2stride+1, stride << 1, N >> 1); conjfft(base, TN, in+stride, out+N/2, log2stride+2, stride << 2, N >> 2);   conjfft(base, TN, in-stride, out+3*N/4, log2stride+2, stride << 2, N >> 2);{ data_t Uk  = out[0]; data_t Zk  = out[0+N/2]; data_t Uk2 = out[0+N/4]; data_t Zdk = out[0+3*N/4]; out[0]       = Uk  + (Zk + Zdk); out[0+N/2]   = Uk  - (Zk + Zdk); out[0+N/4]   = Uk2 - I*(Zk - Zdk); out[0+3*N/4] = Uk2 + I*(Zk - Zdk); }int k; for(k=1;k<N/4;k++) { data_t Uk  = out[k]; data_t Zk  = out[k+N/2]; data_t Uk2 = out[k+N/4]; data_t Zdk = out[k+3*N/4]; data_t w = LUT[k<<log2stride];out[k]       = Uk  + (w*Zk + conj(w)*Zdk);out[k+N/2]   = Uk  - (w*Zk + conj(w)*Zdk);out[k+N/4]   = Uk2 - I*(w*Zk - conj(w)*Zdk);out[k+3*N/4] = Uk2 + I*(w*Zk - conj(w)*Zdk);} }}void fft_init(int N) { LUT = malloc(N/4 * sizeof(data_t));int i; for(i=0;i<N/4;i++) LUT[i] = W(N,i);}
Simple conjugate-pair FFT with precomputed LUT
#include <math.h>#include <complex.h>#include <stdio.h>#include <stdlib.h>  typedef complex float data_t;  #define W(N,k) (cexp(-2.0f * M_PI * I * (float)(k) / (float)(N)))  floats(int n, int k) {   if (n <= 4) return 1.0f;    int k4 = k % (n/4);    if (k4 <= n/8) return (s(n/4,k4) * cosf(2.0f * M_PI * (float)k4 / (float)n));  return (s(n/4,k4) * sinf(2.0f * M_PI * (float)k4 / (float)n)); }  data_t *LUT, *LUT0, *LUT1, *LUT2;float *s2, *s4;  void tangentfft8(data_t *base, int TN, data_t *in, data_t *out, int log2stride,  int stride, int N) {  if(N == 1) { if(in < base) in += TN; out[0] = in[0];  }else if(N == 2) { data_t *i0 = in, *i1 = in + stride;if(i0 < base) i0 += TN; if(i1 < base) i1 += TN; out[0]   = *i0 + *i1; out[N/2] = *i0 - *i1;   }else if(N == 4) {    tangentfft8(base, TN, in, out, log2stride+1, stride << 1, N >> 1);     tangentfft8(base, TN, in+stride, out+2, log2stride+1, stride << 1, N >> 1);      data_t temp1 = out[0] + out[2];     data_t temp2 = out[0] - out[2];    out[0] = temp1;    out[2] = temp2;    temp1 = out[1] - I*out[3];     temp2 = out[1] + I*out[3];    out[1] = temp1;    out[3] = temp2;    }else{    tangentfft8(base, TN, in, out, log2stride+2, stride << 2, N >> 2);     tangentfft8(base, TN, in+(stride*2), out+2*N/8, log2stride+3, stride << 3, N >> 3);     tangentfft8(base, TN, in-(stride*2), out+3*N/8, log2stride+3, stride << 3, N >> 3);     tangentfft8(base, TN, in+(stride), out+4*N/8, log2stride+2, stride << 2, N >> 2);     tangentfft8(base, TN, in-(stride), out+6*N/8, log2stride+2, stride << 2, N >> 2); int k;    for(k=0;k<N/8;k++) { data_t w0 = LUT0[k<<log2stride];data_t w1 = LUT1[k<<log2stride];data_t w2 = LUT2[k<<log2stride];        data_t zk_p   = w0       * out[k+4*N/8];       data_t zk_n   = conj(w0) * out[k+6*N/8];       data_t zk2_p  = w1       * out[k+5*N/8];       data_t zk2_n  = conj(w1) * out[k+7*N/8];       data_t uk     = out[k]                  * s4[k<<log2stride];      data_t uk2    = out[k+N/8]              * s4[k+N/8 << log2stride];      data_t yk_p   = w2       * out[k+2*N/8];      data_t yk_n   = conj(w2) * out[k+3*N/8];data_t y0 = (yk_p + yk_n)*s2[k<<log2stride];data_t y1 = (yk_p - yk_n)*I*s2[k+N/8 << log2stride];        out[k]       = uk + y0 + (zk_p + zk_n);       out[k+4*N/8] = uk + y0 - (zk_p + zk_n);       out[k+2*N/8] = uk - y0 - I*(zk_p - zk_n);       out[k+6*N/8] = uk - y0 + I*(zk_p - zk_n);       out[k+1*N/8] = uk2 - y1 +   (zk2_p + zk2_n);       out[k+3*N/8] = uk2 + y1 - I*(zk2_p - zk2_n);       out[k+5*N/8] = uk2 - y1 -   (zk2_p + zk2_n);       out[k+7*N/8] = uk2 + y1 + I*(zk2_p - zk2_n);     }  }  }  void tangentfft4(data_t *base, int TN, data_t *in, data_t *out, int log2stride, int stride, int N) {if(N == 1) { if(in < base) in += TN; out[0] = in[0];}else if(N == 2) { data_t *i0 = in, *i1 = in + stride;if(i0 < base) i0 += TN; if(i1 < base) i1 += TN; out[0]   = *i0 + *i1; out[N/2] = *i0 - *i1; }else{tangentfft4(base, TN, in, out, log2stride+1, stride << 1, N >> 1); tangentfft8(base, TN, in+stride, out+N/2, log2stride+2, stride << 2, N >> 2);   tangentfft8(base, TN, in-stride, out+3*N/4, log2stride+2, stride << 2, N >> 2);{ data_t Uk  = out[0]; data_t Zk  = out[0+N/2]; data_t Uk2 = out[0+N/4]; data_t Zdk = out[0+3*N/4]; out[0]       = Uk  + (Zk + Zdk); out[0+N/2]   = Uk  - (Zk + Zdk); out[0+N/4]   = Uk2 - I*(Zk - Zdk); out[0+3*N/4] = Uk2 + I*(Zk - Zdk); }int k; for(k=1;k<N/4;k++) { data_t Uk  = out[k]; data_t Zk  = out[k+N/2]; data_t Uk2 = out[k+N/4]; data_t Zdk = out[k+3*N/4]; data_t w = LUT[k<<log2stride];out[k]       = Uk  + (w*Zk + conj(w)*Zdk);out[k+N/2]   = Uk  - (w*Zk + conj(w)*Zdk);out[k+N/4]   = Uk2 - I*(w*Zk - conj(w)*Zdk);out[k+3*N/4] = Uk2 + I*(w*Zk - conj(w)*Zdk);} }}  void fft_init(int N) { LUT0 = malloc(N/8 * sizeof(data_t));LUT1 = malloc(N/8 * sizeof(data_t)); LUT2 = malloc(N/8 * sizeof(data_t));  LUT = malloc(N/4 * sizeof(data_t));  s2 = malloc(N/4 * sizeof(float)); s4 = malloc(N/4 * sizeof(float));  int i;for(i=0;i<N/8;i++) LUT0[i] = W(N,i)*s(N/4,i)/s(N,i);for(i=0;i<N/8;i++) LUT1[i] = W(N,i+N/8)*s(N/4,i+N/8)/s(N,i+N/8);for(i=0;i<N/8;i++) LUT2[i] = W(N,2*i)*s(N/8,i)/s(N/2,i);for(i=0;i<N/4;i++) LUT[i] = W(N,i)*s(N/4,i);for(i=0;i<N/4;i++) s4[i] = s(N/4,i)/s(N,i);for(i=0;i<N/4;i++) s2[i] = s(N/2,i)/s(N,i);}
Simple tangent FFT with precomputed LUT

Questions & Answers

Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Computing the fast fourier transform on simd microprocessors. OpenStax CNX. Jul 15, 2012 Download for free at http://cnx.org/content/col11438/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Computing the fast fourier transform on simd microprocessors' conversation and receive update notifications?

Ask