OnlineAverager.cpp

Go to the documentation of this file.
00001 #include "OnlineAverager.h"
00002 
00003 OnlineAverager::OnlineAverager()
00004         : n_input_ports()
00005 {}
00006 
00007 OnlineAverager::OnlineAverager(unsigned numInputPorts) :
00008         n_input_ports(numInputPorts)
00009 {}
00010 
00011 
00012 OnlineAverager::~OnlineAverager()
00013 {}
00014 
00015 int OnlineAverager::nAnalogInputPorts() const
00016 {
00017     return n_input_ports;
00018 }
00019 
00020 int OnlineAverager::nAnalogOutputPorts() const
00021 {
00022     return 2;
00023 }
00024 
00025 
00026 SimObject::PortType OnlineAverager::outputPortType(port_t p) const
00027 {
00028     if (p < 2)
00029         return analog;
00030     else
00031         return undefined;
00032 }
00033 
00034 SimObject::PortType OnlineAverager::inputPortType(port_t p) const
00035 {
00036     if (p < n_input_ports)
00037         return analog;
00038     else
00039         return undefined;
00040 }
00041 
00042 int OnlineAverager::reset( double dt )
00043 {
00044     sum = 0;
00045     sum2 = 0;
00046     mean = 0;
00047     std = 0;
00048     return 0;
00049 }
00050 
00051 int OnlineAverager::advance( AdvanceInfo const& ai)
00052 {
00053     mean = sum/n_input_ports;
00054     std = sqrt(sum2/n_input_ports - mean * mean);
00055     sum = 0;
00056     sum2 = 0;
00057     return 0;
00058 }
00059 
00060 double OnlineAverager::getAnalogOutput(analog_port_id_t port) const
00061 {
00062     if (port == 0)
00063         return mean;
00064     else
00065         if (port == 1)
00066             return std;
00067     return 0;
00068 }
00069 
00070 void OnlineAverager::setAnalogInput(double value, analog_port_id_t port)
00071 {       
00072     sum = sum + value;
00073     sum2 = sum2 + value * value;
00074 }

Generated on Wed Jul 9 16:34:39 2008 for PCSIM by  doxygen 1.5.5