function Pulse = RaisedCosPulse(L, fsT, beta)
% RaisedCosPulse - Raised cosine Nyquist pulse
%
% Generates a raised cosine pulse spanning L symbol intervals with fsT
% samples per symbol period. beta is the roll-off factor. 
%
% Notice that the effect of the parameter L is to truncate the principally
% infinitely long pulse to L symbol periods. The peak of the pulse is in the
% center, i.e., the pulse is symmetric!
%
% Inputs:
%   L    - pulse length
%   fsT  - samples per symbol period
%   beta - roll-off factor ( beta=0: sinc pulses )
%
% Output:
%   Pulse - pulse shape (L*fsT samples)
%
% Example: 
%   Pulse=RaisedCosPulse(L,fsT,beta)

%% time axis 
t_over_T = (-L/2.0*fsT : 1 : L/2.0*fsT-1)/fsT; % normalized to T

%% generate roll-off function
if (beta > 0)
  % There may be a division by zero at t_over_T = +/-1/(2*beta). Be careful
  % if we are sampling at those values.
  
  crit_ind = ( abs(abs(t_over_T) - 1/(2*beta)) < eps );
  safe = t_over_T( crit_ind );
  % set problematic sample instances to something safe
  t_over_T( crit_ind ) = 0; 
  
  Pulse = cos(beta*pi*t_over_T) ./ (1-(2*beta*t_over_T).^2);
  % fix tricky samples
  Pulse(crit_ind)    = pi/4; 
  t_over_T(crit_ind) = safe;
else
  Pulse = ones( size(t_over_T) );
end

%% multiply with sinc
Pulse = Pulse.*sinc(t_over_T); 