Ask Your Question
1

how to use inverse 1D fft when input is real

asked 2016-03-19 08:22:23 -0500

LBerger gravatar image

Hi,

My program is

    N=32;
    Mat idealLow=Mat::zeros(1,N,CV_32FC1);
    int kCutoff = static_cast<int>(N*0.125);
    idealLow(Rect(0,0,kCutoff,1))=1;
    Rect r(N-kCutoff+1,0,kCutoff-1,1);
    idealLow(r)=1;
    cout<<idealLow<<endl;

    Mat hl,hh;

    dft(idealLow,hl,DFT_REAL_OUTPUT|DFT_SCALE|DFT_INVERSE);
    cout<<hl<<endl;

Results are

[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]
[0.25, 0.033356179, 0.22217911, -0.045528557, 0.15088835, -0.12785141, 0.066141248, -0.18034062, 0, -0.18034062, -0.029529601, -0.12785141, -0.025888346, -0.045528561, -0.0087907538, 0.033356179, 0, 0.082128763, -0.0087907612, 0.093363985, -0.025888346, 0.080015987, -0.029529598, 0.06485568, 0, 0.064855687, 0.066141255, 0.080015972, 0.15088835, 0.093363985, 0.22217911, 0.082128748]

Results should be 0.21875,0.2022584, 0.1571044,0.0949414 . Results display is inverse transform of [1. 0.9999999 + 0.9999999i 1.0000000 - 1.255D-08i - 2.282D-09 - 2.077D-08i...]. (my arrays but in complex)

In docs it is written :

When DFT_INVERSE is set and the input array is real, or it is complex but DFT_REAL_OUTPUT is set, the output is a real array of the same size as input. The function performs a 1D or 2D inverse transformation of the whole input array or each individual row, depending on the flags DFT_INVERSE and DFT_ROWS.

My question is : How to perfom an inverse dft with an array of real ?

Thanks for your answer

edit retag flag offensive close merge delete

Comments

Is your input array actually real, or is it just a real representation of imaginary? IE:

[1,1,1,1,0, ..., 0,1,1,1] or is it

[1+1i, 1+1i, 0, ..., 0+1i, 1+1i]

Tetragramm gravatar imageTetragramm ( 2016-03-19 11:46:55 -0500 )edit

It's a real array : H(0)=1 H(1)=1 H(2)=1 H(3)=1 H(4)=0... As I said result displayed is inverse transform of [1. 0.9999999 + 0.9999999i I have checked with matlab. But may be I don't understand doc..(Ps I'm not very good in english)

LBerger gravatar imageLBerger ( 2016-03-19 13:10:55 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-03-19 14:36:53 -0500

Tetragramm gravatar image

I see the problem. You need to put in a second channel of 0. When you have a one channel matrix, I thinks it's in a packed CSS format. You need to specify that the imaginary components are zero. So here's the altered code. Change CV_32FC1 to CV_32FC2 and it works.

N=32;
Mat idealLow=Mat::zeros(1,N,CV_32FC2);
int kCutoff = static_cast<int>(N*0.125);
idealLow(Rect(0,0,kCutoff,1))=1;
Rect r(N-kCutoff+1,0,kCutoff-1,1);
idealLow(r)=1;
cout<<idealLow<<endl;

Mat hl,hh;

dft(idealLow,hl,DFT_REAL_OUTPUT|DFT_SCALE|DFT_INVERSE);
cout<<hl<<endl;
edit flag offensive delete link more

Comments

Thanks I have already done this and It works. But is it well explained in doc?

LBerger gravatar imageLBerger ( 2016-03-19 14:41:54 -0500 )edit
1

Yes, the relevant section is copied here:

In case of real (single-channel) data, the output spectrum of the forward Fourier transform or input spectrum of the inverse Fourier transform can be represented in a packed format called CCS (complex-conjugate-symmetrical). It was borrowed from IPL (Intel* Image Processing Library). Here is how 2D CCS spectrum looks:

<snip matrix="" showing="" the="" packing="" order="">

In case of 1D transform of a real vector, the output looks like the first row of the matrix above.

Tetragramm gravatar imageTetragramm ( 2016-03-19 16:07:05 -0500 )edit
1
LBerger gravatar imageLBerger ( 2016-03-19 16:12:43 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-03-19 08:22:23 -0500

Seen: 618 times

Last updated: Mar 19 '16