# FFT Help

**URL:** <https://root-forum.cern.ch/t/fft-help/17302>\
**Category:** ROOT\
**Created:** [March 1, 2014, 7:17am UTC](https://root-forum.cern.ch/t/fft-help/17302 "2014-03-01T07:17:16Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![PaMu](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/5f8ce5/32.png) [@PaMu](https://root-forum.cern.ch/u/PaMu)\
**Post date:** [March 1, 2014, 7:17am UTC](https://root-forum.cern.ch/t/fft-help/17302/1 "2014-03-01T07:17:16Z")

</div>

Hi, I am new to root and having problems with FFT. I want to perform the FFT on captured time domain signals captured in the lab.

I have for example a 4 MHz square wave with 37,500 sample points. The code I am using is below. I would really appreciate if someone with more experience could help me answer these questions.

1. Should I use the same amount of time-domain points for the FFT?

2. On my output FFT graph , I am getting negative amplitudes? How is that possible if I am only getting the real values. Should I convert all values to absolute values and If so How do I do this?

3. The biggest issue is getting the graph to label the actual correct frequencies on the x-axis. How is this implemented? For example a 2KHz square wave FFT shows the fundamental peak at less than 100 on the x-axis and when I zoom in even this value changes. It is very important that I have correct frequency values labelled there.

My code is below. y is the Double\_t array containing my time-domain data. I am not sure If I am going about it the correct way. Many thanks for any help in advance.

```auto
    Int_t N = 37500; // number of points
    TVirtualFFT *fft = TVirtualFFT::FFT(1, &N, "R2C"); 
    fft->SetPoints(y);                       
    fft->Transform();                                           

    TH1 *hb1 = 0;
    hb1 = TH1::TransformHisto(fft,hb1,"RE"); // fill histogram hb1 with real values

    TGraph* fftgraph = new TGraph(hb1);                        
    fftgraph->GetXaxis()->SetRange(0, N/2); // Don't displayed mirrored values 
    std::string fftgraphName = (*it)+" FFT";
    fftgraph->SetLineColor(2);
    fftgraph->SetTitle( fftgraphName.c_str() );
    fftgraph->SetName( fftgraphName.c_str() );
    fftgraph->Write();
```

---

_[View the full topic](https://root-forum.cern.ch/t/fft-help/17302)._
