function [dFF_event_mean,rippbandpower] = GetRate(eventTimes,dFoverF,lfpData,windowSize,threshold_,time_window,CNOTimes) %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); eventFrequencies = zeros(1, numel(eventTimes)); for i = 1:numel(eventTimes) startTime = eventTimes(i) - windowSize/2 ; endTime = eventTimes(i) + windowSize/2; if startTimeCNOTimes() eventFrequencies(i) = sum(eventTimes >= startTime & eventTimes <= endTime); end [eventTimesUnique,idx] = uniquetol(eventTimes,windowSize,'DataScale',1); [eventTimesUnique_r,idx_r] = uniquetol(eventTimes,windowSize,'highest','DataScale',1); eventFrequencies_ = eventFrequencies(idx); % Find time point(s) where frequency exceeds threshold aboveThresholdIndices = (eventFrequencies_ == threshold_); eventTimesUnique = 0.5*(eventTimesUnique + eventTimesUnique_r); timeId = eventTimesUnique(aboveThresholdIndices); dFF_event_mean = []; for i = 1:length(timeId) idx = round((timeId(i))*fs_dff); if (idx-time_window*fs_dff >0) && (idx+time_window*fs_dff0 && ((t_idx+time_window)*fs_rp)