FFT Help

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.

    Int_t N = 37500;      // number of points
    TVirtualFFT *fft = TVirtualFFT::FFT(1, &N, "R2C"); 

    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->SetTitle( fftgraphName.c_str() );
    fftgraph->SetName( fftgraphName.c_str() );