00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "PvMultiResolution.h"
00020
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023
00024 PvMultiResolution::PvMultiResolution(mrs_string name):MarSystem("PvMultiResolution", name)
00025 {
00026 flux_ = new Flux("flux");
00027 r_ = 0.1;
00028 m_ = 0.75;
00029
00030 addControls();
00031 }
00032
00033 PvMultiResolution::PvMultiResolution(const PvMultiResolution& a) : MarSystem(a)
00034 {
00035 ctrl_mode_ = getctrl("mrs_string/mode");
00036 ctrl_transient_ = getctrl("mrs_bool/transient");
00037 ctrl_shortmag_ = getctrl("mrs_realvec/shortmag");
00038 ctrl_longmag_ = getctrl("mrs_realvec/longmag");
00039
00040 r_ = 0.1;
00041 m_ = 0.75;
00042 flux_ = new Flux("flux");
00043 }
00044
00045
00046 PvMultiResolution::~PvMultiResolution()
00047 {
00048 delete flux_;
00049 }
00050
00051 MarSystem*
00052 PvMultiResolution::clone() const
00053 {
00054 return new PvMultiResolution(*this);
00055 }
00056
00057 void
00058 PvMultiResolution::addControls()
00059 {
00060
00061 addctrl("mrs_string/mode", "long", ctrl_mode_);
00062 addctrl("mrs_bool/transient", false, ctrl_transient_);
00063 addctrl("mrs_realvec/shortmag", realvec(), ctrl_shortmag_);
00064 addctrl("mrs_realvec/longmag", realvec(), ctrl_longmag_);
00065 addctrl("mrs_real/flux", 0.0);
00066 }
00067
00068 void
00069 PvMultiResolution::myUpdate(MarControlPtr sender)
00070 {
00071 MRSDIAG("PvMultiResolution.cpp - PvMultiResolution:myUpdate");
00072
00073 (void) sender;
00074 ctrl_onSamples_->setValue(ctrl_inSamples_, NOUPDATE);
00075 ctrl_onObservations_->setValue(ctrl_inObservations_->to<mrs_natural>() / 2, NOUPDATE);
00076 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE);
00077
00078 median_buffer_.create(10);
00079 mbindex_ = 0;
00080
00081
00082 powerSpectrum_.create(onObservations_/2,1);
00083 whiteSpectrum_.create(onObservations_/2,1);
00084
00085 {
00086 MarControlAccessor acc(ctrl_shortmag_);
00087 mrs_realvec& shortmag = acc.to<mrs_realvec>();
00088 shortmag.create(onObservations_/2);
00089 }
00090
00091 {
00092 MarControlAccessor acc(ctrl_longmag_);
00093 mrs_realvec& longmag = acc.to<mrs_realvec>();
00094 longmag.create(onObservations_/2);
00095 }
00096
00097
00098 flux_->updControl("mrs_natural/inSamples", 1);
00099 flux_->updControl("mrs_natural/inObservations", onObservations_/2);
00100 flux_->updControl("mrs_real/israte", 44100);
00101 flux_->updControl("mrs_string/mode", "DixonDAFX06");
00102 fluxval_.create(1,1);
00103
00104 }
00105
00106 void
00107 PvMultiResolution::myProcess(realvec& in, realvec& out)
00108 {
00109 mrs_natural t,o;
00110 const mrs_string& mode = ctrl_mode_->to<mrs_string>();
00111
00112
00113 MarControlAccessor acc1(ctrl_shortmag_);
00114 mrs_realvec& shortmag = acc1.to<mrs_realvec>();
00115
00116 MarControlAccessor acc2(ctrl_longmag_);
00117 mrs_realvec& longmag = acc2.to<mrs_realvec>();
00118
00119
00120
00121
00122 if (mode == "short")
00123 {
00124
00125 for (o=0; o < inObservations_/2; o++)
00126 for (t = 0; t < inSamples_; t++)
00127 {
00128 out(o,t) = in(o, t);
00129 }
00130 for (o=0; o < onObservations_/2; o++)
00131 for (t = 0; t < inSamples_; t++)
00132 {
00133
00134 out(2*o, t) = 0.75 * out(2*o,t);
00135 }
00136
00137
00138 }
00139 else if (mode == "long")
00140 {
00141
00142
00143 for (o=inObservations_/2; o < inObservations_; o++)
00144 for (t = 0; t < inSamples_; t++)
00145 {
00146 out(o-inObservations_/2,t) = in(o,t);
00147 }
00148
00149 for (o=0; o < onObservations_/2; o++)
00150 for (t = 0; t < inSamples_; t++)
00151 {
00152 out(2*o, t) = out(2*o,t);
00153 }
00154 }
00155 else if (mode == "shortlong_mixture")
00156 {
00157
00158
00159 for (o=0; o < inObservations_/2; o++)
00160 for (t = 0; t < inSamples_; t++)
00161 {
00162 out(o,t) = in(o, t);
00163 }
00164
00165
00166
00167 for (o=inObservations_/2; o < inObservations_/2 + 200; o++)
00168 for (t = 0; t < inSamples_; t++)
00169 {
00170 out(o-inObservations_/2,t) = in(o,t);
00171 }
00172
00173 for (o=0; o < 200; o++)
00174 for (t = 0; t < inSamples_; t++)
00175 {
00176 out(2*o, t) = 2 * out(2*o,t);
00177 }
00178 }
00179
00180 else if (mode == "transient_switch")
00181 {
00182
00183
00184 for (o=0; o < inObservations_/2; o++)
00185 for (t = 0; t < inSamples_; t++)
00186 {
00187 out(o,t) = in(o, t);
00188 }
00189
00190
00191
00192 for (o=0; o < onObservations_/2; o++)
00193 for (t = 0; t < inSamples_; t++)
00194 {
00195 powerSpectrum_(o,0) = out(2*o,t) * out(2*o,t);
00196 }
00197
00198
00199
00200 for (o=0; o < onObservations_/2; o++)
00201 {
00202
00203 if (powerSpectrum_(o,0) < r_)
00204 whiteSpectrum_(o,0) = r_;
00205 else
00206 {
00207 if (m_ * whiteSpectrum_(o,0) > powerSpectrum_(o,0))
00208 whiteSpectrum_(o,0) = m_ * whiteSpectrum_(o,0);
00209 else
00210 whiteSpectrum_(o,0) = powerSpectrum_(o,0);
00211 }
00212 powerSpectrum_(o,0) = powerSpectrum_(o,0) / whiteSpectrum_(o,0);
00213 }
00214
00215
00216
00217 flux_->process(powerSpectrum_, fluxval_);
00218
00219 median_buffer_(mbindex_) = fluxval_(0,0);
00220 mbindex_++;
00221 if (mbindex_ == 10)
00222 {
00223 mbindex_ = 0;
00224 }
00225
00226
00227 updControl("mrs_real/flux", fluxval_(0,0) - median_buffer_.median());
00228
00229 mrs_real longSum = 0.0;
00230 mrs_real shortSum = 0.0;
00231
00232 mrs_real ratio1;
00233 mrs_real ratio2;
00234
00235
00236
00237 for (o=0; o < onObservations_/2; o++)
00238 for (t = 0; t < inSamples_; t++)
00239 {
00240 shortmag(o) = in(2*o,t);
00241 longmag(o) = in(2*o + inObservations_/2, t);
00242 shortSum += shortmag(o);
00243 longSum += longmag(o);
00244 }
00245
00246
00247 ratio1 = longSum / shortSum;
00248 ratio2 = shortSum / longSum;
00249
00250
00251 for (o=0; o < onObservations_/2; o++)
00252 for (t = 0; t < inSamples_; t++)
00253 {
00254 shortmag(o) = ratio1 * shortmag(o);
00255 }
00256
00257
00258
00259
00260
00261
00262 if (fluxval_(0,0) - median_buffer_.median() <= 0.0000010)
00263 {
00264
00265
00266 for (o=inObservations_/2; o < inObservations_; o++)
00267 for (t = 0; t < inSamples_; t++)
00268 {
00269 out(o-inObservations_/2,t) = in(o,t);
00270 }
00271
00272 for (o=0; o < onObservations_/2; o++)
00273 for (t = 0; t < inSamples_; t++)
00274 {
00275 out(2*o, t) = out(2*o,t);
00276 }
00277
00278 ctrl_transient_->setValue(false, NOUPDATE);
00279 }
00280 else
00281 {
00282
00283 for (o=0; o < inObservations_/2; o++)
00284 for (t = 0; t < inSamples_; t++)
00285 {
00286 out(o,t) = in(o, t);
00287 }
00288
00289 for (o=0; o < onObservations_/2; o++)
00290 for (t = 0; t < inSamples_; t++)
00291 {
00292 out(2*o, t) = ratio1 * out(2*o,t);
00293 }
00294
00295
00296
00297 ctrl_transient_->setValue(true, NOUPDATE);
00298
00299 }
00300
00301 }
00302
00303
00304
00305
00306
00307
00308 }