function [encoder,full_encoder,az]=az_calcul(encoder, antenna_zero, section)

full_encoder=zeros(1,length(encoder)*4);

d=diff(encoder);


u_jump=find(d < 0 & d~=-511);
for i=1:length(u_jump)
    
    test=d(u_jump(i))+d(u_jump(i)-10: u_jump(i)+10);% u_jump(i) is at half +1 in the test array so , 11
    u_zero=find(test >=0 & test <=5);
    if 11 < u_zero(1)
        index=u_zero (1) -11;
        encoder(u_jump(i)+1 : u_jump(i)+index) = encoder(u_jump(i)+index+1);
    else
        index= 11- u_zero(1);
        encoder(u_jump(i)-index+1 : u_jump(i)) = encoder(u_jump(i)+1);
    end
    
end

% u_gap=find(d>1);
% encoder1(1:u_gap(1))=encoder(1:u_gap(1));
% m=19;  %number of packets for the scan/512 (encoder maximum value +1. Ku=512, C=2048)
% for i=1:length(u_gap)
%     temp=[];
%     for j=encoder(u_gap(i))+1:encoder(u_gap(i)+1)-1
%         temp=[temp j*ones(1,m)];
%     end
%     encoder1=[encoder1 temp];
%     a=encoder1';
%     if i+1<=length(u_gap)
%         encoder1=[encoder1 encoder(u_gap(i)+1:u_gap(i+1))'];
%         a=encoder1';
%     else
%         encoder1=[encoder1 encoder(u_gap(i)+1:length(encoder))'];
%     end
% end
encoder1=encoder;
for i=1:length(encoder1)
    full_encoder((i-1)*4+1:i*4)=encoder1(i);
end
middle=section(1:length(section)-1)+3;
temp_az=middle-antenna_zero;
u_neg=find(temp_az < 0);
temp_az(u_neg)=temp_az(u_neg)+512;
az=temp_az*0.7031;
% for i=1:number_az
%     temp=full_encoder((i-1)*M+1)+(full_encoder(i*M)-full_encoder((i-1)*M+1))/2;%mean(full_encoder((i-1)*M+1:i*M));%
%     az_a(i)=temp*0.7031;
% end

% az_a=90-az;
% u_neg=find(az_a<0);
% az_a(u_neg)=az_a(u_neg)+360;