Another fourn1 problem


elaatsch
04-25-2003, 06:02 AM
Help !

I solved the problem of my earler thread myself. The code below calculates phase and amplitude of the rendered fft. The amplitude looks good, but the phase is totally currupted. What went wrong ??

Please help !


void CFftDlg::OnButton1()
{
CNiReal32Vector v1; //just a template class vector
int iSize=512;
v1.SetSize(iSize);

//make a sinus of 512 points
double dblInc=2*PI/(double)iSize;

//the array fourn understands
float *dblaFFT=new float[iSize*2+10];

for(int i=0;i<iSize;i++)
{
v1[i]=sin(dblInc*i);
//fill the array with real parts
dblaFFT[i*2+1]=v1[i];
//fill imag parts with zero
dblaFFT[i*2+2]=0;

}
m_cwgGraph1.GetPlots().Item(1).PlotY(v1); //just a display routine
//calc fourier transform
four1(dblaFFT,iSize,1);
//array starts at first element not at zero
dblaFFT++;
// dblaFFT[10*2+1]=400;


for( i=0;i<iSize;i++)
{
double real=dblaFFT[i*2];
double img=dblaFFT[i*2+1];

//calc amplitude and phase
double amp=sqrt(real*real+img*img);
double phase=atan(img/real);
//store amp on vector
v1[i]=amp;
}
//decrement pointer to get original adress
dblaFFT--;
//display amp
m_cwgGraph2.GetPlots().Item(1).PlotY(v1);

//do inverse transform and display
four1(dblaFFT,iSize,-1);
for( i=0;i<iSize;i++)
{
double real=dblaFFT[i*2+1];
double img=dblaFFT[i*2+2];


v1[i]=real;

}

m_cwgGraph3.GetPlots().Item(1).PlotY(v1);

TMcCloskey
05-25-2003, 03:13 PM
elaatsch -- did you ever resolve your problem? I know this may be late, but in some recent work with four1, some others notice a phase error. A quick fix seems to point to the value of 2*pi that is coded line for the calculation of theta -- change the sign of this value (ie, replace this value with -2*pi) and this should correct the phase sign.

elaatsch
05-26-2003, 01:48 AM
Thank you very much for your reply. In fact I already solved the problem: It is not usefull to calculate the phase diagramm for amplitudes smaller than 10E-5. That is why I got such a disturbing diagramm !

But thanks again!

Erik