four_lines
four_lines

Reputation: 503

Matlab fft2 (2D) giving interchanged values compared to multiple fft (1D) performed across rows and columns

function [output1, output2] = fft2D(input)

   output1 = input';
   output1 = fft(output1);
   output1 = output1';
   output1 = fft(output1);

   output2 = fft2(input);
end

So I calculate in output2 the 2D FFT of input and in output1 the same 2D FFT of input. fft() applies, for a 2D matrix, FFT across the column vectors. So above I apply it over the rows and then over the columns.

However for a random matrix

 [1   1   4   1; 
  12  13  124 1;
  12  2   2   1;
  1   1   1   0]

my output1 is:

   1.0e+02 *

   1.7700 + 0.0000i  -1.0500 + 0.1400i   1.3700 + 0.0000i  -1.0500 - 0.1400i
  -0.1000 - 1.4700i  -0.0200 + 1.1100i  -0.0800 - 1.2100i  -0.2400 + 1.1300i
  -1.2900 + 0.0000i   1.1900 - 0.1200i  -1.0900 + 0.0000i   1.1900 + 0.1200i
  -0.1000 + 1.4700i  -0.2400 - 1.1300i  -0.0800 + 1.2100i  -0.0200 - 1.1100i

and my output2 is

   1.0e+02 *

   1.7700 + 0.0000i  -1.0500 - 0.1400i   1.3700 + 0.0000i  -1.0500 + 0.1400i
  -0.1000 - 1.4700i  -0.2400 + 1.1300i  -0.0800 - 1.2100i  -0.0200 + 1.1100i
  -1.2900 + 0.0000i   1.1900 + 0.1200i  -1.0900 + 0.0000i   1.1900 - 0.1200i
  -0.1000 + 1.4700i  -0.0200 - 1.1100i  -0.0800 + 1.2100i  -0.2400 - 1.1300i

They are the same values but interchanged in various positions! This has been driving me crazy for a long time, because from what I've (re)read online 2D FFT can be performed by applying 1D FFT across rows and then columns. Any help or suggestion would be great!

Upvotes: 4

Views: 87

Answers (1)

jodag
jodag

Reputation: 22214

Use output1 = output1.' instead of output1 = output1' since the latter gives the conjugate transpose and you want the transpose.

function [output1, output2] = fft2D(input)
   output1 = input.';
   output1 = fft(output1);
   output1 = output1.';
   output1 = fft(output1);

   output2 = fft2(input);
end

Alternatively you can specify the dimension to take the FFT along.

function [output1, output2] = fft2D(input)
   output1 = fft(input,[],1);
   output1 = fft(output1,[],2);

   output2 = fft2(input);
end

Upvotes: 5

Related Questions