def generate_sub_matrices(A, rad, RC, n):
    """
    Generate the sub matrices used in RCF routine
    :param A: Data matrix, length n
    :param rad: radius of RCF filter
    :param RC: np array of length 2r+1 with
    :param n:
    :return: A_sub, RC_sub, lists of same dimensions, sampled according to paper: https://doi.org/10.1366%2F12-06766
    """
    ni = n
    A_sub = []
    RC_sub = []
    for i in range(len(A)):
        if i < rad + 1:
            a_sub = A[:i + rad + 1]
            rc_sub = RC[rad - i:2 * rad + 1]
            A_sub.append(a_sub)
            RC_sub.append(rc_sub)
        elif rad + 1 <= i <= n - (rad + 1):
            a_sub = A[i - rad:i + rad + 1]
            rc_sub = RC
            A_sub.append(a_sub)
            RC_sub.append(rc_sub)
        elif i > n - (rad + 1):
            a_sub = A[i - rad:n + 1]
            rc_sub = RC[:rad + (n - i)]
            A_sub.append(a_sub)
            RC_sub.append(rc_sub)
        else:
            print('something has gone wrong')
            import ipdb
            ipdb.set_trace()
            raise RuntimeError("Something has gone wrong and I don't know why")
    return A_sub, RC_sub
