# Increase resolution for FFT

**URL:** <https://root-forum.cern.ch/t/increase-resolution-for-fft/33502>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [April 8, 2019, 10:46pm UTC](https://root-forum.cern.ch/t/increase-resolution-for-fft/33502 "2019-04-08T22:46:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nyx](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Nyx](https://root-forum.cern.ch/u/Nyx)\
**Post date:** [April 8, 2019, 10:46pm UTC](https://root-forum.cern.ch/t/increase-resolution-for-fft/33502/1 "2019-04-08T22:46:11Z")

</div>

I am trying to extract the frequency spectrum using the FFT functions. I followed the [tutorial](https://root.cern.ch/root/htmldoc/tutorials/fft/FFT.C.html) to fill an histogram from my input TGraph. I have 1e5 entries. Then I calculate the FFT:

```auto
TH1 *fourier = 0;
    TVirtualFFT::SetTransform(0);
    fourier = hprojection->FFT(fourier, "MAG R2C");

    TH1D *h1dMag = new TH1D("h1dMag", "Magnitude (i.e., Power Spectrum)", fourier->GetNbinsX(), 0, fourier->GetXaxis()->GetXmax()/hprojection->GetXaxis()->GetXmax()); 
    // rescale axis to get real units
	for (int bin = 1; bin <= tree->GetEntries(); bin++){
		h1dMag->SetBinContent(bin, fourier->GetBinContent(bin));
	}

```

I get a reasonable result:

 ![test](https://root-forum.cern.ch/uploads/default/original/3X/d/7/d7faeff6341a0acbf264a4ebf51e2883ae2feb02.png)

but I need more resolution around the peak, i.e., I need to know with more accuracy where the maximum is, and the width of the distribution.

In case it is useful, my function is basically a cosine function with some initial phase, and the nominal frequency changes slightly with time.

---

<div class="post-metadata">

**Author:** ![oshadura](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/oshadura/32/14460_2.png) [@oshadura](https://root-forum.cern.ch/u/oshadura)\
**Post date:** [April 9, 2019, 9:27am UTC](https://root-forum.cern.ch/t/increase-resolution-for-fft/33502/2 "2019-04-09T09:27:40Z")

</div>

@couet, can you take a look please here?

Thanks,  
Oksana.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 9, 2019, 9:37am UTC](https://root-forum.cern.ch/t/increase-resolution-for-fft/33502/3 "2019-04-09T09:37:28Z")

</div>

> [@Nyx](#):
>
> but I need more resolution around the peak,

You mean more bins ?

---

<div class="post-metadata">

**Author:** ![Nyx](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Nyx](https://root-forum.cern.ch/u/Nyx)\
**Post date:** [April 9, 2019, 2:00pm UTC](https://root-forum.cern.ch/t/increase-resolution-for-fft/33502/4 "2019-04-09T14:00:31Z")

</div>

Yes, that is what I need. I know what the nominal value is going to be more or less, so instead of having more example 1000 bins from 0 to 1000, I could have 1000 bins between 220 and 240.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 10, 2019, 7:34am UTC](https://root-forum.cern.ch/t/increase-resolution-for-fft/33502/5 "2019-04-10T07:34:37Z")

</div>

May be the [variable bin size histogram](https://root.cern/doc/master/classTH1F.html#a2d7efdd7f1e89f2679e5ab8b38c441a9) is a solution in your case ?

---

<div class="post-metadata">

**Author:** ![Nyx](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@Nyx](https://root-forum.cern.ch/u/Nyx)\
**Post date:** [April 10, 2019, 2:00pm UTC](https://root-forum.cern.ch/t/increase-resolution-for-fft/33502/6 "2019-04-10T14:00:40Z")

</div>

The problem is that I want more bins in the `fourier` histogram, but the bins of this histogram will be determined by the bins of the original histogram by the function `fourier = hprojection->FFT(fourier, "MAG R2C");`  
I understand that it is after this step that the binning, i.e., the resolution, is defined. I can’t increase the number of bins of `hprojection` since this is given by the data.

My question would be: is it possible to have more bins for the histogram where the FFT is stored? It would be even better if I can define the range of that histogram around the known nominal value, in order to improve even more the accuracy.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 10, 2019, 2:14pm UTC](https://root-forum.cern.ch/t/increase-resolution-for-fft/33502/7 "2019-04-10T14:14:52Z")

</div>

> [@Nyx](#):
>
> My question would be: is it possible to have more bins for the bin where the FFT is stored? It would be even better if I can define the range of that histogram around the known nominal value, in order to improve even more the accuracy.

I guess @moneta can help you.
