FFT - Help

Hi,

I have recently begun using FFT in root in order to upsample FADC traces. I wish to transform into the frequency domain, pad as required, then transform back into the time domain. If I do not pad the trace, I should recover the original distribution. This is not the case.

My code looks something like this:

//define original histogram
TH1F *h = new TH1F(Form(“h %d %d”, EventId, TankId),“FADC trace”,iter,x[0],x[iter]);
h->GetXaxis()->SetRange(x[0], x[iter]);
for (int i=0;i<iter;i++)
h->SetBinContent(i+1,y[i]/3);
h->GetXaxis()->SetTitle(“t [ns]”);
h->GetYaxis()->SetTitle(“Signal [VEM]”);
h->Draw();

//transform into frequency domain

TH1F *hTrans = new TH1F(“h in frequecy space”, “h in frequecy space”, iter, 0, iter);
hTrans = h->FFT(hTrans, “MAG R2C M”);
hTrans->Draw();
hTrans->SetStats(kFALSE);

//transform back into time domain - should recover same trace

TH1F *hInvTrans = new TH1F(“h in time”, “h in time”, iter, x[0],x[iter] );
hInvTrans = hTrans->FFT(hInvTrans, “MAG C2R M”);
hInvTrans->Draw();
hInvTrans->SetStats(kFALSE);

I guess I don’t know what should be the x-axis label for hTrans, and then again for hInvTrans. Am I doing this correctly? i.e. does “MAG R2C” actually give the correct frequency domain transform, and “MAG C2R” inversely transform this? From the FFT manual it seemed to suggest this. The full code and ascii input are also attached.

I recently posted this on the support forum and think it was in the wrong place. Sorry if I have caused any problems.

Thank you for any help you can give me,

Regards

Ben
3000015_651.txt (5.14 KB)
UpSample.C (1.7 KB)

Hi Ben,

“MAG R2C” will give you a histogram of the magnitudes of the fft of your original histogram. You can’t do an inverse transform on this magnitude histogram, because it’s not really your transform result, it’s only the magnitude of it. Also, it’s true, that the inverse for “R2C” is “C2R”, but, as “C2R” stands for “complex to real”, you can’t do it from a histogram (you want to transform complex numbers). So, you have to make a new TVirtualFFT object of a C2R transform, and give it the output of your transform as input. It’s simpler than it sounds :slight_smile:
I’ve changed your macro to do that, so please take a look, and tell me if it does what you want it to do. The array “output” contains the same values as your original histogram, scaled by the size of the transform.

Cheers,
Anna
fft_forum.C (2.29 KB)

Hi Anna,

Thank you for your help. I think I understand but when I run the macro I get 2 errors:

Error in TFFTComplexReal::Transform: transform was not initialised

and

Error in TPad::Range: illegal world coordinates.

Try as I might, I can not fix this. Did it compile for you? I am using root 5.15/06 on SUSE linux and have installed fftw-3.1.2.

Many thanks, I really appreciate it.

Regards

Ben

Hi Anna,

I have fixed the problem by re-installing my root version. It works fantastically!

Many thanks

Regards

Ben