"Jeff Chang" <pchang@chartermi.net> writes:
> I just know how to do the following case (4point averager), where the
> output just depend on the pass input.
> x = [1 3 2 4 5 4 3 2]
> y[n] = ( x[n] + x[n1] + x[n2] + x[n3] ) / (4)
>
> Solution [1]:
> y = filter( ones(1,4)/4, x )
Right.
> But I think the equation I provided was a bit different (correct me if I'm
> wrong). Do you think this equation y(n) = 1/(2w) * integral( v(n+s), s, w,
> w), has the following equivalent representation?
>
> For w = 3,
> y[n] = ( x[n+3] + x[n+2] + x[n+1] + x[n] + x[n1] + x[n2] + x[n3] ) /
> (2*3+1) ???
I still claim that if v is a vector, the integral of v(n) doesn't make
any sense. From a signal processing point of view, the closest
discrete version is probably what you have written. If you are really
trying to compute the integral of a continuous function using a
discrete approximation, you probably want something like a trapezoid
approximation. Assuming you just want the sliding average of a
vector, use the equation you typed above.
> If I were used the approach in solution [1], my output will be shifted a
> little bit, where the peaks and nulls of the signal will be shifted to the
> right.
Well, yes. The filter is noncausal, so you shift it so that it is
causal and you can use [1], then shift it back afterward. After you
do the filter, just say something like: ynew = y(w:end). Am I missing
something?
PB
>
> "Peter Boettcher" <boettcher@ll.mit.edu> wrote in message
> news:tr7kosmlzc.fsf@coyote.llan.ll.mit.edu...
>> "Jeff Chang" <pchang@chartermi.net> writes:
>>
>> > I have about 200 sample of data and I would like to do a sliding average
>> > that has the following equation:
>> >
>> > v(x) = 1/(2w) * integral( v(x+s), s, w, w)
>> >
>> > Let w=5, and my "v" is following. Any hint? Thanks
>> >
>> > v = [
>> > 19.3226
>> > 9.6244
>> > 12.9935
>> > [snip]
>>
>> Do you mean a summation? If v is discrete, an integral is tough.
>> Assuming you mean a sliding average something like y(x) = sum(v(x+k),
> k=0:5),
>> just use
>>
>> y = filter(ones(1,w)/w, 1, v)
>>
>> Does this give you what you're looking for?

Peter Boettcher <boettcher@ll.mit.edu>
MIT Lincoln Laboratory
MATLAB FAQ: http://www.mit.edu/~pwb/cssm/
