# Finding group delay of transfer function

I'm having trouble finding the group delay of a transfer function. I've seen a solved question on here about finding the group delay, but I want to understand why my method doesn't work.

Here is some sample code:

h = ButterworthFilterModel[3]
sss = h[I w][[1, 1]]
phase = Arg[sss]
groupDelay = -D[phase, w]
Table[groupDelay, {w, 0, 5, 0.1}]


The problem is that the group delay is giving complex numbers when I expect them to be real. The phase should be a real valued function, and if I test a few values, it indeed seems so. However, when I take the derivative, I start to get complex numbers again.

h = ButterworthFilterModel[3];
sss = h[I w][[1, 1]];
phase = ArcTan@@ComplexExpand@ReIm@sss;
groupDelay = -D[phase, w];
Table[groupDelay, {w, 0, 5, 0.1}] // Chop


{2., 2.0102, 2.04307, 2.10467, 2.20218, 2.33846, 2.50245, 2.65754, 2.74073, 2.69171, 2.5, 2.21471, 1.90347, 1.61361, 1.36504, 1.16015, 0.993811, 0.859041, 0.749315, 0.659249, 0.584615, 0.522165, 0.469411, 0.424449, 0.38581, 0.352349, 0.323169, 0.297559, 0.274951, 0.254885, 0.236986, 0.220949, 0.20652, 0.193486, 0.181671, 0.170924, 0.161119, 0.152148, 0.143916, 0.136345, 0.129363, 0.122911, 0.116935, 0.11139, 0.106235, 0.101433, 0.0969522, 0.092765, 0.0888456, 0.0851716, 0.0817228}

• Thanks, that seems to give the correct answer (other than I think there might possible be one too many minus signs). But other than that, do you know why this works but using Arg doesn't? Does this method just split up some of the steps in a way that Mathematica better understands? May 9, 2020 at 0:57
• I messed up a negative sign, which I have now fixed. May 9, 2020 at 2:17
• Arg is not a differentiable function and as documented another way to get it in terms of differentiable functions is phase=ComplexExpand[Arg[sss],TargetFunctions->{Re,Im}] May 9, 2020 at 2:18
• Interesting, my local help documents (pressing F1 on Arg) don't mention anything about the complex numbers in the "Possible Issues" section. I have a recent version of Mathematica (12.0). I didn't know there are more details if you search for the function online. Thanks for showing this! May 9, 2020 at 22:49
• Do you see it by entering ref/Arg#1547431236 in the Documentation Center? May 9, 2020 at 23:46