%hACLRMeasurementRRC RRC pulse shape as defined in TS25.104 Section 6.8.1
%   RC_0 = hACLRMeasurementRRC(OSR,N,ALPHA) is an RRC pulse shape as
%   defined in TS25.104 Section 6.8.1. The pulse shape is designed with a
%   roll-off factor specified by ALPHA and consists of N samples. The pulse
%   shape is designed with a specified oversampling ratio OSR with respect
%   to the chip rate; therefore the chip rate T_c as mentioned in the
%   standard is implicitly T_c = 1 here.

%   Copyright 2013-2014 The MathWorks, Inc.

function RC_0 = hACLRMeasurementRRC(OSR,N,alpha)

    % tau is the time delay in samples applied to the pulse shape 
    % in order to create a causal filter.
    tau = (N-1)/2;
    
    % T is the sampling rate relative to T_c, the chip period; this
    % function is normalized such that T_c = 1.
    T = 1/OSR;

    % For each sample in the pulse shape:
    RC_0=zeros(N,1);
    for n=0:N-1
        
        % t1 is the sample time; t1 = t/(T_c*OSR) - tau/(T_c*OSR) where
        % t is the sample time used in the specification for RC_0(t). 
        t1 = T * (n - tau);
                
        if (t1 == 0) 
            % Special case given by applying l'Hôpital's rule and 
            % evaluating for t1 = 0. 
            RC_0(n+1) = (pi*(1-alpha) + 4*alpha) / pi;
        elseif (abs(t1) == 1/(4*alpha))
            % Special case given by applying l'Hôpital's rule and 
            % evaluating for t1 = +/- 1/(4*alpha). 
            RC_0(n+1) = 1/sqrt(2)*(2*pi*alpha*(cos(pi/(4*alpha)) + ...
                sin(pi/(4*alpha))) - 4*alpha*(cos(pi/(4*alpha)) - ...
                sin(pi/(4*alpha))))  / (2*pi);
        else            
            % General case given by the equation in the standard.
            RC_0(n+1) = (sin(pi*t1*(1-alpha)) + ...
                4*alpha*t1*cos(pi*t1*(1+alpha))) / ...
                (pi*t1*(1-(4*alpha*t1)^2));
        end

    end
        
    % Normalization to give 0dB passband gain. 
    RC_0=RC_0./sum(RC_0);

end
