Splitting an event channel into equal intervals

Discussions and questions about topics not covered above
hazelb
Posts: 6
Joined: 28 Apr 2020, 10:31
Contact:

Splitting an event channel into equal intervals

Unread postby hazelb » 28 Apr 2020, 12:54

Hello,
In Spike v7, I have a script which marks the peak and trough of a waveform into an event channel. I would like to split these equally into 5, as in have 5 intervals between each peak and trough in the event channel. Is it possible to do this in Spike?
Any help / advice would be greatly appreciated, thank you!

User avatar
Tim Bergel
Site Admin
Posts: 2381
Joined: 19 Jun 2008, 14:40
Location: Cambridge, England
Contact:

Re: Splitting an event channel into equal intervals

Unread postby Tim Bergel » 28 Apr 2020, 16:58

This shouldn't be too difficult. The script no doubt first creates a memory channel to hold the events using MemChan() and then fills it with events. You would need to add a second phase of processing where you work through the Peak/Trough events using NextTime(), and (for each peak/trough pair) then use MemSetItem() with an index% argument of zero to add the four extra events to split the peak/trough space into 5 intervals.

Do feel free to get back to me if you have problems with this.
Tim Bergel Cambridge Electronic Design

hazelb
Posts: 6
Joined: 28 Apr 2020, 10:31
Contact:

Re: Splitting an event channel into equal intervals

Unread postby hazelb » 29 Apr 2020, 08:15

Hi Tim,
That's excellent thank you. Does that mean the intervals between the peaks and troughs in will be determined by the time I put in? As the time between each peak and trough is different so ideally it will split the peak and trough into the intervals not based on time.
Thanks for your help!

User avatar
Tim Bergel
Site Admin
Posts: 2381
Joined: 19 Jun 2008, 14:40
Location: Cambridge, England
Contact:

Re: Splitting an event channel into equal intervals

Unread postby Tim Bergel » 29 Apr 2020, 09:19

Does that mean the intervals between the peaks and troughs in will be determined by the time I put in? As the time between each peak and trough is different so ideally it will split the peak and trough into the intervals not based on time

I'm not sure that I understand your question... The times of the new events will be set by your script, so you can use any method you want to calculate the times. I would assume that the calculation would take the overall interval for each peak/trough and divide it by four to get the times for the extra events.

I'm also not sure that I understand what you are aiming to do here. Are these extra events needed to define the times for your analysis? If that is the case, and your analysis is being carried out by a script, then the events are not really necessary - just divide up the peak/trough interval as required 'on the fly'.
Tim Bergel Cambridge Electronic Design

hazelb
Posts: 6
Joined: 28 Apr 2020, 10:31
Contact:

Re: Splitting an event channel into equal intervals

Unread postby hazelb » 29 Apr 2020, 09:56

The data is respiratory data so peaks = inspiration and troughs = expiration. My aim is to split each inspiration into 20% intervals and expiration into 20% intervals in an event channel so I can then use active cursors to follow each event when creating an XY plot. The main thing I hoped to do was to write into my script the adding of 4 markers in the channel that has the peaks and troughs in at equal intervals for splitting the inspiration or expiration into 20% intervals but the issue would be that each breath in/out will not be the same duration so I was hoping it was possible to add markers not based on time. I hope that makes more sense? It is something I can separate in excel but takes a lot longer than if I could write a script for it...
Thank you :)

User avatar
Tim Bergel
Site Admin
Posts: 2381
Joined: 19 Jun 2008, 14:40
Location: Cambridge, England
Contact:

Re: Splitting an event channel into equal intervals

Unread postby Tim Bergel » 30 Apr 2020, 14:41

The main thing I hoped to do was to write into my script the adding of 4 markers in the channel that has the peaks and troughs in at equal intervals for splitting the inspiration or expiration into 20% intervals but the issue would be that each breath in/out will not be the same duration so I was hoping it was possible to add markers not based on time

Well, the markers are added based on time, but those times can be anything you want. So the script code could find the start and end expiration times, and then add a marker at start + ((end-start)/5), another at at start + ((end-start)/5)*2, and so on.

But you don't need to do this! You can find the intermediate points directly using an active cursor search. Say you have set things up so that cursor 0 is at the event for the start time and cursor 1 has found the next event - the end time. Then you could set up cursor 2 to be active in expression mode, with the expression being "C0+((C1-C0)/5)", and repeat with cursors 3, 4 and 4 to get the other positions.
Tim Bergel Cambridge Electronic Design

hazelb
Posts: 6
Joined: 28 Apr 2020, 10:31
Contact:

Re: Splitting an event channel into equal intervals

Unread postby hazelb » 30 Apr 2020, 17:18

Oh excellent! Thank you very much! I originally tried it in active cursor mode but used data points instead of expression which is why I couldn't get it to work! Thank you for your help!


Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest