Code Examples
A repository of 155 code examples for BeepBeep
DetectAppliance.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2018 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package nialm;
19 
20 import ca.uqac.lif.cep.Connector;
21 import ca.uqac.lif.cep.Processor;
22 import ca.uqac.lif.cep.Pullable;
23 import ca.uqac.lif.cep.functions.ApplyFunction;
24 import ca.uqac.lif.cep.signal.Limit;
25 import ca.uqac.lif.cep.signal.PeakFinderLocalMaximum;
26 import ca.uqac.lif.cep.signal.PlateauFinder;
27 import ca.uqac.lif.cep.signal.Threshold;
28 import ca.uqac.lif.cep.tmf.Fork;
29 import ca.uqac.lif.cep.util.Bags;
31 
32 public class DetectAppliance
33 {
34  public static void main(String[] args)
35  {
36  ///
37  Fork f = new Fork(2);
38  // First branch: peak detection
39  Processor peak_finder = new PeakFinderLocalMaximum(5);
40  Connector.connect(f, 0, peak_finder, 0);
41  // Threshold to avoid finding peaks due to noise
42  Threshold peak_th = new Threshold(100);
43  Connector.connect(peak_finder, peak_th);
44  // Dampen to avoid double peaks
45  Processor peak_damper = new Limit(10);
46  Connector.connect(peak_th, peak_damper);
47 
48  // Second branch: plateau detection
49  Processor plateau_finder = new PlateauFinder()
50  .setPlateauRange(5).setRelative(true);
51  Connector.connect(f, 1, plateau_finder, 0);
52  // Threshold to avoid finding plateaus due to noise
53  Threshold plateau_th = new Threshold(100);
54  Connector.connect(plateau_finder, plateau_th);
55  Processor plateau_damper = new Limit(10);
56  Connector.connect(plateau_th, plateau_damper);
57  ///
58 
59  //! Step 2: send to a Moore machine
61  new ApplianceMooreMachine(1000, 700, -700, 150);
62  Connector.connect(peak_damper, 0, amm, 0);
63  Connector.connect(plateau_damper, 0, amm, 1);
64 
65  // Connect input to a fake signal to see how it works
67  new Object[] {0, 333, -150, 0, -175, 0},
68  new Object[] {70, 3, 2, 100, 4, 60});
69  Connector.connect(signal, 1, f, 0);
70 
71  // Connect the output and print at the console
72  ApplyFunction to_list = new ApplyFunction(
73  new Bags.ToList(Number.class, Number.class));
74  Connector.connect(signal, 0, to_list, 0);
75  Connector.connect(amm, 0, to_list, 1);
76  //!
77 
78  // Pull events
79  Pullable p = to_list.getPullableOutput();
80  while (p.hasNext())
81  {
82  System.out.println(p.pull());
83  }
84  }
85 }
static void main(String[] args)
Basic usage of the signal processing processors.
Definition: FakeSignal.java:18