## Spencer moving averages

## Spencer moving averages

(OP)

I've just been idly implementing moving averages in Octave, and came across Spencer's moving averages

spencer15=[-3, -6, -5, 3, 21, 46, 67, 74, 67, 46, 21, 3, -5, -6, -3];

spencer21=[-1 -3 -5 -5 -2 6 18 33 47 57 60 57 47 33 18 6 -2 -5 -5 -3 -1];

[ms,z]= filter(spencer21,sum(spencer21),cet);

Just recently we had a question from someone who wanted to use some fancy pants method for determining optima, which seemed quite similar.

Wolfram has this to say

http://mathworld.wolfram.com/SpencersFormula.html

But I have not been able to find a hand wavy description of what exactly spencer was hoping to achieve. FWIW on real data spencer15 seems about equivalent to a simple moving average with period 7.

Does anybody have a handwavy description?

spencer15=[-3, -6, -5, 3, 21, 46, 67, 74, 67, 46, 21, 3, -5, -6, -3];

spencer21=[-1 -3 -5 -5 -2 6 18 33 47 57 60 57 47 33 18 6 -2 -5 -5 -3 -1];

[ms,z]= filter(spencer21,sum(spencer21),cet);

Just recently we had a question from someone who wanted to use some fancy pants method for determining optima, which seemed quite similar.

Wolfram has this to say

http://mathworld.wolfram.com/SpencersFormula.html

But I have not been able to find a hand wavy description of what exactly spencer was hoping to achieve. FWIW on real data spencer15 seems about equivalent to a simple moving average with period 7.

Does anybody have a handwavy description?

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

## RE: Spencer moving averages

http://interstat.statjournals.net/YEAR/2002/articl...

But it's not well explained, and I'm not sure if I follow their notation correctly. But in the discussion on page 6, they mention

"

It deserves to note that Anderson (1971) is pioneer in linking the degree of the polynomial assumed to estimate the trend with the number of terms operating in the moving average formula.In other words (mine), he linked the number of terms (n) used in the average to a polynomial of order (n? n-1?) used to fit the data. Might be interesting to read the original paper to figure out what this really means.They note that Anderson used a least-squares method to find the best fit coefficients for the polynomial. The coefficient matrix they then give looks somewhat like the sequence you show for Spencer's formula, if I'm parsing their notation correctly.

The Wikipedia article for moving averages notes that the French version of the article gives spectral response formula for the filtering done by various moving average weighting schemes; that would be interesting to look at (and compare Spencer's formula to). I'm not sure how to formulate the problem, nor do I hablo Frankish.

With a nod and one last hand-wave, good luck Greg.

## RE: Spencer moving averages

Page 2 of http://www.stat.berkeley.edu/~aditya/Site/Statisti... says that these equations are specifically for leaving polynomial functions "untouched"

TTFN

FAQ731-376: Eng-Tips.com Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

Of course I can. I can do anything. I can do absolutely anything. I'm an expert!

## RE: Spencer moving averages

Cheers

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

## RE: Spencer moving averages

## RE: Spencer moving averages

So the Spencer filter shape does a good job of preserving the low order amplitudes and getting rid of the high frequency stuff.

It's certainly a lot better than a simple moving average, with a faster roll off, and suppressed side lobes.

Cheers

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

## RE: Spencer moving averages

I may not be reading it right (you plotted output vs. frequency, or is it versus period?), or I'm just too tired and fuzzy about the term "rolloff" - you say faster rolloff for the Spencer filter, but it looks like (comparing Spencer 21 to a 21-pt. moving average, which is what I think the two plot lines mean, i.e. same number of terms used) that the plain jane method rolls off more quickly, just that it has more sidelobe "fuzziness" at higher frequencies? I like the idea of the smoother rolloff (lack of sidelobes, if you will) of the Spencer function, it would seem a better averaging technique in that light, as it would tend to smooth noisy data more like how we humans would fair a line through such.

## RE: Spencer moving averages

## RE: Spencer moving averages

The roll off is the gradient at around a gain of 0.5, as you say the 21 MA has a steeper rolloff, but there again it has virtually 0 passband (the level bit with a gain of 1)

You could use a spencer shaped curve instead of Hanning, but people have been looking at this stuff for centuries, the known window shapes already give you a wide range of tradeoffs to choose from. I haven't seen an anti leakage window with negative values before, that does seem rather unhelpful.

Cheers

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

## RE: Spencer moving averages

TTFN

FAQ731-376: Eng-Tips.com Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

Of course I can. I can do anything. I can do absolutely anything. I'm an expert!

## RE: Spencer moving averages

Greg Locock

## RE: Spencer moving averages

Greg Locock

## RE: Spencer moving averages

TTFN

FAQ731-376: Eng-Tips.com Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

Of course I can. I can do anything. I can do absolutely anything. I'm an expert!

## RE: Spencer moving averages

Greg Locock

## RE: Spencer moving averages

Greg Locock