公式2D离散傅立叶变换C#

时间:2015-12-02 10:39:53

标签: c# dft

计算2D离散傅立叶变换时遇到问题。公式DFT,正确的结果和我的结果是Images

我尝试在C#中编写公式DFT:

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 < M; u++)
            {
                dataGridView2.Rows.Add(1);
                for (int v = 0; v < N; v++)
                {
                    gs = 0;
                    for (int x = 0; x < M; x++)
                    {
                        for (int y = 0; y < 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 < 0)
                        gs = 0;
                    else if (gs > 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;
        }

输入matrik 2D:

1   5   3   2   5
1   5   6   2   4
4   5   2   1   4

但我的结果不正确。 我的结果和正确结果:Images

0 个答案:

没有答案