Matlab code demonstrating use of fft (Fast Fourier Transform)
Your time vector definition is defined a bit strange, I would go for the more standardized form of

startpoint:stepsize:endpoint

endpoint = T*(L-1) % is this correct?
0:T:endpoint


Besides this you could perhaps add some comments in the calculate spectrum section, but for the rest it looks quite clear.