# Rescaling the x-axis of FFT transformed histogram

**URL:** <https://root-forum.cern.ch/t/rescaling-the-x-axis-of-fft-transformed-histogram/17761>\
**Category:** ROOT\
**Created:** [June 13, 2014, 2:47pm UTC](https://root-forum.cern.ch/t/rescaling-the-x-axis-of-fft-transformed-histogram/17761 "2014-06-13T14:47:10Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![eberry](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/45deac/32.png) [@eberry](https://root-forum.cern.ch/u/eberry)\
**Post date:** [June 13, 2014, 2:47pm UTC](https://root-forum.cern.ch/t/rescaling-the-x-axis-of-fft-transformed-histogram/17761/1 "2014-06-13T14:47:10Z")

</div>

I am trying to understand how to use TH1::FFT.

As a test, I am trying to compute the real component of the Fourier transform of a cosine function:  
f(t) = cos(2_pi_x)

I expect a result like this:  
F(w) = (1/2) \* [delta(w+1)+delta(w-1)]  
Re(F(w)) = (1/2) \* [delta(w+1)+delta(w-1)]

When I do the transform, the output histogram has a range on the x-axis from 0 to 100. The shape of the output looks correct: all bins have zero entries except for two bins with content = 0.5. But the x-axis should range from -1 to +1, not 0 to 100.

What is the prescription for rescaling the x-axis of the “real” transformed histogram? I see a prescription in the tutorial for “magnitude” and “phase” transformed histograms, but not for “real” or “imaginary” transformed histograms:  
[root.cern.ch/root/html/tutorials/fft/FFT.C.html](http://root.cern.ch/root/html/tutorials/fft/FFT.C.html)

My code is below:

```auto
  int n_bins = 100;
  double x_min = 0.;
  double x_max = 5.;
  
  TH1F * hist = new TH1F("hist","hist", n_bins, x_min, x_max);
  TF1 * func = new TF1("func", "cos(2.0*TMath::Pi()*x)", x_min, x_max);
  
  for (int bin = 1; bin <= n_bins; ++bin){
    double bin_center = hist -> GetBinCenter(bin);
    double func_value = func -> Eval (bin_center);
    hist -> SetBinContent(bin, func_value);
  }
  
  TH1 * hist_transform;
  hist_transform = hist -> FFT(hist_transform, "RE");
  hist_transform -> Scale (1.0 / float(n_bins));
  hist_transform -> Draw();
```

Thanks,  
Edmund

---

_[View the full topic](https://root-forum.cern.ch/t/rescaling-the-x-axis-of-fft-transformed-histogram/17761)._
