0

I have a list of an evenly sampled signal. For the sake of discussion, assume that the array can be obtained by the following python code

fs =2
np.arange(start=0, stop=360, step=fs)

In my perspective, the above code would correspond to a 90-second long signal. I would like to analyze small chunks of the last 10 seconds of the signal as follow:

 1. Iteration #1: array from the beginning to the end
 2. Iteration #2: array from the beginning to the (end -1 second) 
 3. Iteration #3: array from the beginning to the (end -2 seconds) 
 4. Iteration #4: array from the beginning to the (end -3 seconds) 
 5. Iteration #4: array from the beginning to the (end -3 seconds) 
    etc.... 
 5. Iteration #10: array from the beginning to the (end -10 second) 

There are some convoluted ways I could maybe achieve this by using for loops and counters but I feel like this is overkill as I suspect this could be achieved by some simple array indexing methods as suggested by this StackOverflow question. Can someone point me in the right direction to get this done with an elegant code?

Community
  • 1
  • 1
Dillion Ecmark
  • 704
  • 3
  • 10
  • 23
  • 1
    Seems like you want a regular for loop and `lst[:-i]` – OneCricketeer Nov 09 '16 at 10:04
  • 1
    There'll be a `np.indextricks.as_strided` to this problem – Eric Nov 09 '16 at 10:07
  • 1
    Using a stride of `1`, you can use - http://stackoverflow.com/questions/40084931. Also relevant - http://stackoverflow.com/questions/40345461 – Divakar Nov 09 '16 at 10:14
  • @cricket_007, your method seems the simplest. I am just yet to figure out how to calculate the index i for `lst[:-i]` – Dillion Ecmark Nov 09 '16 at 11:52
  • Start with `for i in range(10)` to see if it does what you want – OneCricketeer Nov 09 '16 at 14:31
  • One issue is identifying the chunks, the other is what do you want to do with them? If the chunks are all the same length they can be stacked into a 2d array. But if they differ in length (beginning to different ends), they probably have to handled individually. Ragged arrays don't stack. – hpaulj Nov 09 '16 at 19:03

0 Answers0