[SciPy-User] frequency components of a signal buried in a noisy time domain signal

Charles R Harris charlesr.harris at gmail.com
Sat Feb 27 14:59:18 EST 2010


On Sat, Feb 27, 2010 at 12:16 PM, <josef.pktd at gmail.com> wrote:

> On Sat, Feb 27, 2010 at 2:07 PM, Charles R Harris
> <charlesr.harris at gmail.com> wrote:
> >
> >
> > On Sat, Feb 27, 2010 at 12:03 PM, Ivo Maljevic <ivo.maljevic at gmail.com>
> > wrote:
> >>
> >> Another suggestion, and this one also makes the parallel to Matlab. Make
> >> sure it works for vectors:
> >>
> >> >>> a=np.array([7,11,250])
> >> >>> nextpow2(a)
> >> array([ 3.,  4.,  8.])
> >>
> >
> > In [27]: tab.searchsorted([7,11,250])
> > Out[27]: array([3, 4, 8])
> >
> > In [28]: np.frexp([7,11,250])[1]
> > Out[28]: array([3, 4, 8], dtype=int32)
>
> It looks like frexp is doubling the array if n is already an integer power
>
> >>> np.frexp(2**np.arange(5))
> (array([ 0.5,  0.5,  0.5,  0.5,  0.5]), array([1, 2, 3, 4, 5]))
> >>> np.arange(5)
> array([0, 1, 2, 3, 4])
> >>> np.ceil(np.log2(2**np.arange(5)))
> array([ 0.,  1.,  2.,  3.,  4.])
>
>
Sure enough ;) Looks like the mantissa need to be checked for .5.

In [22]: def nextpow2(x): m, e = np.frexp(np.abs(x)); return e - (m == .5)
   ....:

In [23]: nextpow2(.5)
Out[23]: -1

In [24]: nextpow2(.25)
Out[24]: -2

In [25]: nextpow2(1)
Out[25]: 0

In [26]: nextpow2(2)
Out[26]: 1

Which brings up the question: is nextpow2(.5) 0 or -1?

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100227/c2c6a936/attachment.html>


More information about the SciPy-User mailing list