# Phase response of moving average filter -- how to interpret?

There are many articles on the frequency response of the moving average filter but they all seem to focus on magnitude. However the phase response is intriguing and I find it hard to interpret. The phase appears to "wrap", but it wraps within the [-pi, pi) interval rather than at its edges. Example below:

A phase unwrapping algorithm would not resolve this, so it is really a "pseudo-wrap". Further, if I add taps to the moving average, it flattens this process out, so I suspect that mathematically, the moving average filter will never reach 0 or 2 pi, though I have never seen an explanation why. Example of an 11-tap:

I find this behaviour fascinating and would be interested in the interpretation of an expert. Does this suggest that features will be distorted at certain "weak spots" in the frequency response? Is it correct to call the phase of a moving average filter "piecewise-linear" rather than linear? I suspect not, given that symmetric FIR filters are analytically shown to have linear phase, but I have a hard time calling this linear.

The frequency response of a causal length $N$ moving average filter is

$$H(\omega)=\frac{\sin\left(\frac{N\omega}{2}\right)}{N\sin\left(\frac{\omega}{2}\right)}e^{-j\omega(N-1)/2}=A(\omega)e^{j\phi(\omega)}\tag{1}$$

Note that $A(\omega)$ is not the magnitude of $H(\omega)$, but it is a real-valued amplitude function, which takes on positive as well as negative values. The phase $\phi(\omega)=-(N-1)\omega/2$, as defined in $(1)$, is obviously linear. That's also the common definition when we talk about a linear phase response.

The phase you plotted is not $\phi(\omega)$, but $\hat{\phi}(\omega)$ as defined by

$$H(\omega)=|A(\omega)|e^{j\hat{\phi}(\omega)}\tag{2}$$

The difference between $\phi(\omega)$ and $\hat{\phi}(\omega)$ is that whenever $A(\omega)$ crosses zero, a phase jump of $\pm \pi$ occurs in $\hat{\phi}(\omega)$, corresponding to a sign change in $A(\omega)$. Nevertheless, we still refer to $H(\omega)$ as a frequency response with a linear phase, because $\phi(\omega)$ is a linear function of $\omega$.

Note that in practice, a linear phase is only relevant in the pass band of a filter, i.e. in a frequency region where no zeros of $H(\omega)$ occur. In the pass band, also $\hat{\phi}(\omega)$ is linear, because it only jumps at the zeros of $H(\omega)$.

• Is there a Matlab command that extracts this definition of phase rather than phase angle? Commented Jan 15, 2016 at 13:13
• @barnhillec: Not that I know of, but for filters with even symmetry in their coefficients, the phase always equals $-(N-1)\omega/2$, where $N$ is the filter length. For odd symmetry you get an additional offset of $\pi/2$. Commented Jan 15, 2016 at 13:21