Dan - 12 days ago 6

Python Question

I am attempting to calculate the MTF from a test target. I calculate the spread function easily enough, but the FFT results do not quite make sense to me. To summarize,the values seem to alternate giving me a reflection of what I would expect. To test, I used a simple square wave and numpy:

`from numpy import fft`

data = []

for x in range (0, 20):

data.append(0)

data[9] = 10

data[10] = 10

data[11] = 10

dataFFT = fft.fft(data)

The results look correct, with the exception of the sign... I am seeing the following for the first 4 values as an example:

30.00000000 +0.00000000e+00j

-29.02113033 +7.10542736e-15j

26.18033989 -1.24344979e-14j

-21.75570505 +1.24344979e-14j

So my question is why positive->negative->positive->negative in the real plane? This is not what I would expect... It I plot it, it almost appears that the correct function is mirrored around the x axis.

Note: I was expecting the following as an example:

This is what I am getting:

Answer

Your pulse is symmetric and positioned in the center of your FFT window (around N/2). Symmetric real data corresponds to only the cosine or "real" components of an FFT result. Note that the cosine function alternates between being -1 and 1 at the center of the FFT window, depending on the frequency bin index (representing cosine periods per FFT width). So the correlation of these FFT basis functions with a positive going pulse will also alternate as long as the pulse in narrower than half the cosine period.

If you want the largest FFT coefficients to be mostly positive, try centering your narrow rectangular pulse around time 0 (or circularly, time N), where the cosine function is always 1 for any frequency.