How do I create a sliding window and/or bin that records the number of elements over a given time period

6 views (last 30 days)
I have neural data collected across 16 different channels (2d matrix = 756909 x 16). This data was recorded over a 30 second period (2d matrix 1 x 756909).
For each channel, I have calculated an amplitude threshold (2d matrix 1 x 16).
Over a 10s period (from 20 - 30s), I want to record the number of neural data points that are greater than or equal to the corresponding threshold for each channel. I would like to do this in windows (or bins) of 0.001s.
My code so far is still very deficient but looks like this:
t1 = 20; %start time, seconds
t2 = 30; %end time, seconds
time = tim_trl(tim_trl>=t1 & tim_trl<=t2); %10s window
for ii = 1:16
for jj = t1:0.001:size(time,2)
end
end
I would appreciate any help or advice.
  2 Comments
dpb
dpb on 25 Jul 2020
Is this fixed sample time and if so, what is the actual sampling rate?
IF the data are in fact collected over exactly 30 sec, we can compute what the sampling rate is but if the 30 sec is just an approximation of how long 756909 samples is as the sampling rate is 40 usec instead of 39.6349... usec, that's a different story.
Or, if it's just polled sampling and the the sampling rate is just about 40 usec, that's something different yet.
Need the groundrules strictly defined first, then it'll be straightforward to answer the questions wanted.
NA
NA on 25 Jul 2020
Edited: NA on 26 Jul 2020
Sorry, didn't include that bit of info. The neural data is collected over ~31s period to account for any delay during recordings. However, the sampling rate I am using is 24414 Hz, and I am only interested in 10s of data.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 25 Jul 2020
Edited: Matt J on 25 Jul 2020
t1 = 20; %start time, seconds
t2 = 30; %end time, seconds
win=tim_trl>=t1 & tim_trl<=t2;
time = tim_trl(win); %10s window
edges=time(1):0.001:time(end)+0.001;
bins=discretize(time,edges);
result=splitapply(@(z)sum(z,1), neuralData(win,:) >= thresholds ,findgroups(bins(:)))
  3 Comments
NA
NA on 31 Jul 2020
Edited: NA on 31 Jul 2020
Hi Matt,
I have had to rewrite my code using a for loop, and I have come up with the following:
t1 = 20; %start time, seconds
t2 = 30; %end time, seconds
ind1 = find(tim_trl>=t1, 1);
ind2 = find(tim_trl>=t2, 1);
time1 = tim_trl(ind1:ind2); %10 sec time frame
sampRate = 24414; %sampling freq (Hz), samples per sec
muaWindow = 0.001; %1ms window
binWidth = round(muaWindow*sampRate); %samples be 1ms
threshold = 0.018;
for jj = 1:16 %ch
abDataBin = data(kk:kk+binWidth-1,jj); %ab data in 1 bin %10 sec of data; matrix size 244141 x 16
for kk = 1:10000
%I am having trouble here
abDataBin = data(1:binWidth,jj); %data in 1 bin
dataThreshold = find(abDataBin >= threshold); %find data points >= threshold %1 >thres; 0 <thres
mua(kk,jj) = sum(dataThreshold); %number of data over threshold per ch
end
end
So far, I'm just having a bit of trouble at this point:
abDataBin = data(kk:kk+binWidth-1,jj); %ab data in 1 bin
When I run the loop, the data in bin 1 gets overwritten, rather than shift to bin 2, 3...10000. Do you have any ideas on how to fix this?
Many thanks.

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!