Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spencer moving averages 2

Status
Not open for further replies.

GregLocock

Automotive
Apr 10, 2001
23,422
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


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?



Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Replies continue below

Recommended for you

There's a little bit of hand-waviness here:


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.
 
I thought I replied yesterday, but...

Page 2 of says that these equations are specifically for leaving polynomial functions "untouched"

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529

Of course I can. I can do anything. I can do absolutely anything. I'm an expert!
 
Thanks, that last link was just the ticket, it leaves low order polynomials (N<4) 'untouched', that is it is essentially a low pass filter. I'll have a play with it and see what its frequency response is like.


Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Would be interested in any results you get for freq. response Greg.
 
Here's the frequency response for a 1024 sample length

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
 
Thanks for that, Greg.

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.
 
Just realized, this would be interesting to people doing FFT analysis, i.e. using Hamming windows...the wiki article for those shows the spectral response of various windowing schemes (all of which show a lot of sidelobe fuzz), and there is some discussion of it going on in thread248-370129 (though the OP keeps talking about Humming windows...)
 
It is plotted versus bin number, ie frequency.

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
 
I would guess that you should be comparing the 21-pt to 21-pt, which shows a higher bandwidth for the Spencer, which probably translates into less phase error.

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529

Of course I can. I can do anything. I can do absolutely anything. I'm an expert!
 
Here's the argument of the transfer function in radians. I'm a bit leary of the MA result, as I used zero padding.



Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Can that, the phase shift of all 4 of those curves can be zeroed by using appropriate zero padding.



Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
You can shift all the phases by doing that, but you can't fix the phase vs. frequency of the filter itself.

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529

Of course I can. I can do anything. I can do absolutely anything. I'm an expert!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor