% Anti-aliasing filter.
function R2 = anti_alias(R)
% The basic problem is that sometimes, we have a transfer function R(omega)
% that does not fall off quickly enough in omega, and as a result the odd
% part of R is discontinuous at the nyquist frequency. There is also often
% a slight discontinuity in slope for the even part of R. This function takes
% R and filters it very gently to remove any high-frequency discontinuities.
N = numel(R);
omega = omega_array(N,1);
R2 = R.*(1 + cos(omega))/2;