0
$\begingroup$

Is there a way to retrieve both Principal and Actual values for a Phase Response using the fvtool (Open Filter Visualization Tool) in MatLab?

Thanks

$\endgroup$
2
  • $\begingroup$ What are the principal and actual values of an IR? I had never heard those terms before. $\endgroup$
    – MBaz
    Commented Feb 5, 2017 at 2:51
  • $\begingroup$ Sorry, sorry! I've edited the problem statement. Thanks $\endgroup$
    – User 5842
    Commented Feb 5, 2017 at 3:04

1 Answer 1

1
$\begingroup$

the Principal value, $ -\pi < \Phi \le +\pi $, of phase is always

$$\begin{align} \Phi & \triangleq \operatorname{Arg}\{H(e^{j \omega})\} \\ &= \operatorname{Arg} \bigg\{ \Re\{H(e^{j \omega})\} + j \,\Im\{H(e^{j \omega})\} \bigg\} \\ &= \operatorname{atan2}\left(\Im\{H(e^{j \omega})\},\,\Re\{H(e^{j \omega})\}\right) \\ \end{align}$$

the four-quadrant arctangent:

$$\begin{align} \operatorname{atan2}(y,x) &= \begin{cases} \arctan(\frac y x) &\text{if } x > 0, \\ \arctan(\frac y x) + \pi &\text{if } x < 0 \text{ and } y \ge 0, \\ \arctan(\frac y x) - \pi &\text{if } x < 0 \text{ and } y < 0, \\ +\frac{\pi}{2} &\text{if } x = 0 \text{ and } y > 0, \\ -\frac{\pi}{2} &\text{if } x = 0 \text{ and } y < 0, \\ \text{undefined} &\text{if } x = 0 \text{ and } y = 0 \\ \end{cases} \\ \\ &= \begin{cases} \arctan\left(\frac{y}{x}\right) &\text{if } x > 0, \\ \frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } y > 0, \\ -\frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } y < 0, \\ \arctan\left(\frac{y}{x}\right) \pm \pi &\text{if } x < 0, \\ \text{undefined} &\text{if } x = 0 \text{ and } y = 0 \\ \end{cases} \\ \end{align}$$

if, by "Actual value", you mean the unwrapped phase, if you have $\frac{N}{2}$ data points for frequency

$$ \omega[k] \triangleq \frac{2 \pi}{N}k $$

then, assuming real coefficients, define your phase at DC to be:

$$ \phi[0] = \Phi[0] = \begin{cases} 0 \quad & H(e^{j 0}) = H(1) \ge 0 \\ \pm \pi & H(e^{j 0}) = H(1) < 0 \\ \end{cases} $$

then for $ 1 \le k < \frac{N}{2} $ unwrapped phase is

$$ \phi[k] = \phi[k-1] + \Phi[k] - \Phi[k-1] + \theta[k] $$

where

$$ \theta[k] = \begin{cases} 2 \pi \quad & \text{if } \Phi[k] < \Phi[k-1] - \pi \\ 0 & \text{if } \Phi[k-1] - \pi \le \Phi[k] \le \Phi[k-1] + \pi \\ -2 \pi \quad & \text{if } \Phi[k-1] +\pi < \Phi[k] \\ \end{cases}$$

that's pretty much what MATLAB's unwrap() does.

there's a better way to do the phase difference of adjacent discrete frequencies:

the unwrapped phase for $ 1 \le k < \frac{N}{2} $ can also be expressed as

$$\begin{align} \phi[k] &= \phi[k-1] + \Phi[k] - \Phi[k-1] + \theta[k] \\ &= \phi[k-1] + \Delta \phi[k] \\ \end{align}$$

where

$$\begin{align} \Delta \phi[k] &= \Phi[k] - \Phi[k-1] + \theta[k] \\ &= \phi[k] - \phi[k-1] \\ &= \arg\{H(e^{j \omega[k]})\} - \arg\{H(e^{j \omega[k-1]})\} \\ \\ &= \arg\left\{ \frac{H(e^{j \omega[k]})}{H(e^{j \omega[k-1]})} \right\} \\ \\ &= \arg\left\{ \frac{\Re\{H(e^{j \omega[k]})\} + j \Im\{H(e^{j \omega[k]})\}}{\Re\{H(e^{j \omega[k-1]})\} + j \Im\{H(e^{j \omega[k-1]})\}} \right\} \\ \\ &= \arg\left\{ \frac{(\Re\{H(e^{j \omega[k]})\} + j \Im\{H(e^{j \omega[k]})\})(\Re\{H(e^{j \omega[k-1]})\} - j \Im\{H(e^{j \omega[k-1]})\})}{(\Re\{H(e^{j \omega[k-1]})\} + j \Im\{H(e^{j \omega[k-1]})\})(\Re\{H(e^{j \omega[k-1]})\} - j \Im\{H(e^{j \omega[k-1]})\})} \right\} \\ \\ &= \arg\left\{ \frac{\Re\{H(e^{j \omega[k]})\}\Re\{H(e^{j \omega[k-1]})\} - j^2 \Im\{H(e^{j \omega[k]})\}\Im\{H(e^{j \omega[k-1]})\} + j \Im\{H(e^{j \omega[k]})\}\Re\{H(e^{j \omega[k-1]})\} - j\Re\{H(e^{j \omega[k]})\}\Im\{H(e^{j \omega[k-1]})\}}{|H(e^{j \omega[k-1]})|^2} \right\} \\ \\ & = \arg\left\{ \begin{matrix} \Re\{H(e^{j \omega[k]})\}\Re\{H(e^{j \omega[k-1]})\} + \Im\{H(e^{j \omega[k]})\}\Im\{H(e^{j \omega[k-1]})\} \\ + \ j \big(\Im\{H(e^{j \omega[k]})\}\Re\{H(e^{j \omega[k-1]})\} - \Re\{H(e^{j \omega[k]})\}\Im\{H(e^{j \omega[k-1]})\} \big) \end{matrix} \right\} \\ \\ & = \arctan \left( \frac{\Im\{H(e^{j \omega[k]})\}\Re\{H(e^{j \omega[k-1]})\} - \Re\{H(e^{j \omega[k]})\}\Im\{H(e^{j \omega[k-1]})\}}{\Re\{H(e^{j \omega[k]})\}\Re\{H(e^{j \omega[k-1]})\} + \Im\{H(e^{j \omega[k]})\}\Im\{H(e^{j \omega[k-1]})\}} \right) \\ \\ \end{align}$$

because $\Delta \phi[k]$ is expected to be

$$ -\frac{\pi}{2} < \Delta \phi[k] < \frac{\pi}{2} $$

even smaller in most non-pathological cases.

that might be the best way to unwrap phase given the real and imaginary parts of your frequency response function.

$\endgroup$
2
  • $\begingroup$ Great answer! If I now want to plot both the principal and actual value of the Phase Response in MatLab, would I simply do plot([angle(H1) unwrap(angle(H1))];? $\endgroup$
    – User 5842
    Commented Feb 5, 2017 at 4:40
  • $\begingroup$ the Principle value and the unwrapped phase will always differ by an integer times $2 \pi$. you just want the unwrapped phase to be most continuous. $\endgroup$ Commented Feb 5, 2017 at 4:44

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.