Getting wrong periodogram
I think that is because your exponentials are wrong.
There is no variable named w in your code, although you refer to it, so I believe it should be something like:

per2(i)=sum(x(k)*exp(-2j*pi*k*w(i))));


But consider using fft instead:

pe2 = abs(fft(x)).^2;


or

pe2 = abs(fft(x(1:K))).^2;


if you insist on using only $K$ samples for some reason (why generate 10000 sample then??).

Perhaps you should consider the Welch method, with length 256

pe2 = pwelch(x,256,128,256);


BTW - you can generate AR process using filter:

x = filter(1,a,wn);


where a is the vector of AR coefficients.