I am trying to evaluate the following expression in Mathematica:

$$ \bigg| \frac{\left(1-z^{-2}\right)^n}{\left(1-z^{-1}\right) \left(2-z^{-n}-z^{-1}\right)} \bigg|^2 $$

Here $z$ is the complex exponential (of the $Z$ transform) and is given by: $ z=e^{-2i\pi f/f_s} $, where $f_s$ is a constant.

In order to evaluate this, I wrote the following code in Mathematica:

z := Exp[(2*Pi*I*f/fs)];
h := Abs[(1 - z^-2)^n/((1 - z^-1) (2 - (z^-1) - z^(-n)))];
Simplify[h^2, Element[f, Reals]] // ComplexExpand // TrigReduce 

Mathematica evaluates the expression, however doesn't completely simplify it. I get terms of the following kind in the denominator:

ArcTan[Cos[(2*f*Pi)/fs], Sin[(2*f*Pi)/fs]]

The ArcTan function can obviously be simplified to just 2*f*Pi)/fs.

Is there any way to get Mathematica to do this on its own?

I have posted an image of the code and result I get in the figure.


  • 3
    $\begingroup$ N is a reserved word. Use lowercase for your symbol names $\endgroup$ Mar 8, 2016 at 6:04
  • $\begingroup$ Thanks fro your quick reply. I tried replacing N by small case, however I am still getting the same results. $\endgroup$
    – Saqib Shah
    Mar 8, 2016 at 6:32
  • $\begingroup$ Try {ArcTan[Cos[(2*f*Pi)/fs], Sin[(2*f*Pi)/fs]], (2*f*Pi)/fs} /. {f -> 2, fs -> 1}. You'll see they aren't equal. $\endgroup$
    – Michael E2
    May 17, 2016 at 11:19

2 Answers 2


First, use $n$ and $h$ (not $N$ and $H$) in your code. (Please change your problem accordingly). Second, be sure to use semicolons at the end of each line. Third, make the ArcTan simplification explicitly:

z := Exp[(2 π I f/fs)];
h := Abs[(1 - z^(-2))^n/((1 - z^(-1)) (2 - (z^(-1)) - z^(-n)))];
Simplify[ComplexExpand[h^2], Element[f, Reals]] //. 
 ArcTan[Cos[aa__], Sin[aa__]] -> aa

$\frac{2^{2 n-3} \csc ^2\left(\frac{\pi f}{\text{fs}}\right) \sin ^2\left(\frac{2 \pi f}{\text{fs}}\right)^n}{-2 \cos \left(\frac{2 \pi f n}{\text{fs}}\right)+\cos \left(\frac{2 \pi f}{\text{fs}}-\frac{2 \pi f n}{\text{fs}}\right)-2 \cos \left(\frac{2 \pi f}{\text{fs}}\right)+3}$

Here, the additional transformation is:

ArcTan[Cos[aa_], Sin[aa_]] -> aa

which means everywhere there is a term of this form (where I arbitrarily chose the variable name aa to refer to any set of variables), replace the ArcTan[...] with aa.

  • $\begingroup$ Thanks David for your comment, the last line of your code uses a "->" symbol, I assume this forces Mathematica to convert every expression on the left to the one on the right? (Sorry about the basic question, but I have never used Mathematica before.). One more thing. Why do the Cos and Sin have the arguments "aa__"? $\endgroup$
    – Saqib Shah
    Mar 8, 2016 at 10:04
  • $\begingroup$ @SaqibShah. Look up Rule and ReplaceRepeated in the documentation. $\endgroup$
    – m_goldberg
    Mar 8, 2016 at 12:16

It is important to keep in mind that ArcTan[Tan[x]] is not always equal to x. When x is between -Pi/2 and Pi/2, it is valid. So we have

In[24]:= ArcTan[Tan[x]]

Out[24]= ArcTan[Tan[x]]


In[25]:= FullSimplify[ArcTan[Tan[x]], -Pi/2 < x < Pi/2]

Out[25]= x

Similarly, it follows that

In[26]:= FullSimplify[ArcTan[Cos[x], Sin[x]], -Pi/2 < x < Pi/2]

Out[26]= x

Therefore, in the present question's context we have:

In[27]:= FullSimplify[ ArcTan[Cos[(2*f*Pi)/fs], Sin[(2*f*Pi)/fs]], -fs < 4 f < fs]

Out[27]= (2 f [Pi])/fs


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.