# FFT in MATLAB is shifted in frequency [closed]

I have a signal in MATLAB on which I'd like to perform an FFT. My signal is stored in s, and I use the code below (inspired by the MATLAB help):

L = length(s);
nfft = 2^nextpow2(L);
S = fft(s,nfft)/L;
fftf = 1/Ts/2*linspace(0,1,nfft/2+1);
ffts = (2*abs(S(1:nfft/2+1)));


My signal s is a GMSK-modulated one, that is, it varies between $f_c-2.4e3$ and $f_c+2.4e3$ in my case when transmitting 0 or 1, respectively. $f_c$ is set to 100kHz. For a long input, say, 250 bits worth of 1's and 250 bits worth of 0's, I get what I expect, see the first image below.

If I instead choose a low number of bits, say 10 1 bits followed by 10 0 bits, I get as expected, but it is shifted down to ~90kHz instead of centered at 100kHz. This is something I can't quite understand - it seems changing the sample rate and length of the FFT changes absolutely nothing.

Can anyone explain to me why? Thanks in advance!

EDIT: I'm not allowed to post pictures, so here's some links instead.

-

## closed as off topic by Asaf Karagila, Davide Giraudo, Alexander Gruber♦, Dilip Sarwate, Stefan HansenFeb 21 '13 at 12:23

Questions on Mathematics Stack Exchange are expected to relate to math within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

I feel that this question may benefit more on a programming related site. –  Asaf Karagila Feb 21 '13 at 11:38
@Asaf It's one thing to feel this way, and quite another to say the question is off-topic. Is signal processing not mathematics? –  user53153 Feb 21 '13 at 12:35
@5pm: Depends who you're asking. Sometimes set theory is not mathematics... :-) If I could vote to migrate to SO I would. –  Asaf Karagila Feb 21 '13 at 12:38
I chose math.stackexchange.com because I figured my mistake was mathematical rather than a programming error. But I guess I can try somewhere else.. –  Tausen Feb 21 '13 at 12:40
Without trying it out (don't have matlab) I can guess this is related to the signal being padded to the length that is a power of 2. Padding from 500 to 512 in the first example is a small matter, but in the second it's from 20 to 32. This discussion may be helpful. –  user53153 Feb 21 '13 at 13:07