Click here to Skip to main content
15,886,137 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
SuggestionRe: How to run the C++ app on cluster? Pin
David Crow5-Mar-19 7:10
David Crow5-Mar-19 7:10 
AnswerRe: How to run the C++ app on cluster? Pin
jung-kreidler7-Mar-19 3:54
jung-kreidler7-Mar-19 3:54 
GeneralRe: How to run the C++ app on cluster? Pin
oleg637-Mar-19 4:12
professionaloleg637-Mar-19 4:12 
QuestionUnderstanding makefile and dependency Pin
Member 141617705-Mar-19 6:28
Member 141617705-Mar-19 6:28 
QuestionRe: Understanding makefile and dependency Pin
David Crow5-Mar-19 6:59
David Crow5-Mar-19 6:59 
AnswerRe: Understanding makefile and dependency Pin
CPallini6-Mar-19 1:45
mveCPallini6-Mar-19 1:45 
AnswerRe: Understanding makefile and dependency Pin
Richard MacCutchan6-Mar-19 2:47
mveRichard MacCutchan6-Mar-19 2:47 
Question[C++] Fast Fourier Transform algorithm does not work properly Pin
Member 141687012-Mar-19 1:51
Member 141687012-Mar-19 1:51 
Hello, there is a pseudocode for recursive radix 2 DIT Fast Fourier Transform(page 11,12) at this link.

I have written a code in c++ which does the same, but it doesn't work properly.
For example when I take 1024 datapoints of sin(0.1*x) where x={0,1,...1023}, I get this.

Reverse transform inserted for this gives initial function multiplied by 1024, so it works.
What could be wrong? I tried with value dir and dir/2 inside "Shift" function too.

Here is the code:
Notation: E2-even part, E3-odd part
I work without complex numbers library, so there are both "_re" and "_im" tables.

C++
void FFT(double *tab_re, double *tab_im, double *results_re, double *results_im, int n, int dir)	//n-data size
{
if(n==1)
{results_re[0]=tab_re[0];	//real values
results_im[0]=tab_im[0];	//imaginary
return;}

int nh=n/2;

double *E2_re=new double [nh];
double *E3_re=new double [nh];
double *E2_im=new double [nh];
double *E3_im=new double [nh];

double *F2_re=new double [nh];
double *F3_re=new double [nh];
double *F2_im=new double [nh];
double *F3_im=new double [nh];

for(int k=0;k<nh;++k)	//even and odd parts
{E2_re[k]=tab_re[2*k];
E2_im[k]=tab_im[2*k];
E3_re[k]=tab_re[2*k+1];
E3_im[k]=tab_im[2*k+1];}

//recursion:
FFT(E2_re,E2_im,F2_re,F2_im,nh,dir);
FFT(E3_re,E3_im,F3_re,F3_im,nh,dir);

Shift(F3_re,F3_im,nh,dir);	//multiplying by phase

for(int k=0;k<nh;++k)
{
results_re[k]=F2_re[k]+F3_re[k];
results_im[k]=F2_im[k]+F3_im[k];
results_re[k+nh]=F2_re[k]-F3_re[k];
results_im[k+nh]=F2_im[k]-F3_im[k];}}




void Shift(double *tab_re, double *tab_im, int n, int v)
{double re,im;
double pi=3.14159265359;
double arg;

for(int i=0;i<n;++i)
{re=tab_re[i];
im=tab_im[i];

arg=v*2.0*pi*i/n;

tab_re[i]=re*cos(arg)-im*sin(arg);
tab_im[i]=re*sin(arg)+im*cos(arg);}}

AnswerRe: [C++] Fast Fourier Transform algorithm does not work properly Pin
Daniel Pfeffer2-Mar-19 22:08
professionalDaniel Pfeffer2-Mar-19 22:08 
GeneralRe: [C++] Fast Fourier Transform algorithm does not work properly Pin
Member 141687013-Mar-19 0:15
Member 141687013-Mar-19 0:15 
AnswerRe: [C++] Fast Fourier Transform algorithm does not work properly Pin
leon de boer4-Mar-19 4:55
leon de boer4-Mar-19 4:55 
GeneralRe: [C++] Fast Fourier Transform algorithm does not work properly Pin
Member 141687014-Mar-19 8:16
Member 141687014-Mar-19 8:16 
AnswerRe: [C++] Fast Fourier Transform algorithm does not work properly Pin
Member 1433176610-Oct-19 5:49
Member 1433176610-Oct-19 5:49 
QuestionMDI or SDI. How do I connect View with a resource formview. Pin
Member 118836021-Mar-19 1:44
Member 118836021-Mar-19 1:44 
AnswerRe: MDI or SDI. How do I connect View with a resource formview. Pin
Victor Nijegorodov1-Mar-19 2:30
Victor Nijegorodov1-Mar-19 2:30 
GeneralRe: MDI or SDI. How do I connect View with a resource formview. Pin
Member 118836021-Mar-19 4:05
Member 118836021-Mar-19 4:05 
GeneralRe: MDI or SDI. How do I connect View with a resource formview. Pin
Victor Nijegorodov1-Mar-19 20:45
Victor Nijegorodov1-Mar-19 20:45 
GeneralRe: MDI or SDI. How do I connect View with a resource formview. Pin
Member 118836021-Mar-19 21:59
Member 118836021-Mar-19 21:59 
GeneralRe: MDI or SDI. How do I connect View with a resource formview. Pin
Victor Nijegorodov1-Mar-19 22:34
Victor Nijegorodov1-Mar-19 22:34 
GeneralRe: MDI or SDI. How do I connect View with a resource formview. Pin
Member 118836022-Mar-19 2:03
Member 118836022-Mar-19 2:03 
QuestionHow to stop flickering of controls in my Dialog window Pin
manoharbalu28-Feb-19 0:43
manoharbalu28-Feb-19 0:43 
AnswerRe: How to stop flickering of controls in my Dialog window Pin
Victor Nijegorodov28-Feb-19 1:02
Victor Nijegorodov28-Feb-19 1:02 
GeneralRe: How to stop flickering of controls in my Dialog window Pin
manoharbalu28-Feb-19 1:56
manoharbalu28-Feb-19 1:56 
AnswerRe: How to stop flickering of controls in my Dialog window Pin
mo149228-Feb-19 3:01
mo149228-Feb-19 3:01 
GeneralRe: How to stop flickering of controls in my Dialog window Pin
manoharbalu1-Mar-19 1:09
manoharbalu1-Mar-19 1:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.