title: Formula 2D discrete fourier transform C#
body: <p>I have problem when calculate 2D discrete fourier transform. Formula DFT, correct result, and my result is <a href="http://i.stack.imgur.com/YDKWJ.png" rel="nofollow">Images</a>. </p>
  
  <p>I try to write formula DFT in C# :</p>
  
  <pre><code>private void DFT()
          {
              tabControl1.SelectedIndex = 1;
              int N, M;
              double gs, fx, ux_d_n, vy_d_m;
              N = 5;
              M = dataGridView1.Rows.Count - 1;
  
              for (int u = 0; u &lt; M; u++)
              {
                  dataGridView2.Rows.Add(1);
                  for (int v = 0; v &lt; N; v++)
                  {
                      gs = 0;
                      for (int x = 0; x &lt; M; x++)
                      {
                          for (int y = 0; y &lt; N; y++)
                          {
                              fx=float.Parse(dataGridView1.Rows[x].Cells[y].Value.ToString());
                              ux_d_n=(float)u * (float)x / (float)N;
                              vy_d_m=(float)v * (float)y / (float)M;
  
                              gs += fx * cos(360F * (ux_d_n + vy_d_m));
                          }
                      }
  
                      if (gs &lt; 0)
                          gs = 0;
                      else if (gs &gt; 255)
                          gs = 255;
  
                      dataGridView2.Rows[u].Cells[v].Value = gs;                
                  }
              }
          }
          private double cos(double sudut)
          {
              double hasil, tmp;
              tmp = sudut * Math.PI / 180F;
              hasil = Math.Cos(tmp);
              hasil = Math.Round(hasil, 4);
              return hasil;
          }
  </code></pre>
  
  <p>Input matrik 2D :</p>
  
  <pre><code>1   5   3   2   5
  1   5   6   2   4
  4   5   2   1   4
  </code></pre>
  
  <p>But my result is not correct.
  My result and correct result : <a href="http://i.stack.imgur.com/YDKWJ.png" rel="nofollow">Images</a>. </p>