function filtered = filt242(x, scale)
% filtered = filt242(x, scale)
% scale is optional; defaults to 2; (should be >= 1)
% three-point filter with center weight at 1/scale and the
%     remainder evenly divideded between the two flanks
% i.e. filtered x(n) is sum(x(n-1)/2  x/(4) x(n+1)/2)

[rows,cols]=size(x);
if (cols == 1)
   flipit = 1;
   x = x';             % row vector
else
   flipit = 0;
end


if (~exist('scale', 'var'))
   scale = 2;
end


if (scale <1)
   error('scale must he equal to or greater than 1')
end


centerweight = 1/scale;
sideweight   = (1-centerweight)/2;

filtered = sum([...
   sideweight  * [x    x(end) x(end)];
   centerweight* [x(1) x      x(end)];
   sideweight  * [x(1) x(1)    x    ]]);

filtered = filtered(2:end-1);

if (flipit)
   filtered = filtered';
end




