rfft2d_fr16 and ifft2d_fr16 problem

Question asked by ALitz on Nov 17, 2009
Latest reply on Nov 27, 2009 by AndreasL

Hi,

Im attempting to do an FFT/IFFT on an 8-bit image, but am having poor results with the following code, which simply attempts to do an FFT, then an inverse, to make sure that not too much precision has been lost.   I guess I am uncertain whether or not I am scaling the data correctly?  I am using VDSP 5.0, update 6.

The resultant image I get out of the IFFT vaguely resembles the input image, but with much precision lost....

Original Image:

----------------------

Output Image after IFFT:

-------------------------------------

// Calculate Twiddle

complex_fract16* t_t = (complex_fract16*)malloc(sizeof(complex_fract16)*64);
twidfft2d_fr16(t_t,64);

fract16* pDst=  pInputMatrix;
unsigned char* pSrc = pI1;

// I am attempting to convert 8-bit image data

// to [1 -1], then convert to fract 16 data type?

for(int ii = 0; ii < 64*64 ; ii++)
{
// Scale to 1 to -1
float fVal = (*pSrc++);
fVal = (fVal-128)/255;
fract16 frac =  float_to_fr16(fVal);
*pDst++ = frac;
}

// Do the FFT

rfft2d_fr16(pInputMatrix,pTempMatrix, pOutputMatrix, t_t, 1, 64, 0, 0);
// Immediately do the inverse, to see what I end up with
ifft2d_fr16(pOutputMatrix, pTempMatrix, pFinalMatrix, t_t, 1, 64, 0, 0);

...

// Convert back to 8-bit?

for(int ii = 0; ii < 64*64 ; ii++)
{
float fVal =  fr16_to_float(pSrc->re);
fVal = (fVal*255)+128;
*pDst = (unsigned char)fVal;
pSrc++; pDst++;
}