function [dFF_eventNREM,dFF_eventREM,dFF_eventWAKE,dFF_eventAll] = getFiringRateEvents(popRate,dFoverF,acc,sleepState,thresholds,time_window) %windowSize = 0.5; % Size of the sliding window %threshold = 0; % Frequency threshold % Calculate event frequencies using sliding window approach fs_dff = 100; N_dFF = length(dFoverF); %% durationPeakDiff = 10; [pka, locs_a, ~] = findpeaks(popRate,'minpeakheight',mean(popRate)+thresholds(1)*std(popRate),... 'WidthReference','halfprom','MinPeakDistance',durationPeakDiff*2); [pkb, locs_b, ~] = findpeaks(popRate,'minpeakheight',mean(popRate)+thresholds(2)*std(popRate),... 'WidthReference','halfprom','MinPeakDistance',durationPeakDiff*2); [locs,pks] = setdiff(locs_a,locs_b); eventTimes = locs; dFF_eventNREM = []; dFF_eventWAKE = []; dFF_eventREM = []; dFF_eventAll = []; for i = 1:length(eventTimes) idx = eventTimes(i); if (idx-sum(time_window)*fs_dff >0) && (idx+sum(time_window)*fs_dff