burst_checker.cpp
Go to the documentation of this file.
00001 /*
00002  * burst_checker.cpp
00003  * Copyright 2013 University of Massachusetts Lowell
00004  * Author: Jonathan Hasenzahl
00005  */
00006 
00007 #include "burst_calc/burst_checker.h"
00008 #include <cstdio>
00009 
00013 BurstChecker::BurstChecker()
00014 {
00015     frame_count_ = 0;
00016     spike_count_ = 0;
00017     is_bursting_ = false;
00018     is_possible_burst_ = false;
00019     end_of_burst_ = false;
00020 }
00021 
00029 void BurstChecker::init(int index, double baseline, double threshold,
00030                         int burst_window)
00031 {
00032     burst_.channels.push_back(index);
00033     index_ = index;
00034     baseline_ = baseline;
00035     threshold_ = threshold;
00036     burst_window_ = burst_window;
00037 }
00038 
00047 void BurstChecker::update(const neuro_recv::dish_state& d)
00048 {
00049     if (d.samples[index_] <= baseline_)
00050     {
00051         // Newest sample is not above baseline:
00052         // If a there is a possible burst, end it.
00053         if (is_possible_burst_)
00054         {
00055             if (is_bursting_)
00056             {
00057                 end_of_burst_ = true;
00058                 is_bursting_ = false;
00059             }
00060             is_possible_burst_ = false;
00061             frame_count_ = 0;
00062             spike_count_ = 0;
00063             // Clear the burst sequence if there was no actual burst
00064             if (!end_of_burst_)
00065                 burst_.dishes.clear();
00066         }
00067     }
00068     else if (d.samples[index_] <= threshold_)
00069     {
00070         // Newest sample is between baseline and threshold:
00071         // If there is a possible burst, increment frame count. If frame count
00072         // doesn't exceed the window, add the dish state to the sequence.
00073         // Otherwise, end the possible burst.
00074         if (is_possible_burst_)
00075         {
00076             if (++frame_count_ <= burst_window_)
00077             {
00078                 burst_.dishes.push_back(d);
00079                 burst_.end = d.header.stamp;
00080             }
00081             else
00082             {
00083                 if (is_bursting_)
00084                 {
00085                     end_of_burst_ = true;
00086                     is_bursting_ = false;
00087                 }
00088                 is_possible_burst_ = false;
00089                 frame_count_ = 0;
00090                 spike_count_ = 0;
00091                 // Clear the burst sequence if there was no actual burst
00092                 if (!end_of_burst_)
00093                     burst_.dishes.clear();
00094             }
00095         }
00096     }
00097     else
00098     {
00099         // Newest sample is a spike:
00100         // Add the spike state to the sequence and increment frame count and
00101         // spike count. If there was no possible burst before, there is now. If
00102         // this is the 3rd spike, a burst is occurring.
00103         frame_count_++;
00104         spike_count_++;
00105         if (!is_possible_burst_)
00106         {
00107             is_possible_burst_ = true;
00108             burst_.header.stamp = d.header.stamp;
00109         }
00110         if (spike_count_ == 3)
00111             is_bursting_ = true;
00112         burst_.dishes.push_back(d);
00113         burst_.end = d.header.stamp;
00114     }
00115 
00116     /*printf("State: %f Frames: %d Spikes: %d Possible: %s Burst: %s End: %s\n",
00117            d.samples[index_],
00118            frame_count_,
00119            spike_count_,
00120            is_possible_burst_ ? "Yes" : "No",
00121            is_bursting_ ? "Yes" : "No",
00122            end_of_burst_ ? "Yes" : "No");*/
00123 }
00124 
00131 void BurstChecker::reset()
00132 {
00133     end_of_burst_ = false;
00134     burst_.dishes.clear();
00135 }
00136 
00144 const ros::Time* BurstChecker::getTimePtr()
00145 {
00146     if (is_possible_burst_)
00147         return &burst_.header.stamp;
00148     else
00149         return NULL;
00150 }


burst_calc
Author(s): Jonathan Hasenzahl
autogenerated on Sun Jan 5 2014 11:12:30