#NEWLINE# def rcosfilter( N , alpha , Ts , Fs ) : #NEWLINE# #INDENT# '\n    Generates a raised cosine (RC) filter (FIR) impulse response.\n\n    Parameters\n    ----------\n    N : int\n        Length of the filter in samples.\n\n    alpha : float\n        Roll off factor (Valid values are [0, 1]).\n\n    Ts : float\n        Symbol period in seconds.\n\n    Fs : float\n        Sampling Rate in Hz.\n\n    Returns\n    -------\n\n    h_rc : 1-D ndarray (float)\n        Impulse response of the raised cosine filter.\n\n    time_idx : 1-D ndarray (float)\n        Array containing the time indices, in seconds, for the impulse response.\n    ' #NEWLINE# T_delta = ( 1 / float ( Fs ) ) #NEWLINE# time_idx = ( ( np . arange ( N ) - ( N / 2 ) ) * T_delta ) #NEWLINE# sample_num = np . arange ( N ) #NEWLINE# h_rc = np . zeros ( N , dtype = float ) #NEWLINE# for x in sample_num : #NEWLINE# #INDENT# t = ( ( x - ( N / 2 ) ) * T_delta ) #NEWLINE# if ( t == 0.0 ) : #NEWLINE# #INDENT# h_rc [ x ] = 1.0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( alpha != 0 ) and ( t == ( Ts / ( 2 * alpha ) ) ) ) : #NEWLINE# #INDENT# h_rc [ x ] = ( ( np . pi / 4 ) * ( np . sin ( ( ( np . pi * t ) / Ts ) ) / ( ( np . pi * t ) / Ts ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( alpha != 0 ) and ( t == ( ( - Ts ) / ( 2 * alpha ) ) ) ) : #NEWLINE# #INDENT# h_rc [ x ] = ( ( np . pi / 4 ) * ( np . sin ( ( ( np . pi * t ) / Ts ) ) / ( ( np . pi * t ) / Ts ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# h_rc [ x ] = ( ( np . sin ( ( ( np . pi * t ) / Ts ) ) / ( ( np . pi * t ) / Ts ) ) * ( np . cos ( ( ( ( np . pi * alpha ) * t ) / Ts ) ) / ( 1 - ( ( ( ( 2 * alpha ) * t ) / Ts ) * ( ( ( 2 * alpha ) * t ) / Ts ) ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( time_idx , h_rc )