Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6712 Discussions

Problem with FFT - wrong amplitudes in calculated magnitude spectrum

lkosovsky
Beginner
399 Views
Hi,
I'm developing an application for Xscale processor. The goal is to perform FFT of already acquired block of data.

Below is a snippet of the code I'm using:

IppsFFTSpec_R_32s *pFFTSpec = NULL;
Ipp8u *pWorkBuf = NULL;

Ipp32s* pDst = ippsMalloc_32s(blockSize + 2);
Ipp32s* pDstMag = ippsMalloc_32s(blockSize/2);

status = ippsFFTInitAlloc_R_32s(&pFFTSpec, order, IPP_FFT_DIV_FWD_BY_N, ippAlgHintNone);
status = ippsFFTGetBufSize_R_32s(pFFTSpec, &bufSize);
pWorkBuf = (Ipp8u*)malloc(bufSize);
ippsFFTFwd_RToCCS_32s_Sfs(pSrc, (Ipp32s*)pDst, pFFTSpec, 0, pWorkBuf);
ippsMagnitude_32sc_Sfs((Ipp32sc*)pDst, pDstMag, blockSize/2, 0);

I apply windows on the raw data and don't expect result amplitudes to be exactly correct, but what I get is not quite right. Frequencies are all in right places of the spectrum, but amplitudes are wrong

Hope somebody in the forum has done similar processing, and will be kind enough to look at the code snippet to point at my mistake. I think I'm doing something wrong.

Thank you,
Leon Kosovsky
0 Kudos
4 Replies
Vladimir_Dudnik
Employee
399 Views

Hello Leon,

there is comment from our experts:

it seems you are trying to apply complex magnitude to results from real FFT transform.

Please try to convert CCS data to complex format or perform complex FFT operation.

Regards,
Vladimir

0 Kudos
Vladimir_Dudnik
Employee
399 Views

there is additional comment from our expert:

if you are interested only in first half of FFT results you may use CCS format.

It is not clear what seems to be wrong for you, FFT results or subsequent Magnitude results?

BTW, please note that in your code FFT contains blockSize/2 + 1 complex elements whereas Magnitude calculates 1 elements less.

The results of FFT is divided by 2**order (IPP_FFT_DIV_FWD_BY_N) so results of Magnitude will be also N times less. If you need Magnitude results in correct range you may use IPP_FFT_NODIV_BY_ANY at FFT call or you can apply scalefactor = -order at Magnitude call.

Regards,
Vladimir

0 Kudos
lkosovsky
Beginner
399 Views
Hello Vladimir, thank you for your help.

I was trying to imitate an Example 7-5, from page 7-38 from the latest (v5.2) ippsman.pdf. I am interested in only first part of FFT. That is why I was using CCS format and ippsMagnitude function.

Now, the FFT result was correct only partially: frequencies were all in right spots but amplitudes ( and subsequently magnitudes) were off.

It turned out, and I have to apologizes for this, I had a problem with raw data that was processed by my FFT implementation. I expected to see specific spectrum magnitudes assuming known input signals. But these signals were corrupted due to problem in DAQ driver. That is why results were wrong. When I fixed the driver everything became correct.

I've applied the advice you give in your post. Here is the final stripped code snippet that works for me:

Ipp32s* pDst = ippsMalloc_32s(blockSize + 2);
Ipp32s* pDstMag = ippsMalloc_32s(blockSize/2 + 1);

status = ippsFFTInitAlloc_R_32s(&pFFTSpec, order, IPP_FFT_DIV_FWD_BY_N, ippAlgHintNone);
status = ippsFFTGetBufSize_R_32s(pFFTSpec, &bufSize);
pWorkBuf = (Ipp8u*)malloc(bufSize);
ippsFFTFwd_RToCCS_32s_Sfs(pSrc, pDst, pFFTSpec, 0, pWorkBuf);
ippsMagnitude_32sc_Sfs((Ipp32sc*)pDst, pDstMag, (blockSize/2 + 1), -1);

Hope it'll be useful for our online community :-)

Thank you.
0 Kudos
Vladimir_Dudnik
Employee
399 Views

thank you for sharing your findings here, definetely it may help others to use IPP functions in their applications

Regards,
Vladimir

0 Kudos
Reply