function [c_L,c_L_ind,c_R,c_R_ind]=segments(pom_L,pom_R,peak)
% peak 1 - MINIMUM
% peak 2 - MAXIMUM

    for j=1:size(pom_L,1)
        x=pom_L(j,:);             % 1-50
        delka=length(x);
        okno_d=10;
        pres=4;
        body=[];indexy=[];
        for i=1:pres:(delka-okno_d+1)
            sig=x(i:(i+okno_d-1));
            if peak==1      
                [p1,ind]=min(sig);
            else
                [p1,ind]=max(sig);
            end
            body=[body p1];
            indexy=[indexy ind+i-1];
        end        
        if peak==1
            [a,b]=min(body);
            c_L(j,1)=a;
            c_L_ind(j,1)=indexy(b);
        else
            [a,b]=max(body);
            c_L(j,1)=a;
            c_L_ind(j,1)=indexy(b);
        end
    end

    for j=1:size(pom_R,1)
        x=pom_R(j,:);             % 1-50
        delka=length(x);
        okno_d=10;
        pres=5;
        body=[];
        indexy=[];
        for i=1:pres:(delka-okno_d+1)
            sig=x(i:(i+okno_d-1));
            if peak==1      
                [p1,ind]=min(sig);
            else
                [p1,ind]=max(sig);
            end
            body=[body p1];
            indexy=[indexy ind+i-1];
        end
        if peak==1
           [a,b]=min(body);
            c_R(j,1)=a;
            c_R_ind(j,1)=indexy(b);
        else
            [a,b]=max(body);
             c_R(j,1)=a;
             c_R_ind(j,1)=indexy(b);
        end
        
    end

end