function [raisedcos, t] = rc(alpha, trange, tstep, toffset)

%Raised Cosine Pulse
%function [raisedcos, t] = rc(alpha, trange, tstep, toffset) 
%   returns a vector whose elements are the raised cosine pulse function 
%   of the elements of t
%   raisedcos = sinc(t) * cos(pi*alpha*t) / (1 - 4* alpha^2 * t^2)
%   t = [-trange : tstep: trange] + toffset
%   alpha = rolloff factor in [0, 1]
%   toffset = timing offset
%   EE 120 - University of California, Berkeley - Fall 2005


t = (-trange:tstep:trange) + toffset;
raisedcos = zeros(size(t));

if (alpha == 0)
    raisedcos = sinc(t);
else
    tmp = find((t ~= 1/(2*alpha)) & (t ~= -1/(2*alpha)));
    raisedcos(tmp) = sinc(t(tmp)).*cos(pi.*alpha.*t(tmp))./(1 - 4*alpha^2.*t(tmp).^2);
    raisedcos(find(t==1/(2*alpha))) = sinc(1/(2*alpha))*pi/4;
    raisedcos(find(t==-1/(2*alpha))) = sinc(-1/(2*alpha))*pi/4;
end
