Note that there are some explanatory texts on larger screens.

plurals
  1. PODiscrete Fourier transform
    text
    copied!<p>I am currently trying to write some fourier transform algorithm. I started with a simple DFT algorithm as described in the mathematical definition:</p> <pre><code>public class DFT { public static Complex[] Transform(Complex[] input) { int N = input.Length; Complex[] output = new Complex[N]; double arg = -2.0 * Math.PI / (double)N; for (int n = 0; n &lt; N; n++) { output[n] = new Complex(); for (int k = 0; k &lt; N; k++) output[n] += input[k] * Complex.Polar(1, arg * (double)n * (double)k); } return output; } } </code></pre> <p>So I tested this algorithm with the following code:</p> <pre><code> private int samplingFrequency = 120; private int numberValues = 240; private void doCalc(object sender, EventArgs e) { Complex[] input = new Complex[numberValues]; Complex[] output = new Complex[numberValues]; double t = 0; double y = 0; for (int i = 0; i &lt; numberValues; i++) { t = (double)i / (double)samplingFrequency; y = Math.Sin(2 * Math.PI * t); input[i] = new Complex(y, 0); } output = DFT.Transform(input); printFunc(input); printAbs(output); } </code></pre> <p>The transformation works fine, but only if numberValues is a multiple number of the samplingFrequency (in this case: 120, 240, 360,...). Thats my result for 240 values:</p> <p><a href="http://s1.directupload.net/images/110928/n3m8hqg6.jpg">http://s1.directupload.net/images/110928/n3m8hqg6.jpg</a></p> <p>The transformation just worked fine.</p> <p>If i am trying to calculate 280 values I get this result:</p> <p><a href="http://s7.directupload.net/images/110928/qizoiqbt.jpg">http://s7.directupload.net/images/110928/qizoiqbt.jpg</a></p> <p>Why I am getting a incorrect result if I change the number of my calculated values? I am not sure if my problem here is a problem with my code or a misunderstanding of the mathematical definition of the DFT. In either way, can anybody help me with my problem? Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload