本文整理汇总了C++中KstVectorPtr::value方法的典型用法代码示例。如果您正苦于以下问题:C++ KstVectorPtr::value方法的具体用法?C++ KstVectorPtr::value怎么用?C++ KstVectorPtr::value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KstVectorPtr
的用法示例。
在下文中一共展示了KstVectorPtr::value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fit
void Normalization::fit(int k, int p, int iLength, double arr[], double cof[], KstVectorPtr vector_out)
{
if(k+p < iLength)
{
double v1[p];
double v2[p];
int j=0;
for(int i=k; i<k+p; i++)
{
v1[j] = (double)i;
v2[j] = arr[i];
j++;
}
double c0, c1, cov00, cov01, cov11, chisq;
gsl_fit_linear(v1, 1, v2, 1, p, &c0, &c1, &cov00, &cov01, &cov11, &chisq);
cof[0] = c0;
cof[1] = c1;
for(int i=k; i<k+p; i++)
{
vector_out->value()[i] = cof[0]+cof[1]*i;
}
}
else
{
for(int i=k; i<iLength; i++)
{
vector_out->value()[i] = cof[0]+cof[1]*i;
}
}
}
示例2: algorithm
//swap input vector
bool Reverse::algorithm() {
KstVectorPtr input = inputVector(INPUT);
KstVectorPtr output = outputVector(OUTPUT);
output->resize(input->length());
int length = input->length();
for (int i = 0; i < length; i++){
output->value()[length-i-1] = input->value()[i];
}
return true;
}
示例3: createFitScalars
// FIXME: KstPlugin should not know about fit scalars!!
void KstPlugin::createFitScalars() {
if (_plugin->data()._isFit && _outputVectors.contains("Parameters")) {
KstVectorPtr vectorParam = _outputVectors["Parameters"];
if (vectorParam) {
QString paramName;
int i = 0;
int length = vectorParam->length();
for (paramName = _plugin->parameterName(i);
!paramName.isEmpty() && i < length;
paramName = _plugin->parameterName(++i)) {
double scalarValue = vectorParam->value(i);
if (!_outputScalars.contains(paramName)) {
QString scalarName = i18n("%1-%2").arg(tagName()).arg(paramName);
KstScalarPtr s = new KstScalar(scalarName, scalarValue);
s->writeLock();
s->setProvider(this);
s->writeUnlock();
_outputScalars.insert(paramName, s);
} else {
_outputScalars[paramName]->setValue(scalarValue);
}
}
}
}
}
示例4: createFitScalars
void KstCPlugin::createFitScalars() {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
// Assumes that this is called with a write lock in place on this object
if (_plugin->data()._isFit && _outputVectors.contains("Parameters")) {
KstVectorPtr vectorParam = _outputVectors["Parameters"];
if (vectorParam) {
QString paramName;
int i = 0;
int length = vectorParam->length();
KstWriteLocker blockScalarUpdates(&KST::scalarList.lock());
KST::scalarList.setUpdateDisplayTags(false);
for (paramName = _plugin->parameterName(i);
!paramName.isEmpty() && i < length;
paramName = _plugin->parameterName(++i)) {
double scalarValue = vectorParam->value(i);
if (!_outputScalars.contains(paramName)) {
KstScalarPtr s = new KstScalar(KstObjectTag(paramName, tag()), this, scalarValue);
s->KstObject::writeLock(); // must write lock, since fit scalars are created from update()
_outputScalars.insert(paramName, s);
++_outScalarCnt;
} else {
_outputScalars[paramName]->setValue(scalarValue);
}
}
KST::scalarList.setUpdateDisplayTags(true);
}
}
}
示例5: vectorToFile
int KST::vectorToFile(KstVectorPtr v, QFile *f) {
int rc = 0;
#define BSIZE 128
char buf[BSIZE];
int _size = v->length();
double *_v = v->value();
register int modval;
KProgressDialog *kpd = new KProgressDialog(0L, "vector save", i18n("Saving Vector"), i18n("Saving vector %1...").arg(v->tagName()));
kpd->setAllowCancel(false);
kpd->progressBar()->setTotalSteps(_size);
kpd->show();
modval = QMAX(_size/100, 100);
for (int i = 0; i < _size; i++) {
int l = snprintf(buf, BSIZE, "%d %g\n", i, _v[i]);
f->writeBlock(buf, l);
if (i % 100 == 0) {
kpd->progressBar()->setProgress(i);
kapp->processEvents();
}
}
kpd->progressBar()->setProgress(_size);
delete kpd;
#undef BSIZE
return rc;
}
示例6: algorithm
bool Differentiation::algorithm() {
KstVectorPtr inputvector = inputVector(INPUTVECTOR);
KstScalarPtr time_step = inputScalar(TIME_STEP);
KstVectorPtr derivative = outputVector(DERIVATIVE);
/* Memory allocation */
if (derivative->length() != inputvector->length()) {
derivative->resize(inputvector->length(), true);
}
derivative->value()[0] = (inputvector->value()[1] - inputvector->value()[0]) / time_step->value();
int i = 1;
for (; i < inputvector->length()-1; i++) {
derivative->value()[i] = (inputvector->value()[i+1] - inputvector->value()[i-1])/(2*time_step->value());
}
derivative->value()[i] = (inputvector->value()[i] - inputvector->value()[i-1]) / time_step->value();
return true;
}
示例7: paintCell
void KstVectorTable::paintCell( QPainter* painter, int row, int col, const QRect& cr, bool selected, const QColorGroup& cg ) {
KstVectorPtr vector = *KST::vectorList.findTag(_strVector);
QString str;
painter->eraseRect( 0, 0, cr.width(), cr.height() );
if (selected) {
painter->fillRect( 0, 0, cr.width(), cr.height(), cg.highlight() );
painter->setPen(cg.highlightedText());
} else {
painter->fillRect( 0, 0, cr.width(), cr.height(), cg.base() );
painter->setPen(cg.text());
}
if( col == 0 && vector) {
str.setNum(vector->value(row), 'g', 16);
}
painter->drawText(0, 0, cr.width(), cr.height(), AlignLeft, str);
}
示例8: generateVector
KstVectorPtr KstVector::generateVector(double x0, double x1, int n, const QString &tag) {
if (n < 2) {
n = 2;
}
if (x0 > x1) {
double tx;
tx = x0;
x0 = x1;
x1 = tx;
}
if (x0 == x1) {
x1 = x0 + 0.1;
}
QString t = tag;
if (t.isEmpty()) {
KST::vectorList.lock().readLock();
t = "V" + QString::number(KST::vectorList.count() + 1) + "-" + "X(" + QString::number(x0) + ".." + QString::number(x1) + ")";
KST::vectorList.lock().readUnlock();
}
while (KST::vectorTagNameNotUnique(t, false)) {
t += "'";
}
KstVectorPtr xv = new KstVector(t, n);
for (int i = 0; i < n; i++) {
xv->value()[i] = x0 + double(i) * (x1 - x0) / (n - 1);
}
xv->_scalars["min"]->setValue(x0);
xv->_scalars["max"]->setValue(x1);
xv->UpdateScalars();
return xv;
}
示例9: algorithm
bool CrossCorrelate::algorithm() {
KstVectorPtr array_one = inputVector(ARRAY_ONE);
KstVectorPtr array_two = inputVector(ARRAY_TWO);
KstVectorPtr step_value = outputVector(STEP_VALUE);
KstVectorPtr correlated = outputVector(CORRELATED);
if (array_one->length() <= 0 ||
array_two->length() <= 0 ||
array_one->length() != array_two->length()) {
return false;
}
double* pdArrayOne;
double* pdArrayTwo;
double* pdResult[2];
double dReal;
double dImag;
int iLength;
int iLengthNew;
bool iReturn = false;
//
// zero-pad the array...
//
iLength = array_one->length();
iLength *= 2;
step_value->resize(array_one->length(), false);
correlated->resize(array_two->length(), false);
//
// round iLength up to the nearest power of two...
//
iLengthNew = 64;
while( iLengthNew < iLength && iLengthNew > 0) {
iLengthNew *= 2;
}
iLength = iLengthNew;
if (iLength <= 0)
return false;
pdArrayOne = new double[iLength];
pdArrayTwo = new double[iLength];
if (pdArrayOne != NULL && pdArrayTwo != NULL) {
//
// zero-pad the two arrays...
//
memset( pdArrayOne, 0, iLength * sizeof( double ) );
memcpy( pdArrayOne, array_one->value(), array_one->length() * sizeof( double ) );
memset( pdArrayTwo, 0, iLength * sizeof( double ) );
memcpy( pdArrayTwo, array_two->value(), array_two->length() * sizeof( double ) );
//
// calculate the FFTs of the two functions...
//
if (gsl_fft_real_radix2_transform( pdArrayOne, 1, iLength ) == 0) {
if (gsl_fft_real_radix2_transform( pdArrayTwo, 1, iLength ) == 0) {
//
// multiply one FFT by the complex conjugate of the other...
//
for (int i=0; i<iLength/2; i++) {
if (i==0 || i==(iLength/2)-1) {
pdArrayOne[i] = pdArrayOne[i] * pdArrayTwo[i];
} else {
dReal = pdArrayOne[i] * pdArrayTwo[i] + pdArrayOne[iLength-i] * pdArrayTwo[iLength-i];
dImag = pdArrayOne[i] * pdArrayTwo[iLength-i] - pdArrayOne[iLength-i] * pdArrayTwo[i];
pdArrayOne[i] = dReal;
pdArrayOne[iLength-i] = dImag;
}
}
//
// do the inverse FFT...
//
if (gsl_fft_halfcomplex_radix2_inverse( pdArrayOne, 1, iLength ) == 0) {
if (step_value->length() != array_one->length()) {
pdResult[0] = (double*)realloc( step_value->value(), array_one->length() * sizeof( double ) );
} else {
pdResult[0] = step_value->value();
}
if (correlated->length() != array_two->length()) {
pdResult[1] = (double*)realloc( correlated->value(), array_two->length() * sizeof( double ) );
} else {
pdResult[1] = correlated->value();
}
if (pdResult[0] != NULL && pdResult[1] != NULL) {
for (int i = 0; i < array_one->length(); ++i) {
step_value->value()[i] = pdResult[0][i];
}
for (int i = 0; i < array_two->length(); ++i) {
correlated->value()[i] = pdResult[1][i];
}
//.........这里部分代码省略.........
示例10: doTests
void doTests() {
KstVectorPtr vp = new KstVector(KstObjectTag("tempVector"), 10);
for (int i = 0; i < 10; i++){
vp->value()[i] = i;
}
KstPSDPtr psd = new KstPSD(QString("psdTest"), vp, 0.0, false, 10, false, false, QString("vUnits"), QString("rUnits"), WindowUndefined, 0.0, PSDUndefined);
doTest(psd->tagName() == "psdTest");
doTest(psd->vTag() == "tempVector");
doTest(psd->output() == PSDUndefined);
doTest(!psd->apodize());
doTest(!psd->removeMean());
doTest(!psd->average());
doTest(psd->freq() == 0.0);
doTest(psd->apodizeFxn() == WindowUndefined);
doTest(psd->gaussianSigma() == 0);
KstVectorPtr vpVX = psd->vX();
KstVectorPtr vpVY = psd->vY();
// until we call update the x and y vectors will be uninitialised and
// and so they should be of length 1 and the value of vpVX[0] and
// vpVX[0] should be NAN...
doTestV(QString("vpVX->length()"), vpVX->length(), 1);
doTestV(QString("vpVY->length()"), vpVY->length(), 1);
doTestV(QString("vpVX->length()"), isnan(vpVX->value()[0]), 1);
doTestV(QString("vpVY->length()"), isnan(vpVY->value()[0]), 1);
doTest(psd->update(0) == KstObject::UPDATE);
for(int j = 0; j < vpVX->length(); j++){
doTest(vpVX->value()[j] == 0);
}
psd->setOutput(PSDAmplitudeSpectralDensity);
psd->setApodize(true);
psd->setRemoveMean(true);
psd->setAverage(true);
psd->setFreq(0.1);
psd->setApodizeFxn(WindowOriginal);
psd->setGaussianSigma(0.2);
doTest(psd->tagName() == "psdTest");
doTest(psd->vTag() == "tempVector");
doTest(psd->output() == PSDAmplitudeSpectralDensity);
doTest(psd->apodize());
doTest(psd->removeMean());
doTest(psd->average());
doTest(psd->freq() == 0.1);
doTest(psd->apodizeFxn() == WindowOriginal);
doTest(psd->gaussianSigma() == 0.2);
// doTest(psd->update(0) == KstObject::UPDATE);
// QString ps = "PSD: " + psd->vTag();
// doTest(psd->propertyString() == ps);
// doTest(!psd->curveHints().curveName() == "");
// printf("Curve name [%s]", kstCHL[0].curveName());
// printf("X Vector name [%s]", kstCHL[0].xVectorName());
// printf("Y Vector name [%s]", kstCHL[0].yVectorName());
KTempFile tf(locateLocal("tmp", "kst-csd"), "txt");
QFile *qf = tf.file();
QTextStream ts(qf);
psd->save(ts, "");
QFile::remove(tf.name());
QDomNode n = makeDOMElement("psdDOMPsd", "psdDOMVector").firstChild();
QDomElement e = n.toElement();
KstPSDPtr psdDOM = new KstPSD(e);
doTest(psdDOM->tagName() == "psdDOMPsd");
doTest(psdDOM->output() == PSDAmplitudeSpectralDensity);
doTest(psdDOM->apodize());
doTest(psdDOM->removeMean());
doTest(psdDOM->average());
doTest(psdDOM->freq() == 128);
doTest(psdDOM->apodizeFxn() == WindowOriginal);
doTest(psdDOM->gaussianSigma() == 0.01);
// KstVectorPtr vpVX = psdDOM->vX();
// for(int j = 0; j < vpVX->length(); j++){
// printf("[%d][%lf]", j, vpVX->value()[j]);
// }
// KstVectorPtr vpVY = psdDOM->vY();
}
示例11: fitChanged
void KstViewFitsDialog::fitChanged(const QString& strFit) {
KstCPluginList fits;
KstCPluginPtr plugin;
double* params = 0L;
double* covars = 0L;
double chi2Nu = 0.0;
int numParams = 0;
int numCovars = 0;
int i;
fits = kstObjectSubList<KstDataObject,KstCPlugin>(KST::dataObjectList);
plugin = *(fits.findTag(strFit));
if (plugin) {
KstScalarPtr scalarChi2Nu;
KstVectorPtr vectorParam;
plugin->readLock();
const KstScalarMap& scalars = plugin->outputScalars();
scalarChi2Nu = scalars["chi^2/nu"];
if (scalarChi2Nu) {
scalarChi2Nu->readLock();
chi2Nu = scalarChi2Nu->value();
scalarChi2Nu->unlock();
}
const KstVectorMap& vectors = plugin->outputVectors();
vectorParam = vectors["Parameters"];
if (vectorParam) {
KstVectorPtr vectorCovar;
vectorParam->readLock();
vectorCovar = vectors["Covariance"];
if (vectorCovar) {
vectorCovar->readLock();
numParams = vectorParam->length();
numCovars = vectorCovar->length();
if (numParams > 0 && numCovars > 0) {
params = new double[numParams];
covars = new double[numCovars];
for (i = 0; i < numParams; i++) {
params[i] = vectorParam->value(i);
}
for (i = 0; i < numCovars; i++) {
covars[i] = vectorCovar->value(i);
}
}
vectorCovar->unlock();
}
vectorParam->unlock();
}
plugin->unlock();
}
_tableFits->setParameters(params, numParams, covars, numCovars, chi2Nu);
if (numParams > 0) {
_tableFits->horizontalHeaderItem(0)->setText(QObject::tr("Value"));
_tableFits->horizontalHeaderItem(1)->setText(QObject::tr("Covariance:"));
_tableFits->verticalHeaderItem(numParams+0)->setText("---");
_tableFits->verticalHeaderItem(numParams+1)->setText(QObject::tr("Chi^2/Nu"));
if (plugin) {
QExplicitlySharedDataPointer<Plugin> pluginBase;
plugin->readLock();
pluginBase = plugin->plugin();
if (pluginBase) {
textLabelFit->setText(pluginBase->data()._readableName);
for (i = 0; i < numParams; i++) {
QString parameterName = pluginBase->parameterName(i);
_tableFits->horizontalHeaderItem(i+2)->setText(parameterName);
_tableFits->verticalHeaderItem(i)->setText(parameterName);
}
}
plugin->unlock();
}
}
_tableFits->update();
}
示例12: update
KstObject::UpdateType KstCSD::update(int update_counter) {
KstVectorPtr inVector = _inputVectors[INVECTOR];
bool force = dirty();
setDirty(false);
if (KstObject::checkUpdateCounter(update_counter) && !force) {
return lastUpdateResult();
}
if (update_counter <= 0) {
assert(update_counter == 0);
force = true;
}
bool xUpdated = KstObject::UPDATE == inVector->update(update_counter);
// if vector was not changed, don't update the CSD
if (!xUpdated && !force) {
return setLastUpdateResult(NO_CHANGE);
}
double *tempOutput, *input;
int tempOutputLen = PSDCalculator::calculateOutputVectorLength(_windowSize, _average, _averageLength);
_PSDLen = tempOutputLen;
tempOutput = new double[tempOutputLen];
input = inVector->value();
int xSize = 0;
for (int i=0; i < inVector->length(); i+= _windowSize) {
//ensure there is enough data left.
if (i + _windowSize >= inVector->length()) {
break; //If there isn't enough left for a complete window.
}
_psdCalculator.calculatePowerSpectrum(input + i, _windowSize, tempOutput, tempOutputLen, _removeMean, false, _average, _averageLength, _apodize, _apodizeFxn, _gaussianSigma, _outputType, _frequency);
// resize output matrix
(*_outMatrix)->resize(xSize+1, tempOutputLen);
if ((*_outMatrix)->sampleCount() == (xSize+1)*tempOutputLen) { // all is well.
// copy elements to output matrix
for (int j=0; j < tempOutputLen; j++) {
(*_outMatrix)->setValueRaw(xSize, j, tempOutput[j]);
}
} else {
KstDebug::self()->log(i18n("Could not allocate sufficient memory for CSD."), KstDebug::Error);
break;
}
xSize++;
}
delete tempOutput;
double frequencyStep = .5*_frequency/(double)(tempOutputLen-1);
(*_outMatrix)->change((*_outMatrix)->tagName(), xSize, tempOutputLen, 0, 0, _windowSize, frequencyStep);
(*_outMatrix)->update(update_counter);
return setLastUpdateResult(UPDATE);
}
示例13: switch
void KstViewLabel::DataCache::update() {
for (QValueVector<DataRef>::ConstIterator i = data.begin(); valid && i != data.end(); ++i) {
switch ((*i).type) {
case DataRef::DataRef::DRScalar:
{
KST::scalarList.lock().readLock();
KstScalarPtr p = *KST::scalarList.findTag((*i).name);
KST::scalarList.lock().unlock();
if (p) {
p->readLock();
if (QVariant(p->value()) != (*i).value) {
valid = false;
}
p->unlock();
}
}
break;
case DataRef::DRString:
{
KST::stringList.lock().readLock();
KstStringPtr p = *KST::stringList.findTag((*i).name);
KST::stringList.lock().unlock();
if (p) {
p->readLock();
if (QVariant(p->value()) != (*i).value) {
valid = false;
}
p->unlock();
}
}
break;
case DataRef::DRExpression:
{
bool ok = false;
const double val = Equation::interpret((*i).name.latin1(), &ok, (*i).name.length());
if (QVariant(val) != (*i).value) {
valid = false;
}
}
break;
case DataRef::DRVector:
{
bool ok = false;
const double idx = Equation::interpret((*i).index.latin1(), &ok, (*i).index.length());
if (idx != (*i).indexValue) {
valid = false;
break;
}
KST::vectorList.lock().readLock();
KstVectorPtr p = *KST::vectorList.findTag((*i).name);
KST::vectorList.lock().unlock();
if (p) {
p->readLock();
if (QVariant(p->value(int((*i).indexValue))) != (*i).value) {
valid = false;
}
p->unlock();
}
}
break;
case DataRef::DataRef::DRFit:
{
KST::dataObjectList.lock().readLock();
KstDataObjectList::Iterator oi = KST::dataObjectList.findTag((*i).name);
KST::dataObjectList.lock().unlock();
if (oi != KST::dataObjectList.end()) {
KstCPluginPtr fit = kst_cast<KstCPlugin>(*oi);
if (fit) {
fit->readLock();
if (fit->label((int)((*i).indexValue)) != (*i).index) {
valid = false;
}
fit->unlock();
}
}
}
break;
}
}
}
示例14: update
KstObject::UpdateType KstCPlugin::update(int update_counter) {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
if (!isValid()) {
return setLastUpdateResult(NO_CHANGE);
}
if (recursed()) {
return setLastUpdateResult(NO_CHANGE);
}
bool force = dirty();
setDirty(false);
if (KstObject::checkUpdateCounter(update_counter) && !force) {
return lastUpdateResult();
}
#define CLEANUP() do {\
for (unsigned i = 0; i < _outStringCnt; ++i) { \
if (_outStrings[i]) { \
free(_outStrings[i]); \
_outStrings[i] = 0L; \
} \
} \
for (unsigned i = 0; i < _inStringCnt; ++i) { \
if (_inStrings[i]) { \
free(_inStrings[i]); \
_inStrings[i] = 0L; \
} \
} \
} while(0)
writeLockInputsAndOutputs();
const QValueList<Plugin::Data::IOValue>& itable = _plugin->data()._inputs;
const QValueList<Plugin::Data::IOValue>& otable = _plugin->data()._outputs;
int itcnt = 0, vitcnt = 0, sitcnt = 0;
bool doUpdate = force;
// Populate the input scalars and vectors
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = itable.begin(); it != itable.end(); ++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if (!_inputVectors.contains((*it)._name)) {
KstDebug::self()->log(i18n("Input vector [%1] for plugin %2 not found. Unable to continue.").arg((*it)._name).arg(tagName()), KstDebug::Error);
CLEANUP();
return setLastUpdateResult(NO_CHANGE);
}
KstVectorPtr iv = _inputVectors[(*it)._name];
if (!iv) {
kstdFatal() << "Input vector \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == iv->update(update_counter)) || doUpdate;
_inVectors[vitcnt] = iv->value();
_inArrayLens[vitcnt++] = iv->length();
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
KstScalarPtr is = _inputScalars[(*it)._name];
if (!is) {
kstdFatal() << "Input scalar \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == is->update(update_counter)) || doUpdate;
_inScalars[itcnt++] = is->value();
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
KstStringPtr is = _inputStrings[(*it)._name];
if (!is) {
kstdFatal() << "Input string \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == is->update(update_counter)) || doUpdate;
// Maybe we should use UTF-8 instead?
_inStrings[sitcnt++] = strdup(is->value().latin1());
} else if ((*it)._type == Plugin::Data::IOValue::PidType) {
_inScalars[itcnt++] = getpid();
}
}
if (!doUpdate) {
CLEANUP();
unlockInputsAndOutputs();
return setLastUpdateResult(NO_CHANGE);
}
vitcnt = 0;
// Populate the output vectors
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin();
it != otable.end();
++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if (!_outputVectors.contains((*it)._name)) {
KstDebug::self()->log(i18n("Output vector [%1] for plugin %2 not found. Unable to continue.").arg((*it)._name).arg(tagName()), KstDebug::Error);
CLEANUP();
unlockInputsAndOutputs();
return setLastUpdateResult(NO_CHANGE);
}
_outVectors[vitcnt] = _outputVectors[(*it)._name]->value();
_outArrayLens[vitcnt++] = _outputVectors[(*it)._name]->length();
}
}
if (_outStringCnt > 0) {
//.........这里部分代码省略.........
示例15: crossspectrum
void CrossPowerSpectrum::crossspectrum() {
KstVectorPtr v1 = *_inputVectors.find(VECTOR_ONE);
KstVectorPtr v2 = *_inputVectors.find(VECTOR_TWO);
KstScalarPtr fft = *_inputScalars.find(FFT_LENGTH);
KstScalarPtr sample = *_inputScalars.find(SAMPLE_RATE);
KstVectorPtr real = *_outputVectors.find(REAL);
KstVectorPtr imaginary = *_outputVectors.find(IMAGINARY);
KstVectorPtr frequency = *_outputVectors.find(FREQUENCY);
double SR = sample->value(); // sample rate
double df;
int i, xps_len;
double *a, *b;
double mean_a, mean_b;
int dv0, dv1, v_len;
int i_subset, n_subsets;
int i_samp, copyLen;
double norm_factor;
/* parse fft length */
xps_len = int( fft->value() - 0.99);
if ( xps_len > KSTPSDMAXLEN ) xps_len = KSTPSDMAXLEN;
if ( xps_len<2 ) xps_len = 2;
xps_len = int ( pow( 2, xps_len ) );
/* input vector lengths */
v_len = ( ( v1->length() < v2->length() ) ?
v1->length() : v2->length() );
dv0 = v_len/v1->length();
dv1 = v_len/v2->length();
while ( xps_len > v_len ) xps_len/=2;
// allocate the lengths
if ( real->length() != xps_len ) {
real->resize( xps_len, false );
imaginary->resize( xps_len, false );
frequency->resize( xps_len, false );
}
/* Fill the frequency and zero the xps */
df = SR/( 2.0*double( xps_len-1 ) );
for ( i=0; i<xps_len; i++ ) {
frequency->value()[i] = double( i ) * df;
real->value()[i] = 0.0;
imaginary->value()[i] = 0.0;
}
/* allocate input arrays */
int ALen = xps_len * 2;
a = new double[ALen];
b = new double[ALen];
/* do the fft's */
n_subsets = v_len/xps_len + 1;
for ( i_subset=0; i_subset<n_subsets; i_subset++ ) {
/* copy each chunk into a[] and find mean */
if (i_subset*xps_len + ALen <= v_len) {
copyLen = ALen;
} else {
copyLen = v_len - i_subset*xps_len;
}
mean_b = mean_a = 0;
for (i_samp = 0; i_samp < copyLen; i_samp++) {
i = ( i_samp + i_subset*xps_len )/dv0;
mean_a += (
a[i_samp] = v1->value()[i]
);
i = ( i_samp + i_subset*xps_len )/dv1;
mean_b += (
b[i_samp] = v2->value()[i]
);
}
if (copyLen>1) {
mean_a/=(double)copyLen;
mean_b/=(double)copyLen;
}
/* Remove Mean and apodize */
for (i_samp=0; i_samp<copyLen; i_samp++) {
a[i_samp] -= mean_a;
b[i_samp] -= mean_b;
}
for (;i_samp < ALen; i_samp++) {
a[i_samp] = 0.0;
b[i_samp] = 0.0;
}
/* fft */
rdft(ALen, 1, a);
rdft(ALen, 1, b);
/* sum each bin into psd[] */
real->value()[0] += ( a[0]*b[0] );
real->value()[xps_len-1] += ( a[1]*b[1] );
for (i_samp=1; i_samp<xps_len-1; i_samp++) {
//.........这里部分代码省略.........