function [bmask, b] = bigtarget(a, thresh, offset, nside)
           % offset 5, nside 2 looks good for OS; thresh about 25
[nd, np] = size(a);   % maybe extend later to handle all 4 beams at once

ii = 1:nd;

switch nside
   case 1
      aa = (a + a([1, 1:(nd-1)], :) + a([2:nd, nd], :)) / 3;
   case 2
      aa = (a + a([1, 1:(nd-1)], :) + a([2:nd, nd], :) + ...
                a([1, 1, 1:(nd-2)], :) + a([3:nd, nd, nd], :)) / 5;
   case 3
      aa = (a + a([1, 1:(nd-1)], :) + a([2:nd, nd], :) + ...
                a([1, 1, 1:(nd-2)], :) + a([3:nd, nd, nd], :) + ...
                a([1, 1, 1, 1:(nd-3)], :) + a([4:nd, nd, nd, nd], :)) / 7;
   case 0
      aa = a;
   otherwise
      error('nside must be in range 0-3');
end

wu = ones(nd, 1);
wu(1:offset) = (0:(offset-1)).' / offset;
wu(nd:-1:(nd - offset + 1)) = 2 - wu(1:offset);
wd = 0.25 * flipud(wu);
wu = 0.25 * wu;

wu = wu(:, ones(np, 1));
wd = wd(:, ones(np, 1));

iu = [ones(1, offset), 1:(nd - offset)];
id = [(1 + offset):nd, nd * ones(1, offset)];

b = 0.5 * a - wu .* aa(iu, :) - wd .* aa(id, :);

% Ignore the top (offset + nside) bins
topmask = ones(nd, np);
topmask(1:(offset+ nside), :) = 0;

bmask = (b > thresh) & topmask;




