Esempio n. 1
0
void PSD::change(VectorPtr in_V,
                               double in_freq, bool in_average, int in_averageLen, bool in_apodize,
                               bool in_removeMean, const QString& in_VUnits, const QString& in_RUnits,
                               ApodizeFunction in_apodizeFxn, double in_gaussianSigma, PSDType in_output,
                               bool interpolateHoles) {

  if (in_V) {
    _inputVectors[INVECTOR] = in_V;
  }
  _Frequency = in_freq;
  _Average = in_average;
  _Apodize = in_apodize;
  _apodizeFxn = in_apodizeFxn;
  _gaussianSigma = in_gaussianSigma;
  _prevOutput = PSDUndefined;
  _RemoveMean = in_removeMean;
  _vectorUnits = in_VUnits;
  _rateUnits = in_RUnits;
  _Output = in_output;
  _interpolateHoles = interpolateHoles;
  _averageLength = in_averageLen;

  _last_n_subsets = 0;
  _last_n_new = 0;
  _last_n_new = 0;

  _PSDLength = 1;

  _fVector->resize(_PSDLength);
  _sVector->resize(_PSDLength);

  _changed = true;
  updateVectorLabels();
}
Esempio n. 2
0
void PSD::internalUpdate() {
  writeLockInputsAndOutputs();

  VectorPtr iv = _inputVectors[INVECTOR];

  const int v_len = iv->length();

  _last_n_new += iv->numNew();
  assert(_last_n_new >= 0);

  int n_subsets = (v_len)/_PSDLength;

  // determine if the PSD needs to be updated.
  // if not using averaging, then we need at least _PSDLength/16 new data points.
  // if averaging, then we want enough new data for a complete subset.
  // ... unless we are counting from end at fixed length (scrolling data).
  bool scrolling_data = (_last_n == iv->length());
  if ( (!_changed) && ((_last_n_new < _PSDLength/16) ||
        (_Average && scrolling_data && (_last_n_new < _PSDLength/16)) ||
        (_Average && !scrolling_data && (n_subsets - _last_n_subsets < 1))) &&
       iv->length() != iv->numNew()) {
    unlockInputsAndOutputs();
    return;
  }

  _changed = false;

  _adjustLengths();

  double *psd = _sVector->value();
  double *f = _fVector->value();

  int i_samp;
  for (i_samp = 0; i_samp < _PSDLength; ++i_samp) {
    f[i_samp] = i_samp * 0.5 * _Frequency / (_PSDLength - 1);
  }
  //f[0] = -1E-280; // really 0 (this shouldn't be needed...)

  _psdCalculator.calculatePowerSpectrum(iv->value(), v_len, psd, _PSDLength, _RemoveMean,  _interpolateHoles, _Average, _averageLength, _Apodize, _apodizeFxn, _gaussianSigma, _Output, _Frequency);

  _last_n_subsets = n_subsets;
  _last_n_new = 0;
  _last_n = iv->length();

  updateVectorLabels();

  // should be updated by the update manager
  //_sVector->update();
  //_fVector->update();

  unlockInputsAndOutputs();

  return;
}
Esempio n. 3
0
void Equation::internalUpdate() {
  Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
  if (!_pe) {
    return;
  }

  writeLockInputsAndOutputs();

  Equations::Context ctx;
  ctx.sampleCount = _ns;
  ctx.xVector = _xInVector;

  _pe->update(&ctx);

  _isValid = FillY(true);

  unlockInputsAndOutputs();

  updateVectorLabels();

  return;
}
Esempio n. 4
0
void KstPSD::commonConstructor(const QString& in_tag, KstVectorPtr in_V,
                               double in_freq, bool in_average, int in_averageLen, bool in_apodize, 
                               bool in_removeMean, const QString& in_VUnits, const QString& in_RUnits, 
                               ApodizeFunction in_apodizeFxn, double in_gaussianSigma, PSDType in_output,
                               bool interpolateHoles) {

  _typeString = i18n("Spectrum");
  _type = "PowerSpectrum";
  if (in_V) {
    _inputVectors[INVECTOR] = in_V;
  }
  KstObject::setTagName(KstObjectTag::fromString(in_tag));
  _Freq = in_freq;
  _Average = in_average;
  _Apodize = in_apodize;
  _apodizeFxn = in_apodizeFxn;
  _gaussianSigma = in_gaussianSigma;
  _prevOutput = PSDUndefined;
  _RemoveMean = in_removeMean;
  _vUnits = in_VUnits;
  _rUnits = in_RUnits;
  _Output = in_output;
  _interpolateHoles = interpolateHoles;
  _averageLen = in_averageLen;

  _last_n_subsets = 0;
  _last_n_new = 0;

  _PSDLen = 1;
  KstVectorPtr ov = new KstVector(KstObjectTag("freq", tag()), _PSDLen, this);
  _fVector = _outputVectors.insert(FVECTOR, ov);

  ov = new KstVector(KstObjectTag("sv", tag()), _PSDLen, this);
  _sVector = _outputVectors.insert(SVECTOR, ov);

  updateVectorLabels();
}
Esempio n. 5
0
KstObject::UpdateType KstPSD::update(int update_counter) {
  Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);

  bool force = dirty();
  setDirty(false);

  if (KstObject::checkUpdateCounter(update_counter) && !force) {
    return lastUpdateResult();
  }

  if (recursed()) {
    return setLastUpdateResult(NO_CHANGE);
  }

  writeLockInputsAndOutputs();

  KstVectorPtr iv = _inputVectors[INVECTOR];

  if (update_counter <= 0) {
    assert(update_counter == 0);
    force = true;
  }

  bool xUpdated = KstObject::UPDATE == iv->update(update_counter);

  const int v_len = iv->length();

  // Don't touch _last_n_new if !xUpdated since it will certainly be wrong.
  if (!xUpdated && !force) {
    unlockInputsAndOutputs();
    return setLastUpdateResult(NO_CHANGE);
  }

  _last_n_new += iv->numNew();
  assert(_last_n_new >= 0);

  int n_subsets = v_len/_PSDLen;

  // determine if the PSD needs to be updated. if not using averaging, then we need at least _PSDLen/16 new data points. if averaging, then we want enough new data for a complete subset.
  if ( ((_last_n_new < _PSDLen/16) || (_Average && (n_subsets - _last_n_subsets < 1))) &&  iv->length() != iv->numNew() && !force) {
    unlockInputsAndOutputs();
    return setLastUpdateResult(NO_CHANGE);
  }

  _adjustLengths();

  double *psd = (*_sVector)->value();
  double *f = (*_fVector)->value();

  int i_samp;
  for (i_samp = 0; i_samp < _PSDLen; ++i_samp) {
    f[i_samp] = i_samp * 0.5 * _Freq / (_PSDLen - 1);
  }

  _psdCalculator.calculatePowerSpectrum(iv->value(), v_len, psd, _PSDLen, _RemoveMean,  _interpolateHoles, _Average, _averageLen, _Apodize, _apodizeFxn, _gaussianSigma, _Output, _Freq);

  _last_n_subsets = n_subsets;
  _last_n_new = 0;

  updateVectorLabels();
  (*_sVector)->setDirty();
  (*_sVector)->update(update_counter);
  (*_fVector)->setDirty();
  (*_fVector)->update(update_counter);

  unlockInputsAndOutputs();

  return setLastUpdateResult(UPDATE);
}