I would like to find the phase of a transfer function in python symbolically
I would like for example to find the phase of H_lp1 given below
from sympy import *
import cmath
import numpy as np
fr = Symbol('fr', real=True)
fo = Symbol('fo', real=True)
fn = Symbol('fn', real=True)
f = Symbol('f',real=True)
q = Symbol('q', real=True)
qn = Symbol('qn', real=True)
wr = 2*pi*fr
wo = 2*pi*fo
wn = 2*pi*fn
w = 2*pi*f
s = I*w
H_lp1 = wo/(s+wo)
Thanks
Adding a more complicated example
LPN - s domain
H_lpn2 = (s**2*(wo/wn)**2+wo**2)/(s**2+s*(wo/q)+wo**2)
(re_part,im_part) = H_lpn2.expand(complex=True).as_real_imag()
H_lpn2_ph_expanded = atan(im_part/re_part)
H_lpn2_ph = simplify(H_lpn2_ph_expanded)
produces atan(f*fo/(q*(f**2 - fo**2)))
This is incorrect as it dropped the term that contains the fn
The correct expression should be
pi*sign(f**2-fn**2)/2 -atan(q*(f**2-fo**2)/(f*fo))