# 3dDFT question

Hello,

I’m trying to run 3dDFT on a surface and wondering why 3dDFT is changing DFT length. The data includes 112 time points - (4: stimuli + 10: resting) * 8 cycles.

Here is my script file and output:
3dDFT -prefix sample.DFT pb06.TMSfMRI.subj1_lh.lh.r01.detrend.niml.dset
++ Authored by: Kevin Murphy & Zhark the Transformer
++ Data length = 112 ; FFT length = 120
++ Output complex-valued dataset: ./sample.DFT.niml.dset

Thanks!
Taek

Hi, Taek-

Looking at the code, it appears that that FFT implementation is optimized for speed, so the input time series are zero-padded up to “powers of 2 combined with powers of 3 and 5 (no more than 3^3 and 5^5, though).” Note that hte output file’s “TR” info has the appropriate physical frequency value (in Hz) corresponding to the upsampled time series. Do you need the spectral values at specific frequencies?

Note also that the type of the numbers in the output volumes is “complex”, so if you wanted amplitudes, for example, you would perhaps want to use 3dcalc:

``````
3dcalc -a FILE -expr 'abs(a)' -prefix AMPS.nii.gz

``````

–pt

Hey Taylor,

Could you explain more specifically about “powers of 2 combined with powers of 3 and 5 (no more than 3^3 and 5^5, though)”…? Does this mean that 3dDFT adds 8 zero-paddings consisting of 3 and 5? Does zero-padding affect the magnitudes and phases of the DFT?

After performing DFT, I calculated the phases and amplitudes at specific frequencies (e.g. in my experiment, the stimulus has a periodicity at frequency 8). For example, I calculate the phase using the following command.

3dcalc -prefix \$output_dir/pb08.\${subj}\${hemi}.\${hemi}.r{\$r}.DFTPHA -cx2r PHASE -a \$output_dir/pb07.\${subj}\${hemi}.\${hemi}.r{\$r}.DFT.niml.dset’[8]’ -expr “a”

Thanks!
Taek

Hi, Taek-

I don’t know what is meant by frequency “8”. At what Hertz is your frequency?

Re. the multiples of two or small factors of 3 and 5-- it is referring to the fact that “120” can be decomposed into only factors of 2, 3 and 5:
120 = 2 * 2 * 2 * 3 * 5

Zeropadding does not add information to the output spectra, but it does alter the frequencies that are reported; often it is used for interpolation, for exmaple (but again, it does not add information).

Re. your 3dcalc command-- I don’t really understand it. So, firstly, you are processing on a surface? And you are picking out the volume with index 8? I don’t think you are getting phase information out by just selecting a single volume (unless you have left out intermediate steps). For a real component “Real” and an imaginary component “Imag” from the complex number, the phase is given by: arctan(Imag/Real).

–pt

Sorry for the confusion!

I don’t know what is meant by frequency “8”. At what Hertz is your frequency?

The stimulus in the experiment has a periodicity at every 42 secs (~.023Hz). Like I said earlier, the data includes 112 time points - (4: stimuli + 10: resting) * 8 times and TR = 3s.

So, firstly, you are processing on a surface?

Yes Correct.

And you are picking out the volume with index 8? I don’t think you are getting phase information out by just selecting a single volume (unless you have left out intermediate steps). For a real component “Real” and an imaginary component “Imag” from the complex number, the phase is given by: arctan(Imag/Real).

The input in the 3dcalc (e.g. \$output_dir/pb07.\${subj}\${hemi}.\${hemi}.r{\$r}.DFT.niml.dset) is the output from the 3dDFT (3dDFT -prefix pb07.\${subj}\${hemi}.\${hemi}.r{\$r}.DFT.niml.dset pb06.\${subj}_\${hemi}.\${hemi}.r{\$r}.detrend.niml.dset). so I believe the input in the 3dcalc already includes complex number. This is why I calculate the phase at the period of 8 (frequency ~0.023Hz). Does this make sense?

Thanks!!
Taek

Bob has now updated the program so you can specify the number of points to match; by default, it will still zeropad up to a “fast” number as before.

In your case with 112 points in the time series, running:

``````
3dDFT -prefix AAA FILE

``````

… would give you an FFT zeropadded to N=120 points.

Now, with the newest version of AFNI, you could run the following:

``````
3dDFT -nfft 112 -prefix BBB FILE

``````

… and that will process (more slowly) with 112 points.

The latter should land you on your frequency more directly, if that’s what you want.

Re. the phase calculation:
Ah, I didn’t see that you had included “-cx2r PHASE” in your 3dcalc command, OK. Sorry for my confusion.

–pt

Great! Thank you for your followup Taylor!

So…if i put the number of time points (nfft), DFT will be performed without zero-padding. I will try to test it!

Thank you so much,
Taek