title: Frequencies when performing FFT with Eigen::FFT
body: <p>I'm currently trying to figure out how exactly to use <code>Eigen</code>'s FFT algorithm. Let us a assume I have a function</p>
  
  <pre><code>std::complex&lt;double&gt; f(std::complex&lt;double&gt; const &amp; t){
      return std::sin(t);
  }
  </code></pre>
  
  <p>I then compute with this function</p>
  
  <pre><code>Eigen::VectorXcd time(1000);
  Eigen::VectorXcd f_values(1000);
  for(int u = 0; u &lt; 1000; ++u){
      time(u) = u* 2. * M_PI / 1000;
      f_values(u) = f(time(u));
  }
  </code></pre>
  
  <p>I'd now like to compute the Fourier transformation of <code>f_values</code>, so I do</p>
  
  <pre><code>Eigen::FFT&lt;double&gt; fft;
  Eigen::VectorXcd f_freq(1000);
  fft.fwd(f_freq, f_values);
  </code></pre>
  
  <p>Now I would like to plot this, but to do this I need the frequencies at which <code>f_freq</code> was evaluated, but I don't really know how to obtain these frequencies. So my question boils down to finding the <code>Eigen::VectorXcd</code> containing the frequencies to plot things like this
  <a href="https://i.stack.imgur.com/lPATN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lPATN.png" alt="enter image description here"></a>
  (I'm sorry for using a picture as description, but I think its much clearer this way then if I tried to describe it with words... The <code>amplitude</code> from the plot should correspond to my <code>f_freq</code> and what I looking for is the values of <code>freq</code> in the picture...).</p>
  
  <p>Here are the above code snippets put into a single file:</p>
  
  <pre><code>#include &lt;eigen3/Eigen/Dense&gt;
  #include &lt;eigen3/unsupported/Eigen/FFT&gt;
  #include &lt;complex&gt;
  #include &lt;cmath&gt;
  
  std::complex&lt;double&gt; f(std::complex&lt;double&gt; const &amp; t){
       return std::sin(t);
  }
  
  int main(){
      Eigen::VectorXcd time(1000);
      Eigen::VectorXcd f_values(1000);
      for(int u = 0; u &lt; 1000; ++u){
          time(u) = u* 2. * M_PI / 1000;
          f_values(u) = f(time(u));
      }
  
      Eigen::FFT&lt;double&gt; fft;
      Eigen::VectorXcd f_freq(1000);
      fft.fwd(f_freq, f_values);
      //freq = ....
  }
  </code></pre>
  
  <hr>
  
  <p>I implemented one of the suggested answers as follows:</p>
  
  <pre><code>#include &lt;eigen3/Eigen/Dense&gt;
  #include &lt;eigen3/unsupported/Eigen/FFT&gt;
  #include &lt;complex&gt;
  #include &lt;cmath&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  std::complex&lt;double&gt; f(std::complex&lt;double&gt; const &amp; t){
       return std::sin(1.*t);
  }
  
  int main(){
      std::ofstream freq_out("frequencies.txt");
      std::ofstream f_freq_out("f_freq.txt");
  
      unsigned const N = 1000.;
      Eigen::VectorXcd time(N);
      Eigen::VectorXcd f_values(N);
      for(int u = 0; u &lt; N; ++u){
          time(u) = u* 2. * M_PI / double(N);
          f_values(u) = f(time(u));
      }
  
      Eigen::FFT&lt;double&gt; fft;
      Eigen::VectorXcd f_freq(N);
      Eigen::VectorXd freq(N);
      fft.fwd(f_freq, f_values);
  
      double const Ts = 2. * M_PI/double(N);
      double const Fs = 1./Ts;
  
      for(int u = 0; u &lt; N; ++u){
          freq(u) = Fs * u / double(N);
      }
  
      freq_out &lt;&lt; freq; 
      f_freq_out &lt;&lt; f_freq.cwiseAbs();
  }
  </code></pre>
  
  <p>which results in the following plot
  <a href="https://i.stack.imgur.com/Aj8ex.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Aj8ex.png" alt="enter image description here"></a>
  This seems a bit off.. The scaling certainly makes not much sense, but also the fact that there are two values that spike makes me a bit skeptical..</p>