# Unwraps a vector of phase values. Like MATLAB's unwrap, but uses (function)

    function H = local_unwrap(H)
    %
    % second difference information to do a better job.
    %
    tol2 = 1.8 * pi;
    n    = length(H);
    dH   = diff( H );
    dH   = mod( dH + pi, 2 * pi ) - pi;
    dH3  = diff( dH, 2 );
    tt1  = find( dH3 > +tol2 ) + 1;
    dH( tt1 ) = dH( tt1 ) - 2 * pi;
    tt2  = find( dH3 < -tol2 ) + 1;
    dH( tt2 ) = dH( tt2 ) - 2 * pi;
    H = reshape( cumsum( [H(1);dH(:)] ), size(H) );