#include "TH1D.h" #include "TVirtualFFT.h" #include "TF1.h" #include "TCanvas.h" void FFT_Back(){ //prepare the canvas for drawing TCanvas *myc = new TCanvas("myc", "Fast Fourier Transform", 800, 600); myc->SetFillColor(45); TPad *c1_1 = new TPad("c1_1", "c1_1",0.01,0.51,0.49,0.99); TPad *c1_2 = new TPad("c1_2", "c1_2",0.51,0.51,0.99,0.99); TPad *c1_3 = new TPad("c1_3", "c1_3",0.01,0.01,0.49,0.49); TPad *c1_4 = new TPad("c1_4", "c1_4",0.51,0.01,0.99,0.49); c1_1->Draw(); c1_2->Draw(); c1_3->Draw(); c1_4->Draw(); c1_1->SetFillColor(30); c1_1->SetFrameFillColor(42); c1_2->SetFillColor(30); c1_2->SetFrameFillColor(42); c1_3->SetFillColor(30); c1_3->SetFrameFillColor(42); c1_4->SetFillColor(30); c1_4->SetFrameFillColor(42); c1_1->cd(); //A function to sample TF1 *fsin = new TF1("fsin", "sin(x)", 0, 2*TMath::Pi()); fsin->Draw(); Int_t n=1000; TH1D *hsin = new TH1D("hsin", "hsin", n+1, 0, 2*TMath::Pi()); Double_t x; //Fill the histogram with function values for (Int_t i=0; i<=n; i++){ x = (Double_t(i)/n)*(2*TMath::Pi()); hsin->SetBinContent(i+1, fsin->Eval(x)); } hsin->Draw("same"); fsin->GetXaxis()->SetLabelSize(0.05); fsin->GetYaxis()->SetLabelSize(0.05); c1_2->cd(); double re, im; TH1 *hm =0; hm = hsin->FFT(hm, "MAG"); hm->Draw(); c1_3->cd(); TH1 *hp = 0; hp = hsin->FFT(hp, "PH"); hp->Draw(); c1_4->cd(); TVirtualFFT *fft = TVirtualFFT::GetCurrentTransform(); fft->GetPointsComplex(re,im); TVirtualFFT *fft_back = TVirtualFFT::FFT(1, &n, "C2R M K"); fft_back->SetPointsComplex(re,im); fft_back->Transform(); TH1 *hb = 0; hb = TH1::TransformHisto(fft_back,hb,"MAG"); hb->Draw(); }