# Zero Phase - Moving Average Filter

How can I obtain a Zero Phase Moving Average Filter? I read for example in Matlab that filtfilt give you zero phase doing forward and backward filter, I dont understand well how that work, I think taking the same number of values in the past and future can give me that, but it isnt causal right?

• That's correct: taking the same number in the past and the future will give you a zero phase filter (provided the coefficient values are (anti)symmetric), but the filter will not be causal. Does it need to be? Most offline processing does not require causality, hence filtfilt.
– Peter K.
Commented Nov 26, 2015 at 1:48
• Can I obtain a zero phase without taking future values? Commented Nov 26, 2015 at 1:50
• Only in some esoteric situations.
– Peter K.
Commented Nov 26, 2015 at 1:53
• boy, @PeterK., i can't imagine a truly linear-phase and causal filter that is truly IIR. i can't see how you would get symmetry without the thing being FIR. and, semantically, i would call a Truncated IIR (TIIR) a method of implementing a class of FIR. and then you don't get linear phase unless you to the filtfilt thing with it, blockwise, sorta like Powell-Chau. Commented Nov 26, 2015 at 3:32
• This answer explains how filtfilt works. Commented Nov 26, 2015 at 7:48

$$h[n]=\begin{cases}\frac{1}{N},&\quad -(N-1)/2\le n\le (N-1)/2\\0,&\quad\text{otherwise}\end{cases}$$
where $N$ is the (odd) filter length. Since $h[n]$ has non-zero values for $n<0$, it is not causal, and consequently, it can only be implemented by adding a delay, i.e. by making it causal.
Note that you can't simply use Matlab's filtfilt function with that filter because even though you would get zero phase (with a delay), the magnitude of the filter's transfer function gets squared, corresponding to a triangular impulse response (i.e., input samples further away from the current sample receive less weight).
This answer explains in more detail what filtfilt does.