Inadvertent complex objective function

I have the following CVX/MATLAB code:
cvx_precision low % Still extremely accurate, variable bulkSubset(nTxRf)
objective = 0;
for ff = 1:size(H,3)
hPrime = H(:,:,ff);
objective = objective + log_det(eye(nMsAnt) + snrFactorhPrimediag(bulkSubset)hPrime’);
maximize( objective )
subject to
lb <= bulkSubset <= ub
ones(nTxRf,1) == actTx
sum(bulkSubset) == actTx

My objective function “should” be real, but due to machine error…if I insert a breakpoint in the code and calculate log(det(I+snrFactorhPrimehPrime’)…I get a complex result. Upon running the code, CVX sometimes says that the optimization failed. Am wondering if I should do something like insert a norm or abs somewhere… or what would CVX allow… or is this complex log_det a non-issue?

Need to add… hPrime is a complex matrix

If the imaginary component is just round-off level, then just take the real part. I.e.

CVX is very fussy, and will produce an error message if there is even a tiny imaginary component of something which needs to be real. You can also get into trouble with an expression such as x'A'*A*x which in exact arithmetic should be real, but in floating point arithmetic may result in a non-zero imaginary term. To avoid that, it can be re-written,as (A*x)'*(A*x) , which should avoid a round-off level imaginary term, Or do B = A*x , then use B"*B