55 TCanvas *myc =
new TCanvas(
"myc",
"Fast Fourier Transform", 800, 600);
56 myc->SetFillColor(45);
57 TPad *c1_1 =
new TPad(
"c1_1",
"c1_1",0.01,0.67,0.49,0.99);
58 TPad *c1_2 =
new TPad(
"c1_2",
"c1_2",0.51,0.67,0.99,0.99);
59 TPad *c1_3 =
new TPad(
"c1_3",
"c1_3",0.01,0.34,0.49,0.65);
60 TPad *c1_4 =
new TPad(
"c1_4",
"c1_4",0.51,0.34,0.99,0.65);
61 TPad *c1_5 =
new TPad(
"c1_5",
"c1_5",0.01,0.01,0.49,0.32);
62 TPad *c1_6 =
new TPad(
"c1_6",
"c1_6",0.51,0.01,0.99,0.32);
69 c1_1->SetFillColor(30);
70 c1_1->SetFrameFillColor(42);
71 c1_2->SetFillColor(30);
72 c1_2->SetFrameFillColor(42);
73 c1_3->SetFillColor(30);
74 c1_3->SetFrameFillColor(42);
75 c1_4->SetFillColor(30);
76 c1_4->SetFrameFillColor(42);
77 c1_5->SetFillColor(30);
78 c1_5->SetFrameFillColor(42);
79 c1_6->SetFillColor(30);
80 c1_6->SetFrameFillColor(42);
83 TH1::AddDirectory(kFALSE);
86 TF1 *fsin =
new TF1(
"fsin",
"sin(x)+sin(2*x)+sin(0.5*x)+1", 0, 4*TMath::Pi());
90 TH1D *hsin =
new TH1D(
"hsin",
"hsin", n+1, 0, 4*TMath::Pi());
94 for (Int_t i=0; i<=n; i++){
95 x = (Double_t(i)/n)*(4*TMath::Pi());
96 hsin->SetBinContent(i+1, fsin->Eval(x));
99 fsin->GetXaxis()->SetLabelSize(0.05);
100 fsin->GetYaxis()->SetLabelSize(0.05);
105 TVirtualFFT::SetTransform(0);
106 hm = hsin->FFT(hm,
"MAG");
107 hm->SetTitle(
"Magnitude of the 1st transform");
112 hm->SetStats(kFALSE);
113 hm->GetXaxis()->SetLabelSize(0.05);
114 hm->GetYaxis()->SetLabelSize(0.05);
118 hp = hsin->FFT(hp,
"PH");
119 hp->SetTitle(
"Phase of the 1st transform");
121 hp->SetStats(kFALSE);
122 hp->GetXaxis()->SetLabelSize(0.05);
123 hp->GetYaxis()->SetLabelSize(0.05);
128 TVirtualFFT *fft = TVirtualFFT::GetCurrentTransform();
131 fft->GetPointComplex(0, re, im);
132 printf(
"1st transform: DC component: %f\n", re);
133 fft->GetPointComplex(n/2+1, re, im);
134 printf(
"1st transform: Nyquist harmonic: %f\n", re);
137 Double_t *re_full =
new Double_t[n];
138 Double_t *im_full =
new Double_t[n];
139 fft->GetPointsComplex(re_full,im_full);
142 TVirtualFFT *fft_back = TVirtualFFT::FFT(1, &n,
"C2R M K");
143 fft_back->SetPointsComplex(re_full,im_full);
144 fft_back->Transform();
147 hb = TH1::TransformHisto(fft_back,hb,
"Re");
148 hb->SetTitle(
"The backward transform result");
153 hb->SetStats(kFALSE);
154 hb->GetXaxis()->SetLabelSize(0.05);
155 hb->GetYaxis()->SetLabelSize(0.05);
167 Double_t *in =
new Double_t[2*((n+1)/2+1)];
169 for (Int_t i=0; i<=n; i++){
170 x = (Double_t(i)/n)*(4*TMath::Pi());
171 in[i] = fsin->Eval(x);
183 TVirtualFFT *fft_own = TVirtualFFT::FFT(1, &n_size,
"R2C ES K");
184 if (!fft_own)
return;
185 fft_own->SetPoints(in);
186 fft_own->Transform();
189 fft_own->GetPoints(in);
193 hr = TH1::TransformHisto(fft_own, hr,
"RE");
194 hr->SetTitle(
"Real part of the 3rd (array) tranfsorm");
196 hr->SetStats(kFALSE);
197 hr->GetXaxis()->SetLabelSize(0.05);
198 hr->GetYaxis()->SetLabelSize(0.05);
201 him = TH1::TransformHisto(fft_own, him,
"IM");
202 him->SetTitle(
"Im. part of the 3rd (array) transform");
204 him->SetStats(kFALSE);
205 him->GetXaxis()->SetLabelSize(0.05);
206 him->GetYaxis()->SetLabelSize(0.05);
212 TF1 *fcos =
new TF1(
"fcos",
"cos(x)+cos(0.5*x)+cos(2*x)+1", 0, 4*TMath::Pi());
213 for (Int_t i=0; i<=n; i++){
214 x = (Double_t(i)/n)*(4*TMath::Pi());
215 in[i] = fcos->Eval(x);
217 fft_own->SetPoints(in);
218 fft_own->Transform();
219 fft_own->GetPointComplex(0, re_2, im_2);
220 printf(
"2nd transform: DC component: %f\n", re_2);
221 fft_own->GetPointComplex(n/2+1, re_2, im_2);
222 printf(
"2nd transform: Nyquist harmonic: %f\n", re_2);