# What Is the Transfer Function of a Moving Average (FIR Filter)?

To make post-processing easier, I export scope measurements as CSV files, which are then post-processed (mostly in Microsoft Excel, which is not the best tool for the job, but it is all I have at my disposal).

One of the post processing used is a simple moving average, and I was wondering how it does transform the source measurement. I expect it to behave similarly to a low-pass filter, but I guess it is not the same. Hence, my question.

I am specifically looking for a Bode plot. Thanks in advance.

• "all I have at my disposal:" if you're allowed to run software on your computer, there's a wealth of free tools that are really really good. In your case, you might want to look into getting octave – or, if you're more after a modern language, go for Python / Numpy / Scipy. Enthought Canopy actually is a pretty nice thing to have fun with Python signal processing and math tools, and totally free. – Marcus Müller Jun 9 '17 at 9:54
• Not in a locked-down professional environment, but thanks for the references anyway. – Sclrx Jun 9 '17 at 9:56
• :( environments that "protect" their users from using the right tools make me sad; and that's coming from someone who's used to working with people that have to develop on actually air-gapped computers. I don't know your company's policies, and I do not wish to interfere with those, but there's a lot of software that can be run directly from the folder you've downloaded them in, without installation. Octave for Windows as an example: you simply uncompress the .zip and run bin/octave or so. – Marcus Müller Jun 9 '17 at 10:04
• There's also plenty bootable USB drive images that you can start your computer with without interfering in any way with the data on your hard drive. Might be a nice thing to get started with at home. – Marcus Müller Jun 9 '17 at 10:05
• – Olli Niemitalo Jun 9 '17 at 10:26

The frequency response of the moving average is called the asinc or psinc, the aliased sinc or periodic sinc (sinc for cardinal sine), or the Dirichlet function.

Since the sum of the moving average filter coefficients is equal to one, it preserves constant signal, hence is somewhat lowpass. When the length $N=2$, the shape in the frequency domain is shaped like a cosine, hence decreasing.

Otherwise, it ripplles in the frequency domain. When the length is even, the amplification at Nyquist is $0$, when odd, of $1/N$, as shown below:

So it's globally lowpass, not the best, but one of the fastest to compute, allowing fast recursive computations.

The following figure is borrowed from Frequency Response of the Running Average Filter:

This is the gain applied to different frequencies (normalized to interval 0-$\pi$), for running averages of length $L = 4$ (red), $8$ (green), and $16$ (blue). As you can see, low frequencies are better preserved than higher frequency ones, with ripples (except for $L=2$, the only true low-pass, but an imprecise one). So globally, the behavior is low-pass. It is very simple to compute, and not very good, as said in other answer.

However, for a better job:

• you can easily implement better finite support low-pass filter in Excel (for almost the same price)
• you can call external .exe. or .dll calls in Excel for sharper low-pass filters (did that 15 years back, my highest scientific achievement)
• you can use free, easy to install software/languages, like scilab, octave, freemat, julia, python, where better filters are implemented (or easy to program, allowing you to read, filter and export csv files for other purposes.

A moving average is a shifted rectangle in the time domain, so it transforms to a (phase modulated) sinc() function centered at DC in the frequency domain. It is a lowpass filter, just not a very good one: high sidelobes and a very slow transition.

Moving Average in its general form is basically an FIR Filter which means it can mimic any linear system you'd like by the choice of the length and coefficients.

If you mean Moving Average by a filter of length $N$ and with coefficients of the form $\frac{1}{N}$ then this constant sliding window will have LPF effect indeed.

It will have the form of a Sinc in the Frequency hence it is not the best LPF to play with.

• i think all moving average filters have an LPF effect. they all have a DC gain of 1. – robert bristow-johnson Oct 7 '17 at 19:32

TF = (1 - z^- D)/(1- z^-1)

Where D is the number of cycles you use for averaging. This is a recursive implementation, though still an FIR. It will behave the same as a the non-recursive implementation as long as the memory elements are properly initialized to zero.