Zero-Phase Algorithm in Matlab From this document it's says

1.Filter the Data
2.Flip that
3.Filter again
4.and Flip that again


for zero-phase filter. but when i do this in matlab , i'm compare between filtfilt method and what i did , it isnt equal. what is the problem ?  

MATLAB CODE

clc;clear all;
emg_healthy=load('emg_healthy.txt');
x= 10;
fs= 4000;
my_counter = 1000;
myRawData = emg_healthy(:,2);
myRawData = myRawData(1:my_counter);
myDataRecti = abs(myRawData);
[b,a]= butter(6,x/(fs/2),'low');
filter_y=filtfilt(b,a,myDataRecti);
firstFilter = filter(b,a,myDataRecti);
flip_firstFilter = fliplr(firstFilter);
secondFilter = filter(b,a,flip_firstFilter);
flip_secondFilter = fliplr(secondFilter);
xlabel('Sample Number');ylabel('Genliği');plot(flip_secondFilter,'b');
hold on ;
xlabel('Sample Number');ylabel('Rect Genliği');plot(filter_y,'r');


RESULT



-----------------------------------EDIT-----------------------------------

thanks to robert bristow-johnson, i tried zero-padding to myData , end and begin.
This is i try

MATLAB CODE

% % EMG Soleus 
clc;clear all;
emg_healthy=load('emg_healthy.txt');
x= 10;
fs= 4000;
my_counter = 1000;
myRawData = emg_healthy(:,2);
myRawData = myRawData(1:my_counter);
myDataRecti = abs(myRawData);
[b,a]= butter(6,x/(fs/2),'low');
for i = 1:1:(my_counter/4)
myZeroDataRecti(i) = 0;    
end
for i = (my_counter/4+1):1:(my_counter+my_counter/4)
myZeroDataRecti(i) = myDataRecti(i-my_counter/4);
end
for i=(my_counter+my_counter/4+1):1:(my_counter+my_counter/4+my_counter/4)
    myZeroDataRecti(i) = 0;
end
filter_y=filtfilt(b,a,myZeroDataRecti);
firstFilter = filter(b,a,myZeroDataRecti);
flip_firstFilter = fliplr(firstFilter);
secondFilter = filter(b,a,flip_firstFilter);
flip_secondFilter = fliplr(secondFilter);
xlabel('Sample Number');ylabel('Amplitude');plot(myZeroDataRecti,'g');
hold on ;
xlabel('Sample Number');ylabel('Amplitude');plot(flip_secondFilter,'b');
xlabel('Sample Number');ylabel('Amplitude');plot(filter_y,'r');
% 


RESULT



another i try , i again add zero-padding begin and end but i used filtfit method to apply without zero-padding data 

MATLAB CODE 

% % EMG Soleus 
clc;clear all;
emg_healthy=load('emg_healthy.txt');
x= 10;
fs= 4000;
my_counter = 1000;
myRawData = emg_healthy(:,2);
myRawData = myRawData(1:my_counter);
myDataRecti = abs(myRawData);

[b,a]= butter(6,x/(fs/2),'low');
filter_y=filtfilt(b,a,myDataRecti);
for i = 1:1:(my_counter/4)
myZeroDataRecti(i) = 0;    
end
for i = (my_counter/4+1):1:(my_counter+my_counter/4)
myZeroDataRecti(i) = myDataRecti(i-my_counter/4);
end
for i=(my_counter+my_counter/4+1):1:(my_counter+my_counter/4+my_counter/4)
    myZeroDataRecti(i) = 0;
end
firstFilter = filter(b,a,myZeroDataRecti);
flip_firstFilter = fliplr(firstFilter);
secondFilter = filter(b,a,flip_firstFilter);
flip_secondFilter = fliplr(secondFilter);
xlabel('Sample Number');ylabel('Amplitude');plot(flip_secondFilter,'b');
hold on ;
xlabel('Sample Number');ylabel('Amplitude');plot(myDataRecti,'g');
xlabel('Sample Number');ylabel('Amplitude');plot(myZeroDataRecti,'c');
xlabel('Sample Number');ylabel('Amplitude');plot(filter_y,'r');
% 


RESULT



in my opion, there are two things we have to think about that,

1.First picture in the edit part,my signal (myCode-LEGEND) amortize itself , but matlab function (filtfilt) keep continiues , why is that ?

2.Second picture in the edit part, my signal(myCode-LEGEND) different from filtfilt function signal. And between myCode and 250Zero+originalData+250Zero i think it doesnt any phase shift. If we say that it's true what should i do ? Will i remove 250 zero from begin and end ?
As far as I can see you're doing the basic filtering right. The difference with Matlab's filtfilt function is that the latter uses certain initial conditions in the calls to filter to minimize transients.

The Matlab documentation says the following:


  filtfilt minimizes start-up and ending transients by matching initial conditions, and you can use it for both real and complex inputs


The appropriate reference is


  Gustafsson, F. "Determining the initial states in forward-backward filtering." IEEE® Transactions on Signal Processing. Vol. 44, April 1996, pp. 988–992