I can't correctly extract spectrum from data points of odd function (e.g. $\cos\left(\frac23\pi x\right)$, $16$-points vector $[1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1]$), instead of one function I get a bunch of sines and cosines (which are correct for a given window and points, but still not ok for further analysis):
$(0.375000)\cos( (2.00)\pi x) + (0.000000)\sin( (2.00)\pi x)+ (0.042224)\cos( (1.88)\pi x) + (0.008399)\sin( (1.88)\pi x)+ (0.044194)\cos( (1.75)\pi x) + (0.018306)\sin( (1.75)\pi x)+ (0.048952)\cos( (1.62)\pi x) + (0.032708)\sin( (1.62)\pi x)+ (0.062500)\cos( (1.50)\pi x) + (0.062500)\sin( (1.50)\pi x)+ (0.164437)\cos( (1.38)\pi x) + (0.246097)\sin( (1.38)\pi x)+ (-0.044194)\cos( (1.25)\pi x) + (-0.106694)\sin( (1.25)\pi x)+ (-0.005612)\cos( (1.12)\pi x) + (-0.028213)\sin( (1.12)\pi x)+ (0.000000)\cos( (1.00)\pi x) + (0.000000)\sin( (1.00)\pi x)+ (-0.005612)\cos( (0.88)\pi x) + (0.028213)\sin( (0.88)\pi x)+ (-0.044194)\cos( (0.75)\pi x) + (0.106694)\sin( (0.75)\pi x)+ (0.164437)\cos( (0.62)\pi x) + (-0.246097)\sin( (0.62)\pi x)+ (0.062500)\cos( (0.50)\pi x) + (-0.062500)\sin( (0.50)\pi x)+ (0.048952)\cos( (0.38)\pi x) + (-0.032708)\sin( (0.38)\pi x)+ (0.044194)\cos( (0.25)\pi x) + (-0.018306)\sin( (0.25)\pi x)+ > (0.042224)\cos( (0.12)\pi x) + (-0.008399)\sin( (0.12)\pi x)$
Is it a fundamental restriction of the FFT or am I doing something wrong? Thank you.
Input sanity check: repeat your sequence to see if it describes the function you want. Your input:
when repeated, becomes
This obviously is not a simple periodic function: sometimes two 1s appear together. This is what your FFT output describes.
How to fix this? Don't include the redundant right endpoint of the period. Concretely:
Additional points:
1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1have to do with $\cos(2\pi/3)$? Sampling this function at integers, I get1,-.5,-.5repeated.fft([1,0,0,1,0,0,1,0,0,1,0,0,1,0,0])/15in Matlab works just fine, resulting in $$\frac13 + \frac13 \exp(5\cdot 2\pi ix/15)+\frac13 \exp(-5\cdot 2\pi ix/15) = \frac13+\frac23 \cos(2\pi x/3)$$