2

I tried using Aforge.Math for doing FFT2 on 2D complex matrix and tried the same on matlab

On C#, for AForge:

Complex[,] array2D = new Complex[,] { {  (Complex)1,  (Complex)2 }, {  (Complex)3,  (Complex)4 }, {  (Complex)5, (Complex) 6 }, {  (Complex)7,  (Complex)8 } };
FourierTransform.FFT2(array2D,FourierTransform.Direction.Forward);

On Mathlab:

x =[1 2; 3 4; 5 6; 7 8]
fft2(x)

but unfortunately the results are not the same for c#: enter image description here

for mathlab:

  36.0000 + 0.0000i  -4.0000 + 0.0000i
  -8.0000 + 8.0000i   0.0000 + 0.0000i
  -8.0000 + 0.0000i   0.0000 + 0.0000i
  -8.0000 - 8.0000i   0.0000 + 0.0000i 

I have no clue why the results are different, btw I can just use tools , don't know details about FFT2. Update: AForge result is scaled according to the input matrix size!

Community
  • 1
  • 1
Md Sifatul Islam
  • 846
  • 10
  • 28
  • Your AForge does not look correct. A "Complex" consists of a real and an imaginary. So (Complex)1 only contains one value instead of two. – jdweng Dec 26 '17 at 09:48
  • @jdweng(Complex)1 does the casting as a result contains both imaginary and real value – Md Sifatul Islam Dec 26 '17 at 11:34
  • Your array is wrong. You are getting two complex numbers instead of one. See : http://www.aforgenet.com/framework/docs/html/a4bea38d-b9fb-4a29-bc5f-e79ee55039e0.htm – jdweng Dec 26 '17 at 12:35
  • @jdweng (Complex)1 means new Complex(1,0).. its the same thing.. – Md Sifatul Islam Dec 26 '17 at 12:41
  • NO, NO, NO!!! { { (Complex)(1,0), (Complex)(2,0) }, { (Complex)(3,0), (Complex)(4,0) }, { (Complex)(5,0), (Complex) (6,0) }, { (Complex)(7,0), (Complex)(8,0) } }; – jdweng Dec 26 '17 at 12:50
  • @jdweng Vs does not accept your statemenet. it says 'Complex' is a type but is being used as a variable! – Md Sifatul Islam Dec 26 '17 at 13:04
  • I just want to point out you were creating two complex number instead of one. Are you adding library Aforge.Math.dll to project and adding namespace Aforge.Math? – jdweng Dec 26 '17 at 13:20
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/161978/discussion-between-md-sifatul-islam-and-jdweng). – Md Sifatul Islam Dec 26 '17 at 13:20
  • @jdweng No. You are wrong. Asker is correct. `(Complex)1` is `1 + 0i`. – David Heffernan Dec 26 '17 at 16:13
  • David : Look at working Matlab code : x =[1 2; 3 4; 5 6; 7 8] it is 1 +2i – jdweng Dec 26 '17 at 16:24
  • @jdweng No it is not. In the C# code `(Complex)1` is `1 + 0i`. In the Matlab code `1` is, well, `1`. Your pride is once again causing you problems. In both sets of code the input data has size 4x2 and each element of those arrays has zero imaginary part. – David Heffernan Dec 26 '17 at 16:32
  • @jdweng if you put x =[1 2; 3 4; 5 6; 7 8] in console you will see matrix of real numbers, not of complex numbers... – Md Sifatul Islam Dec 27 '17 at 00:04

1 Answers1

1

To get the same result as in matlab, change direction to Backward:

FourierTransform.FFT2(array2D,FourierTransform.Direction.Backward);
Evk
  • 98,527
  • 8
  • 141
  • 191