Using Intel IPP's (Integrated Performance Primitive) FFT Function with non power of 2 array

548 views Asked by At

I am using Intel IPP's FFT (Fast Fourier Transform) function in my project. But my input data size is changeable. But IPP's FFT function allows only array with length of power of 2. So i tried to apply zerro padding for to make array power of 2. But it gives wrong results (i compare it with different programs, like MATLAB etc.). My code is;

#include <ipp.h>

// N is input array size

void IPP_fft(int N){

Ipp32fc* src;  //FFT input array
Ipp32fc* dst;  //FFT output array

int powerOf2Sz = pow(2,ceil(log2(N))); //Finding input's upper power of 2 value
                                      //if it's equal to power of 2 it's equal to N

int orderOfFFT = (int)(log((double)powerOf2Sz) / log(2.0));

src = ippsMalloc_32fc(powerOf2Sz);
dst = ippsMalloc_32fc(powerOf2Sz);

//set input with variable

for(int i = 0; i<N;i++){
   src[i].re = i+1;
   src[i].im = 0;
}

//do zero padding for rest of size

for(int i = N; i<powerOf2Sz;i++){
   src[i].re = 0;
   src[i].im = 0;
}

IppsFFTSpec_C_32fc* pSpec=0;

Ipp8u* pMemSpec   = 0;
Ipp8u* pMemInit   = 0;
Ipp8u* pMemBuffer = 0;

int sizeSpec   = 0;
int sizeInit   = 0;
int sizeBuffer = 0;

int flag = IPP_FFT_NODIV_BY_ANY;

//get sizes for required buffer
ippsFFTGetSize_C_32fc(FFTOrder, flag, ippAlgHintNone, &sizeSpec, &sizeInit, &sizeBuffer);

//allocate memory for buffer
pMemSpec = (Ipp8u*)ippMalloc(sizSpec);

if(sizeInit > 0){
pMemInit = (Ipp8u*)ippMalloc(sizInit);
}

if(sizeBuffer > 0){
pMemBuffer = (Ipp8u*)ippMalloc(sizBuffer);
}

//Initialize FFT Specification Structures
ippsFFTInit_C_32fc(&pSpec, FFTOrder, flag, ippAlgHintNone, pMemSpec, pMemInit);

//free initialization buffer
if(sizeInit > 0){
ippFree(pMemInit);
}

//perform Forward FFT
ippsFFTFwd_CToC_32fc(src,dst,pSpec,pMemBuffer);

//you can use dst output array

if(sizeBuffer > 0){
ippFree(pMemBuffer);
}

ippFree(pMemSpec);

}

Before i should say, when N is a power of 2 size, results are fine. (And i know after zero padding, results will be different and i look them with right way) Am i doing zero padding in the wrong way? (I tried to add 1 zero at the beginning but it also gives incorrect results) Or just Intel IPP's FFT function doesn't support array with size non-power of 2 even they zero padded? Do i must use another library like Intel MKL?

0

There are 0 answers