Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/DeltaFirstOrderRegression.cpp
Go to the documentation of this file.
00001 /*
00002  ** Copyright (C) 2010 Stefaan Lippens
00003  **
00004  ** This program is free software; you can redistribute it and/or modify
00005  ** it under the terms of the GNU General Public License as published by
00006  ** the Free Software Foundation; either version 2 of the License, or
00007  ** (at your option) any later version.
00008  **
00009  ** This program is distributed in the hope that it will be useful,
00010  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  ** GNU General Public License for more details.
00013  **
00014  ** You should have received a copy of the GNU General Public License
00015  ** along with this program; if not, write to the Free Software
00016  ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include "DeltaFirstOrderRegression.h"
00020 
00021 using namespace std;
00022 using namespace Marsyas;
00023 
00024 DeltaFirstOrderRegression::DeltaFirstOrderRegression(mrs_string name) :
00025   MarSystem("DeltaFirstOrderRegression", name)
00026 {
00028   addControls();
00029 }
00030 
00031 DeltaFirstOrderRegression::DeltaFirstOrderRegression(
00032   const DeltaFirstOrderRegression& a) :
00033   MarSystem(a)
00034 {
00035 }
00036 
00037 DeltaFirstOrderRegression::~DeltaFirstOrderRegression()
00038 {
00039 }
00040 
00041 MarSystem*
00042 DeltaFirstOrderRegression::clone() const
00043 {
00044   return new DeltaFirstOrderRegression(*this);
00045 }
00046 
00047 void DeltaFirstOrderRegression::addControls()
00048 {
00049 }
00050 
00051 void DeltaFirstOrderRegression::myUpdate(MarControlPtr sender)
00052 {
00054   MarSystem::myUpdate(sender);
00055   // prefix obsnames with "DeltaR1"
00056   mrs_string inObsNames = ctrl_inObsNames_->to<mrs_string> ();
00057   mrs_string onObsNames = obsNamesAddPrefix(inObsNames, "DeltaR1_");
00058   ctrl_onObsNames_->setValue(onObsNames, NOUPDATE);
00059 
00060   // Allocate and initialize the buffers.
00061   this->memory_.stretch(inObservations_, 2);
00062   this->memory_.setval(0.0);
00063 }
00064 
00065 void DeltaFirstOrderRegression::myProcess(realvec& in, realvec& out)
00066 {
00068   for (mrs_natural o = 0; o < inObservations_; o++)
00069   {
00070     // Calculate delta.
00071     out(o, 0) = 0.5 * (in(o, 0) - memory_(o, 0));
00072     if (inSamples_ > 1)
00073     {
00074       out(o, 1) = 0.5 * (in(o, 1) - memory_(o, 1));
00075       for (mrs_natural t = 2; t < inSamples_; t++)
00076       {
00077         out(o, t) = 0.5 * (in(o, t) - in(o, t - 2));
00078       }
00079     }
00080     // Update memory
00081     memory_(o, 0) = (inSamples_ >= 2 ? in(o, inSamples_ - 2)
00082                      : memory_(o, 1));
00083     memory_(o, 1) = in(o, inSamples_ - 1);
00084   }
00085 }