lambda - Computing the energy of a signal over 30 second periods in Python -


i'm new both python , signal processing, pardon possible misuse of jargon.

i have discrete values of signal in pandas dataframe x, spaced 1 second apart. looks this:

2017-08-02 16:42:00  0.363657 2017-08-02 16:42:01  0.282907 2017-08-02 16:42:02  0.155929 ... 2017-08-02 16:43:14  0.178522 2017-08-02 16:43:15  0.488507 2017-08-02 16:43:16  0.194987 ... 

i compute energy of signal on 30 second periods (by energy mean sum of squares of discrete fourier coefficients, normalized number of summands). output of form

2017-08-02 16:42:00  x_1 2017-08-02 16:42:30  x_2 2017-08-02 16:43:00  x_3 ... 

where each x_i scalar corresponding energy 30s period. i'm fine getting numpy array, need energy values , not time stamps.

i tried doing this:

energy = x.resample('30s').apply(lambda x: (numpy.absolute(numpy.fft.fft(x))**2)/30) 

however, of form

2017-08-02 16:42:00    [[0.422450491863], [0.482244793857], [0.514463... 2017-08-02 16:42:30    [[0.345172558059], [0.554558388074], [0.461898... 2017-08-02 16:43:00    [[0.689816890284], [0.613620822242], [0.389962... 

what did wrong, , how best correct it?

thanks!

edit: changed time bit needed copy small portion of output, don't mind values themselves.

**edit 2: code appears written here, namely:

x = 2017-08-02 16:42:00  0.363657     2017-08-02 16:42:01  0.282907     2017-08-02 16:42:02  0.155929     ...     2017-08-02 16:43:14  0.178522     2017-08-02 16:43:15  0.488507     2017-08-02 16:43:16  0.194987     ... #this imported dataframe, , indeed shows type pandas.core.frame.dataframe.  energy = x.resample('30s').apply(lambda x: (numpy.absolute(numpy.fft.fft(x))**2)/30)  out: energy = 2017-08-02 16:42:00    [[0.422450491863], [0.482244793857], [0.514463... 2017-08-02 16:42:30    [[0.345172558059], [0.554558388074], [0.461898... 2017-08-02 16:43:00    [[0.689816890284], [0.613620822242], [0.389962... ... #type(energy) = object 

import scipy sp  # create input of real sine wave fs = 1.0 fc = 0.25 n = sp.arange(0, 300) x = sp.cos(2*sp.pi*n*fc/fs)  # rearrange x 10 30 second windows x = sp.reshape(x, (-1, 30))  # calculate power on each window [j/s] p = sp.sum(x*x, 1)/x.size  # calculate energy [j = j/s * 30 second] e = p*x.size 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -