MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Multiple application of LinearFilter

On 3/4/06 at 2:35 AM, lrebanks at (Lea Rebanks) wrote:

>I have been using LinearFilter on my data with great success &
>achieve better results the more times I pass my data through the
>LinearFilter. ( I have had to adjust data length to maintain
>correct indexing with PadLeft - but this is not my question here.)

>Below is how I am applying the multiple LinearFilter.



>Data1=LinearFilter[originaldata, {1/2,1/2}];
>Data2=LinearFilter[Data1, {1/2,1/2}]; 
>Data3=LinearFilter[Data2, {1/2,1/2}];

>My question is - Is there a shorter way of writing multiple passes
>of the above.

Yes. But rather than using LinearFilter, I think the built-in function ListConvolve is more efficient and flexible. For your specific application, ListConvolve differs from LinearFilter only in the order of the arguments, i.e.,



Repeated passes with a given kernel are equivalent to a single pass with a longer kernel. That is 3 passes with the kernel (1/2,1/2) give the same result as a single pass with the kernel {1/8,3/8,3/8,1/8}

Here is three passes using ListConvolve and the kernel {1/2,1/2}

ListConvolve[{1/2, 1/2}, 
   ListConvolve[{1/2, 1/2}, ListConvolve[{1/2, 1/2}, 
     {a, b, c, d, e, f}]]]//Simplify
{(1/8)*(a + 3*b + 3*c + d), (1/8)*(b + 3*c + 3*d + e), 
  (1/8)*(c + 3*d + 3*e + f)}

and here is the result using a single pass

ListConvolve[{1/8, 3/8, 3/8, 1/8}, {a, b, c, d, e, f}]//Simplify

{(1/8)*(a + 3*b + 3*c + d), (1/8)*(b + 3*c + 3*d + e), 
  (1/8)*(c + 3*d + 3*e + f)}

As you can see the results are the same.

The real advantage of ListConvolve over LinearFilter is the additional flexibility ListConvolve gives, For example, to get an output the same length as the input you can do

ListConvolve[{1/2, 1/2},  {a, b, c}, {1, 1}]

{a/2 + c/2, a/2 + b/2, b/2 + c/2}

or if you wanted the equivalent of


you could do

To reply via email subtract one hundred and four

  • Prev by Date: Re: Multiple application of LinearFilter
  • Next by Date: Re: Possible Bug in ArcTan ?
  • Previous by thread: Re: Multiple application of LinearFilter
  • Next by thread: Re: Multiple application of LinearFilter