I would like help setting up my code

Hi,
I have an array (31003x1), made up of -1’s, 0’s, and 1’s, that represents neural data. The data was down-sampled from 24.414 KHz to 1 KHz.
I want to see how many times UP initiation takes place.
UP initiation is defined as:
A suppressed state (0), followed by a transition period (random 0’s, +1’s, and -1’s), and then an UP (+1) state. The suppressed state needs to last 90 ms (or 90 data points); the transition period should last 10 ms (or 10 data points); and the UP state needs to last 100 ms (or 100 data points).
OR [defined as]
A DOWN state (-1), followed by a transition period, and then an UP state (+1). Like above, the DOWN state needs to last 90 ms, the transition 10 ms, and the UP state 100 ms.
For the same array, I want to also see how many times UP termination takes place.
UP termination is defined as:
An UP state (+1), followed by a transition phase, and then a suppressed state (-1). The UP state needs to last 100 ms; the transition period 20 ms; and the suppressed state 80 ms.
OR
An UP state (+1), that is followed by a period of transition, and then a DOWN state (-1). Similarly, the UP state needs to last 100 ms; the transition period 20 ms; and the DOWN state 80 ms.
I’m having trouble getting started with this, and would any appreciate your help or guidance.
Thank you.

5 commentaires

Jan
Jan le 2 Nov 2022
Convert the definitions to an abstract representation, which can be expressed as Matlab code.
"An UP state (+1), followed by a transition phase, and then a suppressed state (-1). The UP state needs to last 100 ms; the transition period 20 ms; and the suppressed state 80 ms."
This is less useful for the readers. Convert this as far as possible to expressions about elements of a vector. How man elements must have which value?
What does the "OR" parts of the definitions mean? Are their two different definitions or does the definition contain an Either/Or part?
"The data was down-sampled from 24.414 KHz to 1 KHz" - does this detail matter?
Hi Jan,
Thanks for getting back to me.
"An UP state (+1), followed by a transition phase, and then a suppressed state (-1). The UP state needs to last 100 ms; the transition period 20 ms; and the suppressed state 80 ms."
For this statement (UP termination), I have created the below expressions:
%UP termination templates
U=ones(100,1); %up state
trans=20; %transition is 20 data points
S=zeros(80,1); %suppressed state
I am not sure how to use these templates to run them through the array, and count the number of times UP termination takes place. I tried the following:
%con is the array (31003x1), made up of -1's, 0's, and 1's.
isequal(con,[U; con+trans; S]);
I know it's wrong. Can you please give me more pointers.
Thanks
Please post one or some relevant examples of how an "UP state" looks like.
Are you searching for subvectors with this value: [ones(100, 1); zeros(80, 1)]? Then:
strfind(con.', [ones(100, 1); zeros(80, 1)].')
strfind replies the indices of the matching subvectors. It operates on double vectors also inspite of its name. It needs row vectors as input.
NA
NA le 3 Nov 2022
Hi Jan, thanks for getting back to me.
An UP state is: [ones(100, 1); TRANSITION; zeros(80, 1)];
The TRANSITION period is a segment of 20 datapoints that I would like to overlook because it is made up of random 0's, 1's and -1's.
Is there a way of searching through con accounting for this transition period?
Many thanks
Then the states cannot be uniquely identified. See this example with a shorter pattern
UP = [1,1,1,x,x,x,x,0,0,0] % Pattern: 3*1, 4 transitions, 3*0
signal = [1,1,1,1,0,0,0,0,0,0]
UP 1: ^ ^ ^ x x x ^ ^ ^
UP 2: ^ ^ ^ x x x ^ ^ ^
Which one should be chosen?

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 3 Nov 2022
up1 = strfind(con.', ones(1, 100));
up2 = strfind(con.', zeros(1, 80));
up = intersect(up1, up2 - 21);
Cleanup detections with a too short distance:
upc = zeros(size(up));
t = -Inf;
c = 0;
for k = 1:numel(up)
if up(k) - t > 201
c = c + 1;
upc(c) = up(k);
end
end
up = upc(1:c);
There might be a nicer version.

Catégories

Question posée :

NA
le 2 Nov 2022

Réponse apportée :

Jan
le 3 Nov 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by