So I have this array which contains the waveform of the stimulus used. We played to the rat a ping sound which lasts for 100 ms and occurs every 750 ms. Unfortunately, the machine in this particular protocol did not save an events file so I need to figure out the stimulus onset times myself.
The problem is that it is not a homogeneous stimulation pattern. First we turned the stimulus on for sometime, then shut it off to adjust something, and then played it for a while and then we turned it off again to adjust something and then turned it on till the end. Attached is a figure that shows the pattern.
I tried doing this to get the stimulus onset times -
avg_stim_form = mean(stimulus_waveform);
std_stim_form = std(stimulus_waveform);
norm_stimulus = stimulus_waveform - avg_stim_form;
ratio = round(norm_stimulus./std_stim_form);
stim_form = zeros(1,length(stimulus_waveform));
stim_form(ratio>0.5) = 1;
stim_start = find(stim_form==1, 1 );
stim_form = stim_form(stim_start:end);
d = diff(stim_form);
stimtimes = find(d==1);
This didn't work out because the threshold is too high. In the waveform of the ping, there are many 0 crossings, so howmuchever I lower the threshold for detection, I will still get false positives. I'd be grateful if someone could help me out.