title: Understanding FFT output from Jtransform and ColumbiaFFT
body: <p>I obtain a result that I don't understand when I apply the FFT of Jtransform.</p>
  
  <p>The output frequency I get, is different from what I expect.</p>
  
  <p>Currently I try to use Jtransform. From this library, I used <a href="http://wendykierp.github.io/JTransforms/apidocs/org/jtransforms/fft/DoubleFFT_1D.html#realForward-double:A-" rel="nofollow noreferrer"><code>realForward(double[] a)</code></a>.</p>
  
  <p>To test the application, I used the following parameters:</p>
  
  <ul>
  <li><em>input frequency = 50 hz</em></li>
  <li><em>sample rate = 1 Khz</em></li>
  <li><em>signal length = 1024</em></li>
  </ul>
  
  <p>Below is a code snippet of the test method I wrote:</p>
  
  <pre><code>private static void test() {
      //double[] signal = {980, 988, 1160, 1080, 928, 1068, 1156, 1152, 1176, 1264};
  
      int signalLength = 1024;
      double[] signal = new double[signalLength];
      double sampleRate = 1000;
      // Generate sin signal f = 50 , SampleRate = 0,001
      for (int i = 0; i &lt; signal.length; i++) {
          signal[i] = Math.sin(2 * Math.PI * i * 50.0 / sampleRate);
      }
      // Copy signal for columbiaFFT
      double signal2[] = signal.clone();
      // Calculate FFT using Jtransforms
      DoubleFFT_1D fft_1D = new DoubleFFT_1D(signal.length);
      fft_1D.realForward(signal);
  
      double[] magResult = new double[signal.length / 2];
  
      double re, im;
      magResult[0] = signal[0];
      for (int i = 1; i &lt; magResult.length - 1; i++) {
          re = signal[i * 2];
          im = signal[i * 2 + 1];
          magResult[i] = Math.sqrt(re * re + im * im);
      }
      // converting bin to frequency values
      double[] bin2freq = new double[magResult.length];
  
      // sampleRate is in Hz
      for (int i = 0; i &lt; bin2freq.length; i++) {
          bin2freq[i] = i * sampleRate / magResult.length;
          //bin2freq[i] = i  * sampleRate / * signal.length;
      }
      System.out.println("freq 1 " + bin2freq[1]);
  
  
      // Calculate FFT using columbiaFFT
      FFTColumbia fftColumbia = new FFTColumbia(signalLength);
      double[] imaginary = new double[signal2.length];
      fftColumbia.fft(signal2, imaginary);
      double[] magColumbia = new double[signal2.length];
      for (int i = 0; i &lt; magColumbia.length; i++) {
          magColumbia[i] = Math.sqrt(Math.pow(signal2[i], 2) + Math.pow(imaginary[i], 2));
      }
  
  }
  </code></pre>
  
  <p>When I plot the magnitude of the signal apart from seeing a noise and having negative result for the amplitude which I think it could come from not applying a window, I obtain an unexpected f-plot from applying fft of Jtransform (<a href="https://i.stack.imgur.com/WDUtr.png" rel="nofollow noreferrer">image here</a>).</p>
  
  <p>I also would like to ask if the <a href="http://www.ee.columbia.edu/~ronw/code/MEAPsoft/doc/html/FFT_8java-source.html" rel="nofollow noreferrer">FFT Columbia algorithm</a> is displaying directly the frequency and amplitude or if it is also displaying the bin and I would therefore have to convert it to F.</p>
  
  <p><a href="https://i.stack.imgur.com/aI1DB.png" rel="nofollow noreferrer">See Plotting FFT Columbia vs Jtransform</a></p>
  
  <p>Blue signal is FFT Columbia output 
  Red signal is FFT Jtransform output</p>
  
  <p>If that's the case I might have generated the signal wrong.</p>