SB_mean=function(gamma, delta, n_terms = 50) {
  #Equation 56 from Johnson (1949)
  n = 1:n_terms
  
  mu=c()
  size=length(gamma)
  if(length(delta)==1) delta=rep(delta,size)
  
  for(i in 1:size){
    
    part1 = 0.5 / delta[i]
    
    arg_exp2  = -n^2 / (2 * delta[i]^2)
    arg_cosh  =  n * (1 - 2 * gamma[i] * delta[i]) / (2 * delta[i]^2)
    arg_sech  =  n / (2 * delta[i]^2)
    
    terms2 = exp(arg_exp2) * cosh(arg_cosh) / cosh(arg_sech)
    part2  = sum(terms2) / delta[i]
    
    
    m         = 2 * n - 1
    arg_exp3  = -0.5 * m^2 * pi^2 * delta[i]^2
    arg_sin3  =  m * pi * gamma[i] * delta[i]
    arg_csch3 =  m * pi^2 * delta[i]^2
    
    terms3 = exp(arg_exp3) * sin(arg_sin3) / sinh(arg_csch3)  # cosech(x) = 1/sinh(x)
    part3  = -2 * pi * delta[i] * sum(terms3)
    
    numerator = part1 + part2 + part3
    
    arg_exp_d = -2 * n^2 * pi^2 * delta[i]^2
    arg_cos_d =  2 * n * pi * gamma[i] * delta[i]
    
    denominator = 1 + 2 * sum(exp(arg_exp_d) * cos(arg_cos_d))
    
    mu[i] = (1 / sqrt(2 * pi)) * exp(-0.5 * gamma[i]^2) * numerator / denominator
  }
  return(mu)
}