# Is fft2 in MATLAB unitary? Some differences happen

I meet a problem when implementing fft2 in MATLAB.

The question is I try to simulate the realistic measurements $$Y = |FCXF^H|^2$$ - the intensity of Fourier domain of object $$X$$, where $$F$$ denotes the Fourier transform matrix $$C$$ denotes $$\{+1, -1\}$$ matrix.

But I want to replace the $$C$$ to realistic $$D = \{0,1\}$$ with $$2D - 1 = C$$. Therefore, after some simple calculations, the measuremnts $$Y$$ becomes $$Y_{real} = 2(|FDXF^H|^2 + |F\bar{D}XF^H|^2) - |FXF^H|^2$$, where $$\bar{D}$$ denotes the inversion of $$D$$. The calculations are from a paper.

For original $$Y$$ and $$C$$ the algorithm could work. Therefore, I try to verify with $$Y_{real}$$. Strange things happen, although the intensity of Fourier domain of $$Y_{real}$$ looks similar with $$Y$$. They are totally different!!!

I am very confused, the equations are right, but why they are different? I think the problem is from fft2 function. Could anyone tell me the principle of fft2? Thanks in advance!!!

Here is the code:

This implements the original algorithm with $$C$$:

Y = abs(fftshift(fft2((2*D-ones(n1,n2)).*x))).^2;


This implements the equation - realisitic measurement:

Y_real = 2*(  abs(fftshift(fft2(D.*x))).^2 + abs(fftshift(fft2( ( ones(n1,n2) - D ).*x ))).^2 ) - abs(fftshift(fft2(x))).^2;


The standard (conventional) definition of DFT (1D or 2D) is not unitary.

See for example the 1D standard (conventional) DFT pair as:

$$X[k] = \sum_{n=0}^{N-1} x[n] e^{-j \frac{2\pi}{N} n k }$$

and

$$x[n] = \frac{1}{N} \sum_{k=0}^{N-1} X[k] e^{j \frac{2\pi}{N} k n}$$

DFT is not unitary due to the fact that the forward and backward transforms are not symmetric (the scale $$\frac{1}{N}$$)

Hence MATLAB's fft() and fft2() functions will not provide unitary transforms; i.e., they do not preserve energy.

However, you can define unitary version of DFT by distributing the scale as:

$$X[k] = \frac{1}{\sqrt{N}} \sum_{n=0}^{N-1} x[n] e^{-j \frac{2\pi}{N} n k }$$

and

$$x[n] = \frac{1}{\sqrt{N}} \sum_{k=0}^{N-1} X[k] e^{j \frac{2\pi}{N} k n}$$

Now this pair is unitary.