コード例 #1
0
ファイル: psd.cpp プロジェクト: jmlee4301/kst
QString PSD::descriptionTip() const {
  QString tip;

  tip = tr("Spectrum: %1\n  FFT Length: 2^%2").arg(Name()).arg(length());

  if (average() || apodize() || removeMean()) {
    tip += "\n  ";
    if (average()) tip += tr("Average; ");
    if (apodize()) tip += tr("Apodize; ");
    if (removeMean()) tip += tr("Remove Mean;");
  }
  tip += tr("\nInput: %1").arg(_inputVectors[INVECTOR]->descriptionTip());
  return tip;
}
コード例 #2
0
// store the current state of the widget as the default
void FFTOptions::setWidgetDefaults() {
  _dialogDefaults->setValue("spectrum/freq", sampleRate());
  _dialogDefaults->setValue("spectrum/average", interleavedAverage());
  _dialogDefaults->setValue("spectrum/len", FFTLength());
  _dialogDefaults->setValue("spectrum/apodize", apodize());
  _dialogDefaults->setValue("spectrum/removeMean", removeMean());
  _dialogDefaults->setValue("spectrum/vUnits", vectorUnits());
  _dialogDefaults->setValue("spectrum/rUnits", rateUnits());
  _dialogDefaults->setValue("spectrum/apodizeFxn", apodizeFunction());
  _dialogDefaults->setValue("spectrum/gaussianSigma", sigma());
  _dialogDefaults->setValue("spectrum/output", output());
  _dialogDefaults->setValue("spectrum/interpolateHoles", interpolateOverHoles());
}
コード例 #3
0
void KstPSDGenerator::updateNow() {

  int i_subset, i_samp;
  int n_subsets;
  int v_len;
  int copyLen;
  QValueVector<double> psd, f;
  double mean;
  double nf;
  bool done;
  
  adjustLengths();
  
  v_len = _inputVector->size();
  n_subsets = v_len/_PSDLen+1;
  if (v_len%_PSDLen==0) n_subsets--;

  // always update when asked
  _last_n_new = _inputVector->size();

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

  nf = 0;
  done = false;
  for (i_subset = 0; !done; i_subset++) {
    // copy each chunk into a[] and find mean
    if (i_subset*_PSDLen + _ALen < v_len) {
      copyLen = _ALen;
    } else {
      copyLen = v_len - i_subset*_PSDLen;
      done = true;
    }

    mean = 0;
    for (i_samp = 0; i_samp < copyLen; i_samp++) {
      mean += (
        _a[i_samp] =
        _inputVector->at(i_samp + i_subset*_PSDLen)
        );
    }
    if (copyLen > 1) {
      mean /= (double)copyLen;
    }

    if (apodize()) {
      GenW(copyLen);
    }
     
    // remove mean and apodize
    if (removeMean() && apodize()) {
      for (i_samp=0; i_samp<copyLen; i_samp++) {
        _a[i_samp]= (_a[i_samp]-mean)*_w[i_samp];
      }
    } else if (removeMean()) {
      for (i_samp=0; i_samp<copyLen; i_samp++) {
        _a[i_samp] -= mean;
      }
    } else if (apodize()) {
      for (i_samp=0; i_samp<copyLen; i_samp++) {
        _a[i_samp] *= _w[i_samp];
      }
    }
    nf += copyLen;


    for (;i_samp < _ALen; i_samp++) {
      _a[i_samp] = 0.0;
    }
    // fft a
    rdft(_ALen, 1, _a);
    (*_powerVector)[0] += _a[0]*_a[0];
    (*_powerVector)[_PSDLen-1] += _a[1]*_a[1];
    for (i_samp=1; i_samp<_PSDLen-1; i_samp++) {
      (*_powerVector)[i_samp]+= cabs2(_a[i_samp*2], _a[i_samp*2+1]);
    }
  }

  _last_f0 = 0;
  _last_n_subsets = n_subsets;
  _last_n_new = 0;
  nf = 1.0/(double(_Freq)*double(nf/2.0));
  for ( i_samp = 0; i_samp<_PSDLen; i_samp++ ) {
    (*_powerVector)[i_samp] = sqrt((*_powerVector)[i_samp]*nf);
  }
  if (_Freq <= 0.0) {
    _Freq = 1.0;
  }
}