The problem is with this line:
This causes the gain P to continuously decrease. After a while, the gain P is very small and the filter does not follow the data.
Try replacing this with the following using a constant gain;
KG = 1;
for y = [1:uzunluk]
XK = XK1 + (KG*(Z(a)-XK1));
XK1 = XK;
XK_sakla(a) = XK;
KG_sakla(a) = KG;
Using a constant value of 1, the filter goes through each data point.
After this, try running with KG less than 1 to see the effect, (e.g.)
See how that looks.