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);
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);