00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "PeakRatio.h"
00020
00021 using std::cout;
00022 using std::endl;
00023
00024 using std::ostringstream;
00025
00026 using namespace Marsyas;
00027
00036 PeakRatio::PeakRatio(mrs_string name):MarSystem("PeakRatio", name)
00037 {
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 }
00048
00049 PeakRatio::PeakRatio(const PeakRatio& a) : MarSystem(a)
00050 {
00051
00052
00053
00054
00055 }
00056
00057 PeakRatio::~PeakRatio()
00058 {
00059 }
00060
00061 MarSystem*
00062 PeakRatio::clone() const
00063 {
00064 return new PeakRatio(*this);
00065 }
00066
00067 void
00068 PeakRatio::addControls()
00069 {
00070
00071
00072 }
00073
00074 void
00075 PeakRatio::myUpdate(MarControlPtr sender)
00076 {
00077 MarSystem::myUpdate(sender);
00078 mrs_string inObsNames = ctrl_inObsNames_->to<mrs_string>();
00079
00080 setControl("mrs_natural/onSamples", (mrs_natural)1);
00081 setControl("mrs_natural/onObservations", (mrs_natural)(ctrl_inObservations_->to<mrs_natural>()+2));
00082
00083
00084 mrs_string inObsName = stringSplit(ctrl_inObsNames_->to<mrs_string>(), ",")[0];
00085 inObsNames+="Average_" + inObsName + ",Minimum_" + inObsName + ",";
00086
00087
00088 ctrl_onObsNames_->setValue(obsNamesAddPrefix(inObsNames, "PeakRatio_"), NOUPDATE);
00089
00090 maxima_.stretch(inSamples_);
00091 minima_.stretch(inSamples_);
00092
00093 }
00094
00095
00096 void
00097 PeakRatio::myProcess(realvec& in, realvec& out)
00098 {
00099 mrs_natural t,o;
00100
00101
00102
00103 mrs_real max_ = -1.0 * DBL_MAX;
00104 mrs_real min_ = DBL_MAX;
00105 mrs_real avg_ = 0.0;
00106
00107
00108 for (t=0; t < inSamples_; t++)
00109 {
00110 for (o=0; o < inObservations_; o++)
00111 {
00112 out(o,t)=in(o,t);
00113
00114 if (in(o,t) > max_)
00115 {
00116 max_ = in(o,t);
00117 }
00118 if (in(o,t) < min_)
00119 {
00120 min_ = in(o,t);
00121 }
00122 avg_=avg_+in(o,t);
00123
00124 }
00125 avg_=avg_/(inSamples_*inObservations_);
00126 maxima_(t)=max_;
00127 minima_(t)=min_;
00128 }
00129 mrs_real res1=0.0;
00130 mrs_real res2=0.0;
00131
00132 for (t=0; t < inSamples_; t++)
00133 {
00134
00135 if(minima_(t)!=0.0) res1=maxima_(t)/minima_(t);
00136 if(minima_(t)!=0.0) res2=maxima_(t)/avg_;
00137
00138
00139 out(onObservations_-1,t)=res1;
00140 out(onObservations_-2,t)=res2;
00141 }
00142 }