# trying to understand fast fourier transform in matlab

Y = fft(X);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);


1) I dont understand what lines 2-4 are acheiving, why must lines 2-4 be performed?

2) I realised sometimes input signal X must be windowed using a hamming window, what is the purpose of it?

currently an undergrad student, pls explain in a more basic form