# Trying to find phase and group delay of transfer functions

I have several functions I would like to get the phase and group delay. In python I did the following

from sympy import pi, Symbol, I , atan, im, re, simplify, collect, trigsimp, sign

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

# Lp1 - s domain

H_lp1 = wr/(s+wr)

(re_part,im_part) = H_lp1.expand(complex=True).as_real_imag()

H_lp1_ph = atan(im_part/re_part)

Which returns the correct answer but when I try a more complicated function such as

H_lpn2 = ((s**2+wn**2)*(wo/wn) 2)/(s2+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)

It does not return the complete solution. Any ideas?