Inverse Discrete Fourier Transform And Two-Dimensional Inverse Discrete Fourier Transform

IDFT Formula




N is the size of the sequence. Fundamental Components WN = e^[-j*(2pi/N)], WN^(-nk) is K subharmonic component.
The relation between Euler Formula and Trigonometric Function is:

e^(it) = cos(t)+i·sin(t)
e^(-it) = cos(t)-i·sin(t)

IDFT Code

I deleted my IDFT code unconsciously. The code below is downloaded on the Internet. Thanks Calcular

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Author: Calcular
struct complex{
double r,i;
};
complex multi(complex a,complex b){
complex tmp;
tmp.r=a.r*b.r-a.i*b.i;
tmp.i=a.r*b.i+a.i*b.r;
return tmp;
}
int fi(double in){
if((in-(int)in)>0.5) return (int)in+1;
else return (int)in;
}
void IDFT(double **in,int *out,const int &n)
{
int i,j;
complex **W=new complex*[n];
for(i=0;i<n;i++){
W[i]=new complex[n];
}
complex *lis=new complex[(n-1)*(n-1)+1];
lis[0].r=1;lis[0].i=0;
lis[1].r=cos(2.0*PI/n);
lis[1].i=sin(2.0*PI/n);
for(i=2;i<=(n-1)*(n-1);i++){
lis[i]=multi(lis[1],lis[i-1]);
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
W[i][j]=lis[i*j];
}
}
complex sum;
for(i=0;i<n;i++){
sum.r=0;sum.i=0;
for(j=0;j<n;j++){
sum.r+=W[i][j].r*in[j][0]-W[i][j].i*in[j][1];
sum.i+=W[i][j].i*in[j][0]+W[i][j].r*in[j][1];
}
out[i]=fi(sum.r/n);
}
for(i=0;i<n;i++) delete []W[i];
delete []W;
delete []lis;
}

2D-IDFT Formula




F(u, v) is a spectrum of size MxN, the relation between Euler Formula and Trigonometric Function is:

e^(it) = cos(t)+i·sin(t)
e^(-it) = cos(t)-i·sin(t)

2D-IDFT Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Author: 围城
typedef struct complex
{
double real;
double imagin;
} COMPLEX;
int IDFT2D(COMPLEX *src,COMPLEX *dst,int size_w,int size_h){
for(int i=0;i<size_w;i++){
for(int j=0;j<size_h;j++){
double real=0.0;
double imagin=0.0;
for(int u=0;u<size_w;u++){
for(int v=0;v<size_h;v++){
double R=src[u*size_w+v].real;
double I=src[u*size_w+v].imagin;
double x=Pi*2*((double)i*u/(double)size_w+(double)j*v/(double)size_h);
real+=R*cos(x)-I*sin(x);
imagin+=I*cos(x)+R*sin(x);
}
}
dst[i*size_w+j].real=(1./(size_w*size_h))*real;
dst[i*size_w+j].imagin=(1./(size_w*size_h))*imagin;
}
}
return 0;
}