function q = myunwrap(p, cutoff, dim);
% function q = myunwrap(p, cutoff, dim);
% 
% This is a utility which performs a bugfix on the Mathworks 
% unwrap.m function. Specifically, unwrap.m only works correctly
% for a cutoff of pi. This extends the function to work 
% correctly for arbitrary cutoffs. 
% 
% Method
% Scale the input, so that the cutoff maps to pi, and perform the unwrap. 
% Then, unscale the input back to the original size. This is numerically 
% kludgy, but it will work for cutoffs that are within a few orders of 
% magnitude of pi. 
% 
% Vivek Nadkarni
% May 14, 2002

switch nargin
    
case 1 
    q = unwrap(p);
case 2
    q = (cutoff/pi)*unwrap(p*(pi/cutoff));
otherwise
    if isempty(cutoff)
        cutoff = pi; 
    end
    q = (cutoff/pi)*unwrap(p*(pi/cutoff), pi, dim); 
end

return; 