clear
t1=(-10)/180*pi;
t2=(10)/180*pi;

load X_sub_opt;
MATTT=X_sub_opt;
l=0:1:9;
counter=0;
counter1=1;
discon=0;
for teta=t1:.001:t2
    a=exp(j*pi*l'*sin(teta));
    counter=counter+1;
    x(counter)=teta;
    y1(counter)=sum((a'*MATTT(:,1:2)));
    y2(counter)=sum((a'*MATTT(:,3:4)));
%     z1(counter)= unwrapkon(-angle(y1(counter)./y2(counter)),1);
    z(counter)= -angle(y1(counter)./y2(counter));
%     w(counter)= angle_extract(z(counter),t3,t4,10,10,MATTT,1);
end

for counter1 = 1:(length(z) - 1)
    if abs(z(counter1 + 1) - z(counter1)) > pi
        discon = discon + 1;
    end
end

if discon == 0
    out1 = min(z);
else
    out1 = (z(counter) + z(1))/2;
end

Z = findpeaks(z);

figure
plot(x,z,'r-')
