Thread Subject: difference between filter and movavg output

Subject: difference between filter and movavg output

From: david

Date: 10 Mar, 2011 15:38:07

Message: 1 of 2

Hi,

I am currently using the filter function to calculate an exponential moving average with the following code:

a=2/(N+1);
coef=repmat(1-a,1,N).^(1:N);
ema=filter(coef,sum(coef),data);

Which seems to work fine, however, when I use a for loop to calculate the same EMA I am getting different results. The for loop is as follows:

a=2/(N+1);
ema=zeroes(length(data),1);
ema(1)=data(1);
for i=2:length(data);
     ema(i)=ema(i-1)+a.*(data(i)-ema(i-1))
end

Using the "movavg" function gives the same results as above.
Has anyone any idea as to why these 2 methods are providing different results?
If so, could you please point out where my errors are?

Subject: difference between filter and movavg output

From: Charbel

Date: 20 Apr, 2011 12:15:08

Message: 2 of 2

Sorry can't help U...

i only have one question:

N is the number of points that u got?

Best Regards

CSA

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
moving average david 10 Mar, 2011 10:39:06
filter david 10 Mar, 2011 10:39:06
exponential mov... david 10 Mar, 2011 10:39:05
rssFeed for this Thread

Contact us at files@mathworks.com