[SciPy-User] performant envelope follower

Benjamin Root ben.root@ou....
Fri Sep 17 10:11:47 CDT 2010


On Fri, Sep 17, 2010 at 8:44 AM, henry lindsay smith <
henrylindsaysmith@gmail.com> wrote:

> I have the following code backported from C envelope follower and converted
> into python code (using numpy arrays)
>
>         for i in range(len(self.m_signal)):
>
>             envIn=np.abs(self.m_signal[i]**2)#square for energy
>
>             if(self.envelope < envIn):
>
>                 self.envelope *= self.m_ga
>
>                 self.envelope +=(1-self.m_ga)*envIn
>
>             else:
>
>                 self.envelope *= self.m_gr
>
>                 self.envelope +=(1-self.m_gr)*envIn
>
>             self.sigEnv[i]=self.envelope
>
>
> it runs but slowly as I am iterating through the whole signal which is
> pretty slow in python (but super fast in C)
>
> Can anyone think of a more efficient way to run this possibly as as a
> filtering operation? I need the same result as I'm going to port back into C
> at somepoint.
>
> thanks
>
>
First, I would just go ahead and calculate envln outside the loop, that will
save you some time.

After that, it looks like you have a conditional accumulation operation
going on.  If it was just a conditional, I would suggest np.where(), or if
it was just an accumulation there is np.cumprod() and np.cumsum().  Even
then, one could just use 1's and 0's to do the correct operation within
cumprod() or cumsum().

However, you are doing both a product and a summation in the accumulator,
which is a little harder to figure out.  I am not sure where to go for that.

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20100917/6cd11603/attachment.html 


More information about the SciPy-User mailing list