Free space path loss in decibels

Free space path loss in decibels#

from sympy import Pow, UnevaluatedExpr, log, pi, symbols

d, f, c = symbols("d f c", positive=True)
SPEED_OF_LIGHT = 299792458  # m/s
fspl_linear = Pow((4 * pi * d * f / c), 2, evaluate=False)
fspl_linear
\[\displaystyle \left(\frac{4 \pi d f}{c}\right)^{2}\]

Conversion to dB

fspl_db = UnevaluatedExpr(10 * log(fspl_linear, 10))
fspl_db
\[\displaystyle \frac{10 \log{\left(\left(\frac{4 \pi d f}{c}\right)^{2} \right)}}{\log{\left(10 \right)}}\]
expanded_expr = fspl_db.expand()
expanded_expr
\[\displaystyle - \frac{20 \log{\left(c \right)}}{\log{\left(10 \right)}} + \frac{20 \log{\left(d \right)}}{\log{\left(10 \right)}} + \frac{20 \log{\left(f \right)}}{\log{\left(10 \right)}} + \frac{20 \log{\left(\pi \right)}}{\log{\left(10 \right)}} + \frac{40 \log{\left(2 \right)}}{\log{\left(10 \right)}}\]

Break into constant and variable-dependent components.

components = expanded_expr.doit().as_independent(d, f)
components
(-20*log(c)/log(10) + 20*log(pi)/log(10) + 40*log(2)/log(10),
 20*log(d)/log(10) + 20*log(f)/log(10))

Evaluate the constant component.

const_component_evald = components[0].evalf(subs={c: SPEED_OF_LIGHT})
const_component_evald
\[\displaystyle -147.552216778117\]

Put the components back together.

const_component_evald + components[1]
\[\displaystyle \frac{20 \log{\left(d \right)}}{\log{\left(10 \right)}} + \frac{20 \log{\left(f \right)}}{\log{\left(10 \right)}} - 147.552216778117\]