clear all;

load data.txt;


d1 = data(:,2);
d2 = data(:,3);
ang = data(:,1);

c1 = interp1([ang; 360],[d1; d1(1)],0:1:359,'spline');
c1 = double(uint8(c1));
c2 = interp1([ang; 360],[d2; d2(1)],0:1:359,'spline');
c2 = double(uint8(c2));

risingstar = zeros(244,3);
for i=140:244
    risingstar(i,1) = i;
    display(i); 
    p = find((c1-i)==0)';
    q = double(uint32((p-1)))
    risingstar(i,2)=max(q);
    risingstar(i,3)=min(q);
    
%     if(length(q)==2)
%         risingstar(i,2)=q(1);
%         risingstar(i,3)=q(2);
%     elseif (size(q)==1)
%         risingstar(i,2)=q;
%     end
end

save ch1.txt risingstar -ASCII

fallingchun = zeros(245,3);
for i = 141:245
    fallingchun(i,1) = i;
    display(i); 
    p = find((c2-i)==0)';
    q = double(uint32((p-1)))
    if (~isempty(q))
        fallingchun(i,2)=max(q);
        fallingchun(i,3)=min(q);
    end
end
save ch2.txt fallingchun -ASCII