First of all it looks like that the heavy calc burden is occuring within [for .. end] loop. Therefore, a(n) and b(n) should be computed without a loop just using a vectorization. E.g.:
n = 1:N;
[NN, T2]=meshgrid(n,t2);
a = 2/L*sum(y1.*cos(w*NN.*T2));
b = 2/L*sum( y1.*sin(w*NN.*T2));
Y = sum(a.*cos(NN*w.*T2) + b.*sin(NN*w.*T2));