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; }
// 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()); }
void Mesh :: normalizeSolution( void ) { // center vertices around the origin removeMean( newVertices ); // find the vertex with the largest norm double r = 0.; for( size_t i = 0; i < vertices.size(); i++ ) { r = max( r, newVertices[i].norm2() ); } r = sqrt(r); // rescale so that vertices have norm at most one for( size_t i = 0; i < vertices.size(); i++ ) { newVertices[i] /= r; } }
KstObject::UpdateType KstPSDCurve::update(int update_counter) { int i_subset, i_samp; int n_subsets; int v_len; int copyLen; double mean; double y; bool force = false; KstVectorPtr iv = _inputVectors[INVECTOR]; double *psd; if (KstObject::checkUpdateCounter(update_counter)) return NO_CHANGE; if (update_counter <= 0) { force = true; } else { iv->update(update_counter); } v_len = iv->sampleCount(); n_subsets = v_len/PSDLen+1; last_n_new += iv->numNew(); if ((last_n_new < PSDLen/16) && (n_subsets - last_n_subsets < 1) && !force) { return NO_CHANGE; } psd = (*_sVector)->value(); for (i_samp = 0; i_samp < PSDLen; i_samp++) { psd[i_samp] = 0; } for (i_subset = 0; i_subset < n_subsets; 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; } mean = 0; for (i_samp = 0; i_samp < copyLen; i_samp++) { mean += ( a[i_samp] = iv->interpolate(i_samp + i_subset*PSDLen, v_len) ); } if (copyLen>1) mean/=(double)copyLen; /* Remove Mean and apodize */ if (removeMean() && appodize()) { 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 (appodize()) { for (i_samp=0; i_samp<copyLen; i_samp++) { a[i_samp] *= w[i_samp]; } } for (;i_samp < ALen; i_samp++) a[i_samp] = 0.0; /* fft a */ rdft(ALen, 1, a); /* sum each bin into psd[] */ psd[0]+=a[0]; psd[PSDLen-1] += a[1]; for (i_samp=1; i_samp<PSDLen-1; i_samp++) { psd[i_samp]+= cabs(a[i_samp*2], a[i_samp*2+1]); } } last_f0 = 0; last_n_subsets = n_subsets; last_n_new = 0; norm_factor = 1.0/(sqrt(double(Freq)*double(PSDLen))*double(n_subsets)); psd[0]*=norm_factor; MaxY = MinY = mean = psd[0]; if (psd[0]>0) MinPosY = psd[0]; else (MinPosY = 1.0e300); /* normalize psd */ for (i_samp=1; i_samp<PSDLen; i_samp++) { y = (psd[i_samp]*=norm_factor); if (y>MaxY) MaxY=y; if (y<MinY) MinY=y; if ((y>0) && (y<MinPosY)) MinPosY = y; mean +=y; } if (PSDLen > 0) MeanY = mean/PSDLen; else MeanY = 0; // should never ever happen... NS = PSDLen; if (Freq <= 0) Freq = 1.0; MaxX = Freq/2.0; MinX = 0; MinPosX = 1.0/double(NS) * MaxX; MeanX = MaxX/2.0; double *f = (*_fVector)->value(); f[0] = 0; f[1] = Freq/2.0; (*_sVector)->update(update_counter); (*_fVector)->update(update_counter); return UPDATE; }
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; } }