Hello, Would someone please tell me 1- If we have x[n] (with 100 samples 0..100) and we want to calculate moving average with ( M1 = 5 and M2=5 ) how we should calculate y[0] and y[100] (because it needs x[-5] and x[105]) ? 2- Generally if we have an ideal delay system how we should calculate the output on the same domain of input (because we will need data that is out of input's domain)? Regards, Mac
Movin average
Started by ●April 8, 2005
Reply by ●April 8, 20052005-04-08
Mac wrote:> 1- If we have x[n] (with 100 samples 0..100) and we want to calculate > moving average with ( M1 = 5 and M2=5 ) how we should calculate y[0] > and y[100] (because it needs x[-5] and x[105]) ?a) 0..100 is 101 samples. b) What do you mean by M1, M2? c) From the looks of the question you're saying: movingAverage[n] = sum_{k=n-M1}^{n+M2} x[k] d) There are lots of ways to treat out-of-bounds indices: i) x[n] = 0 for n<0 and n > 100 ii) x[n] = x[n modulo 101] iii) x[n] = x[101-n] for 100 < n < 106 = x[-n] for 0 > n > -6 These correspond to assuming: i) The data is all you have and everything else is zero. ii) The data is really periodic and just keeps repeating itself. iii) The data reflects about its end-points. Depending on what your data is, and what you intend to do with it, one or other might be a better assumption. Gee I hope this isn't a homework question. :-(> 2- Generally if we have an ideal delay system how we should calculate > the output on the same domain of input (because we will need data > that is out of input's domain)?I don't understand the question. Can you re-phrase it? Ciao, Peter K.
Reply by ●April 8, 20052005-04-08
Mac wrote:> Hello, > > Would someone please tell me > > 1- If we have x[n] (with 100 samples 0..100) and we want to calculate > moving average with ( M1 = 5 and M2=5 ) how we should calculate y[0] > and y[100] (because it needs x[-5] and x[105]) ?What do M1 and M2 mean?> 2- Generally if we have an ideal delay system how we should calculate > the output on the same domain of input (because we will need data that > is out of input's domain)?If I understand you (I probably don't, fully), it goes like this: A moving average can be computed by summing the contents of a delay line and dividing by the length of the line. The average won't be correct until the delay line is full of actual samples. Usually, that amounts to a "startup transient" in practice, and is tolerable. An improvement is to average only the actual samples, so the number of items averaged increases by one each time around until the delay line is filled. This creates a different king of transient, sometimes preferred. jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●April 8, 20052005-04-08
"Mac" <macter@doonotspamhost111.com> wrote in message news:1112956945.cedbdbb1fcfee3448b6931e29896f28a@teranews...> Hello, > > Would someone please tell me > > 1- If we have x[n] (with 100 samples 0..100) and we want to calculate > moving average with ( M1 = 5 and M2=5 ) how we should calculate y[0] > and y[100] (because it needs x[-5] and x[105]) ?You don't. Think about what "average" means....> > 2- Generally if we have an ideal delay system how we should calculate > the output on the same domain of input (because we will need data that > is out of input's domain)??????? Do you mean how do you align the output with the input in time? The best answer (for a purist) might be that you don't because you can't. But there may be practical things one could do nonetheless. Another answer might be developed like this: You know the delay. So, delay the input by the known delay amount and align it with the output (for display purposes I suppose). Another answer might be developed like this: You know the delay. So "advance" the output to make the delay go away. I'm thinking of this in the context of a "lead network". I think it really means that you generate a phase shift at some frequency that *appears* to be a lead. You can't get rid of delay really. Need more details / work on something like this because it's system dependent. I'm assuming that you're working in real time here. If not, then the first method works fine. Fred
Reply by ●April 8, 20052005-04-08
Peter, Thank you. In fact I am trying to write small programs (to help me better understand the effect of different processes on datas and also to help me remember algorithems). Its not a homework.> c) From the looks of the question you're saying: > > movingAverage[n] = sum_{k=n-M1}^{n+M2} x[k]Yes, correct. y[n] = (1/(M1+M2+1))(sum_{k=-M1}^{M2} x[n-k]) 2- Assume we have 100 samples for x[n] (0..99) If we have an ideal delay system (y[n]=x[n+2] or y[n]=x[n-2]) how we should calculate the output for y[0] (we do not have datas outside 0..99) ? 3- If I work on sound data then data is hardly periodic. And if I consider 0 for out of band datas my average will be affected at the start and end of y[n]. Thank you for your help again. Mac
Reply by ●April 8, 20052005-04-08
Thank you very much for your help.
I have x[n] for n:0..99 and M1=M2=5, so I can not calculate y[n]
because it needs x[-5] (and data is not periodic so that I can use
samples of another part of x[n])
By M1 and M2 I mean:
y[n] = (1/(M1+M2+1))(sum_{k=-M2}^{M1} x[n-k])
(M2-----n-----M1)
So I can calculate MAV for M1+1 length for y[0] and step by step take
backward part of the moving average into account?
I am sorry if my english is not perfect enough.
Regards,
Mac
Reply by ●April 8, 20052005-04-08
Fred,
Thank you for your help. I am just trying to write a simple program to
calculate the string y[n]=MAV{x[n]} with C or Matlab.
I have x[n] for n:0..99 and M1=M2=5, so I can not calculate y[n]
because it needs x[-5] (and data is not periodic so that I can use
samples of another part of x[n])
By M1 and M2 I mean:
y[n] = (1/(M1+M2+1))(sum_{k=-M2}^{M1} x[n-k])
(M2-----n-----M1)
I am sorry if my english is not perfect enough.
Regards,
Mac
Reply by ●April 8, 20052005-04-08
Mac wrote: ...> 3- If I work on sound data then data is hardly periodic. And if I > consider 0 for out of band datas my average will be affected at the > start and end of y[n].That's how it goes. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●April 8, 20052005-04-08
Mac wrote:> Thank you very much for your help. > > I have x[n] for n:0..99 and M1=M2=5, so I can not calculate y[n] > because it needs x[-5] (and data is not periodic so that I can use > samples of another part of x[n]) > > By M1 and M2 I mean: > > y[n] = (1/(M1+M2+1))(sum_{k=-M2}^{M1} x[n-k]) > > > (M2-----n-----M1) > > > So I can calculate MAV for M1+1 length for y[0] and step by step take > backward part of the moving average into account? > > I am sorry if my english is not perfect enough.Nobody is perfect. Try to believe that I'm stupid, and explain more. What are M1 and M2. What is the significance of both being 5? If M1 and M2 are ends of your sequence and you know both, why do you not know every element between? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●April 8, 20052005-04-08
"Jerry Avins" <jya@ieee.org> wrote in message news:BfidnU046tybR8vfRVn-jQ@rcn.net...> Mac wrote: > > ... > > > 3- If I work on sound data then data is hardly periodic. And if I > > consider 0 for out of band datas my average will be affected at the > > start and end of y[n]. > > That's how it goes.Right. Either truncate the beginning/end of your output sound data, or assume zeros and live with the transient.






