Falcon
Loading...
Searching...
No Matches
burstdetector.hpp
1// ---------------------------------------------------------------------
2// This file is part of falcon-core.
3//
4// Copyright (C) 2015, 2016, 2017 Neuro-Electronics Research Flanders
5//
6// Falcon-server is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Falcon-server is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with falcon-core. If not, see <http://www.gnu.org/licenses/>.
18// ---------------------------------------------------------------------
19
20#pragma once
21
22#include <memory>
23#include <string>
24
25#include "dsp/algorithms.hpp"
26#include "eventdata/eventdata.hpp"
27#include "iprocessor.hpp"
28#include "muadata/muadata.hpp"
29#include "timeseriesdata/timeseriesdata.hpp"
30
31class BurstDetector : public IProcessor {
32 // CONSTRUCTOR and OVERLOADED METHODS
33 public:
34 BurstDetector();
35 void CreatePorts() override;
36 void CompleteStreamInfo() override;
37 void Preprocess(ProcessingContext& context) override;
38 void Process(ProcessingContext& context) override;
39 void Postprocess(ProcessingContext& context) override;
40
41 // PORTS
42 protected:
43 PortIn<MUAType>* data_in_port_;
44 PortOut<EventType>* data_out_port_;
45 PortOut<TimeSeriesType<double>>* stats_out_port_;
46
47 // STATES
48 protected:
49 BroadcasterState<double>* threshold_;
50 BroadcasterState<double>* signal_mean_;
51 BroadcasterState<double>* signal_dev_;
52 BroadcasterState<bool>* burst_;
53 FollowerState<double>* bin_size_mua_;
54
55 StaticState<double>* threshold_dev_;
56 StaticState<double>* smooth_time_;
57 StaticState<double>* detection_lockout_time_;
58 StaticState<bool>* stream_events_;
59 StaticState<bool>* stats_out_;
60
61 bool stats_out_enabled_;
62 std::uint64_t stats_nsamples_;
63
64 std::uint64_t block_;
65 std::uint64_t burn_in_;
66 double sample_rate_;
67
68 double acc_;
69
70 std::unique_ptr<dsp::algorithms::RunningMeanMAD> running_statistics_;
71 std::unique_ptr<dsp::algorithms::ThresholdCrosser> threshold_detector_;
72
73 public:
74 // configure options names ( keep common between options and states )
75 const std::string THRESHOLD_DEV = "threshold_dev";
76 const std::string SMOOTH_TIME = "smooth_time";
77 const std::string DETECTION_LOCKOUT_TIME = "detection_lockout_time";
78 const std::string STREAM_EVENTS = "stream_events";
79 const std::string STREAM_STATISTICS = "stream_statistics";
80
81 protected:
82 const unsigned int N_STATS_OUT = 2;
83
84 // OPTIONS
85 protected:
86 options::Double initial_threshold_dev_{6.};
87 options::Measurement<double, false> initial_smooth_time_{10., "second",
88 options::positive<double>(true)};
89 options::Measurement<double, false> initial_detection_lockout_time_{
90 30., "ms", options::positive<double>(true)};
91 options::Bool default_stream_events_{true};
92 options::Bool initial_stats_out_{true};
93 options::Measurement<double, false> stats_buffer_size_{0.5, "second",
94 options::positive<double>(true)};
95};
Definition streamports.hpp:256
Definition streamports.hpp:98
Definition runinfo.hpp:248