I have a matrix (DFF) that is 370x23, in this instance, that has my signal values from a video. The 370 is the number of frames, and the 23 is the number of ROIs I designated. I am trying to designate the significant signals based on 3 criteria:
- the signals start with a derivative that is 2.5*stdnoise i.e. is significant
- After this, the rest of the signal is greater than 2.5*sigma (noise) above mu (baseline) i.e. 2.5*sigma>mu
- if there is no signal after the derivative, it short circuits and the first criteria is not met
The derivative part usually ID's 1 or 2 cells, and then the rest of the signal is the cells that follow this. The problem is that I don't know how to combine these criteria so that the code identifies the first derivative and then applies the second criteria to only those cells that follow a significant first derivative.
I have code written for the first part, the derivative part and it works fine (note the output is a logical array called raster of the same size as DFF):
numcells = size(DFF,2);
emptyrow = zeros(1,numcells);
difDFF = [emptyrow;difDFF];
rasterSig = find(raster);
difDFFnoise = difDFF;
difDFFnoise(rasterSig) = NaN;
stdnoise = nanstd(difDFFnoise);
sigthresh = 2.5 .* stdnoise;
significantTransients = difDFF - sigthresh
significantTransients(significantTransients>0) = 1;
significantTransients(significantTransients<=0) = 0;
rasterNotSig = find(~raster);
significantTransients(rasterNotSig) = 0
But I can't figure out how to restrict applying the second criteria to only those signals that start with a significant first derivative. This is the code that would perform the function described in criteria 2, but not restricted:
signalthreshold=2.5 .* sigma;
So, is there any way to combine these two criteria and limit the second one to only those signals whose first derivative is significant, as defined in the first bit of code here? Also, I could take or leave the third criteria, because I think I could figure out how to write that once I know how to combine the first and second.
Please help, and thanks for your consideration.