Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Re: Multiple application of LinearFilter

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64858] Re: [mg64850] Re: Multiple application of LinearFilter
  • From: "Lea Rebanks" <lrebanks at netvigator.com>
  • Date: Mon, 6 Mar 2006 05:00:59 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Many thanks Bill.

Very interesting. I will try that, however I feel I may run into problems.

Is it possible to email me your email address so I may respond directly
to you.

I have tried figuring out your cryptic email below with no success after
many tries. 

Speak soon.

Best Regards - Lea Rebanks...



-----Original Message-----
From: Bill Rowe [mailto:readnewsciv at earthlink.net] 
To: mathgroup at smc.vnet.net
Subject: [mg64858] [mg64850] Re: Multiple application of LinearFilter

On 3/4/06 at 2:35 AM, lrebanks at netvigator.com (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.

>EG

>originaldata

>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.,

In[13]:=
LinearFilter[{a,b,c,d},{1/2,1/2}]==ListConvolve[{1/2,1/2},{a,b,c,d}]

Out[13]=
True

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}

In[14]:=
ListConvolve[{1/2, 1/2}, 
   ListConvolve[{1/2, 1/2}, ListConvolve[{1/2, 1/2}, 
     {a, b, c, d, e, f}]]]//Simplify
     
Out[14]=
{(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

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

Out[15]=
{(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

In[18]:=
ListConvolve[{1/2, 1/2},  {a, b, c}, {1, 1}]

Out[18]=
{a/2 + c/2, a/2 + b/2, b/2 + c/2}

or if you wanted the equivalent of

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

you could do

ListConvolve[{1/2,1/2},{a,b,c},{1,1},0]
--
To reply via email subtract one hundred and four




  • Prev by Date: Re: Multiple application of LinearFilter
  • Next by Date: Re: General--Making the DisplayFormula style in ArticleModern look like Traditional
  • Previous by thread: Re: Multiple application of LinearFilter
  • Next by thread: Re: Re: Multiple application of LinearFilter