function mv=midval(y1,y2,y3)
%mid-value select function - median value
  if (y1 <= y2)
    if (y2 <= y3) 
      mv=y2;
    elseif (y1 <= y3)
      mv=y3;
    else 
      mv=y1;
    end
  else
    if (y1 <= y3)
      mv=y1;
    elseif (y2 <= y3)
      mv=y3;
    else
      mv=y2;
    end
    
   end

  end
