function events=mini_waveform_extractor(raw_trace,criterion_trace,criterion_threshold,event_jitter,event_window,baseline_offset_window1,baseline_offset_window2,... fit_slope_thresh,plot_sloperemovedextractions) %description: Works on a single trial at a time, extracting each raw waveform beginning at the point when the criterion trace exceeds a threshold. %Measures and, if above another threshold, removes underlying slope (e.g., if the event is riding on decaying phasic PSC). Uses the criterion matrix %previously established by template_based_mini_detector and spontaneous_event_finder. %called by: cluster_asynch_based_on_phasic, temporary_asynch_analyzer(deprecated), analyze_waveforms_clusters_mixtures_using_database(deprecated) %calls: find_peaks_within_threshold_crossing_regions, exp_decay %notes: the raw_trace is longer than the criterion_trace by enough to ensure that any event detected in the criterion trace can be fully % (as determined by event_window) extracted from the raw trace %code confirm date: sep 19, 2009 events=[]; event_peaks=find_peaks_within_threshold_crossing_regions(criterion_threshold,event_jitter,criterion_trace); for present_peak=1:length(event_peaks) event=raw_trace(event_peaks(present_peak)-event_window(1)+event_window)'; if ~isempty(baseline_offset_window1) || ~isempty(baseline_offset_window2) lin=polyfit([baseline_offset_window1 baseline_offset_window2],event([baseline_offset_window1 baseline_offset_window2]),1);%first need linear fit to check the slope if lin(1)