diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index eb9a2f4..5b709f6 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -78,40 +78,37 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - if (phaseVector[index].size() > SettingConfig::getInstance().SKIP_HEADER) + double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + QVector vecPoints; + + for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) { - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + // 新的数据点 + QCPGraphData onePoint; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) - { - minValue = phaseVector[index][i].at(1).toDouble(); - } - - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); - } + minValue = phaseVector[index][i].at(1).toDouble(); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index eb9a2f4..5b709f6 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -78,40 +78,37 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - if (phaseVector[index].size() > SettingConfig::getInstance().SKIP_HEADER) + double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + QVector vecPoints; + + for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) { - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + // 新的数据点 + QCPGraphData onePoint; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) - { - minValue = phaseVector[index][i].at(1).toDouble(); - } - - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); - } + minValue = phaseVector[index][i].at(1).toDouble(); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 3370847..f6cede4 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -37,8 +37,7 @@ void ChannelItem::updatePhaseMeasureData(PhaseDataDto * phaseData) { - int size = phaseVector.at(index).size() - SettingConfig::getInstance().SKIP_HEADER; - if (size < 0) size = 0; + int size = phaseVector.at(index).size(); double ps = phaseData->channelBeforeDelay.at(index) * 1e12; // 显示ps数据 ui->rawValue->setText(QString::number(ps, 'f', 3) + "ps"); // 原始数据显示单位为ps ui->channelValue->setText(QString::number(ps + channelDelay, 'f', 3) + "ps"); // 补偿值的单位也是ps, 补偿后也显示为ps diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index eb9a2f4..5b709f6 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -78,40 +78,37 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - if (phaseVector[index].size() > SettingConfig::getInstance().SKIP_HEADER) + double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + QVector vecPoints; + + for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) { - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + // 新的数据点 + QCPGraphData onePoint; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) - { - minValue = phaseVector[index][i].at(1).toDouble(); - } - - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); - } + minValue = phaseVector[index][i].at(1).toDouble(); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 3370847..f6cede4 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -37,8 +37,7 @@ void ChannelItem::updatePhaseMeasureData(PhaseDataDto * phaseData) { - int size = phaseVector.at(index).size() - SettingConfig::getInstance().SKIP_HEADER; - if (size < 0) size = 0; + int size = phaseVector.at(index).size(); double ps = phaseData->channelBeforeDelay.at(index) * 1e12; // 显示ps数据 ui->rawValue->setText(QString::number(ps, 'f', 3) + "ps"); // 原始数据显示单位为ps ui->channelValue->setText(QString::number(ps + channelDelay, 'f', 3) + "ps"); // 补偿值的单位也是ps, 补偿后也显示为ps diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 0364a76..7d7fd39 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -2,6 +2,7 @@ #include extern QVector> phaseVector; +extern QVector> channelAllenSigma; DataProcessAlgorithm::DataProcessAlgorithm(QObject *parent) : QObject(parent) { @@ -10,7 +11,7 @@ double DataProcessAlgorithm::allan(int index, int d, int aN, int start) { - int i = start - 1; // 从start处开始取数进行计算,避免开始采集时的数据不稳定带来的影响 + int i = 0; // 从start处开始取数进行计算,避免开始采集时的数据不稳定带来的影响 double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; @@ -30,3 +31,31 @@ delete[] y; return allan[1]; } + +double DataProcessAlgorithm::calAllan(int index, int d, int aN) +{ + int i = 0; + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double sum = 0.0; + double allan[2] = {0.0}; + double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 + + int logd = log10(d); + + for (int j = 3; j > 0; j--) + { + i = aN - 2*d - j; + double v2 = phaseVector[index][i+2*d].at(1).toDouble(); + double v1 = phaseVector[index][i+d].at(1).toDouble(); + double v0 = phaseVector[index][i].at(1).toDouble(); + double sigma = pow(v2 - 2 * v1 + v0, 2); + + sum = channelAllenSigma[index][logd] + sigma; + channelAllenSigma[index][logd] = sum; + } + + allan[0] = sum/(2*tau_2*(aN-2*d)); //delta的平方 + allan[1] = sqrt(sum/(2*tau_2*(aN-2*d))); //delta + + return allan[1]; +} diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index eb9a2f4..5b709f6 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -78,40 +78,37 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - if (phaseVector[index].size() > SettingConfig::getInstance().SKIP_HEADER) + double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + QVector vecPoints; + + for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) { - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + // 新的数据点 + QCPGraphData onePoint; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) - { - minValue = phaseVector[index][i].at(1).toDouble(); - } - - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); - } + minValue = phaseVector[index][i].at(1).toDouble(); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 3370847..f6cede4 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -37,8 +37,7 @@ void ChannelItem::updatePhaseMeasureData(PhaseDataDto * phaseData) { - int size = phaseVector.at(index).size() - SettingConfig::getInstance().SKIP_HEADER; - if (size < 0) size = 0; + int size = phaseVector.at(index).size(); double ps = phaseData->channelBeforeDelay.at(index) * 1e12; // 显示ps数据 ui->rawValue->setText(QString::number(ps, 'f', 3) + "ps"); // 原始数据显示单位为ps ui->channelValue->setText(QString::number(ps + channelDelay, 'f', 3) + "ps"); // 补偿值的单位也是ps, 补偿后也显示为ps diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 0364a76..7d7fd39 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -2,6 +2,7 @@ #include extern QVector> phaseVector; +extern QVector> channelAllenSigma; DataProcessAlgorithm::DataProcessAlgorithm(QObject *parent) : QObject(parent) { @@ -10,7 +11,7 @@ double DataProcessAlgorithm::allan(int index, int d, int aN, int start) { - int i = start - 1; // 从start处开始取数进行计算,避免开始采集时的数据不稳定带来的影响 + int i = 0; // 从start处开始取数进行计算,避免开始采集时的数据不稳定带来的影响 double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; @@ -30,3 +31,31 @@ delete[] y; return allan[1]; } + +double DataProcessAlgorithm::calAllan(int index, int d, int aN) +{ + int i = 0; + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double sum = 0.0; + double allan[2] = {0.0}; + double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 + + int logd = log10(d); + + for (int j = 3; j > 0; j--) + { + i = aN - 2*d - j; + double v2 = phaseVector[index][i+2*d].at(1).toDouble(); + double v1 = phaseVector[index][i+d].at(1).toDouble(); + double v0 = phaseVector[index][i].at(1).toDouble(); + double sigma = pow(v2 - 2 * v1 + v0, 2); + + sum = channelAllenSigma[index][logd] + sigma; + channelAllenSigma[index][logd] = sum; + } + + allan[0] = sum/(2*tau_2*(aN-2*d)); //delta的平方 + allan[1] = sqrt(sum/(2*tau_2*(aN-2*d))); //delta + + return allan[1]; +} diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 16e5fcd..9da73f0 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -11,6 +11,7 @@ explicit DataProcessAlgorithm(QObject *parent = nullptr); static double allan(int index,int d, int aN, int start); //double x[], + static double calAllan(int index, int d, int aN); signals: diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index eb9a2f4..5b709f6 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -78,40 +78,37 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - if (phaseVector[index].size() > SettingConfig::getInstance().SKIP_HEADER) + double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + QVector vecPoints; + + for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) { - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + // 新的数据点 + QCPGraphData onePoint; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) - { - minValue = phaseVector[index][i].at(1).toDouble(); - } - - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); - } + minValue = phaseVector[index][i].at(1).toDouble(); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 3370847..f6cede4 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -37,8 +37,7 @@ void ChannelItem::updatePhaseMeasureData(PhaseDataDto * phaseData) { - int size = phaseVector.at(index).size() - SettingConfig::getInstance().SKIP_HEADER; - if (size < 0) size = 0; + int size = phaseVector.at(index).size(); double ps = phaseData->channelBeforeDelay.at(index) * 1e12; // 显示ps数据 ui->rawValue->setText(QString::number(ps, 'f', 3) + "ps"); // 原始数据显示单位为ps ui->channelValue->setText(QString::number(ps + channelDelay, 'f', 3) + "ps"); // 补偿值的单位也是ps, 补偿后也显示为ps diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 0364a76..7d7fd39 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -2,6 +2,7 @@ #include extern QVector> phaseVector; +extern QVector> channelAllenSigma; DataProcessAlgorithm::DataProcessAlgorithm(QObject *parent) : QObject(parent) { @@ -10,7 +11,7 @@ double DataProcessAlgorithm::allan(int index, int d, int aN, int start) { - int i = start - 1; // 从start处开始取数进行计算,避免开始采集时的数据不稳定带来的影响 + int i = 0; // 从start处开始取数进行计算,避免开始采集时的数据不稳定带来的影响 double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; @@ -30,3 +31,31 @@ delete[] y; return allan[1]; } + +double DataProcessAlgorithm::calAllan(int index, int d, int aN) +{ + int i = 0; + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double sum = 0.0; + double allan[2] = {0.0}; + double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 + + int logd = log10(d); + + for (int j = 3; j > 0; j--) + { + i = aN - 2*d - j; + double v2 = phaseVector[index][i+2*d].at(1).toDouble(); + double v1 = phaseVector[index][i+d].at(1).toDouble(); + double v0 = phaseVector[index][i].at(1).toDouble(); + double sigma = pow(v2 - 2 * v1 + v0, 2); + + sum = channelAllenSigma[index][logd] + sigma; + channelAllenSigma[index][logd] = sum; + } + + allan[0] = sum/(2*tau_2*(aN-2*d)); //delta的平方 + allan[1] = sqrt(sum/(2*tau_2*(aN-2*d))); //delta + + return allan[1]; +} diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 16e5fcd..9da73f0 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -11,6 +11,7 @@ explicit DataProcessAlgorithm(QObject *parent = nullptr); static double allan(int index,int d, int aN, int start); //double x[], + static double calAllan(int index, int d, int aN); signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index 76678f0..52e9a2c 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -10,20 +10,16 @@ QVector> phaseVector(PHASE_MESSURE_CHANNEL, QVector()); // allan方差值 - 1s ~ 10000s -QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0,0)); +QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); +QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); + +int frameCount = 0; PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - - base = (qrand() % 100000) * 1000; - -// QTimer * timer = new QTimer(this); -// connect(timer, &QTimer::timeout, -// this, &PhaseDevice::mockPhaseData); -// timer->start(1000); } PhaseDevice::~PhaseDevice() @@ -36,45 +32,18 @@ { QString startCmd = PhaseProtocolBM::startMessure(); clientUtil->sendData(startCmd.toLocal8Bit()); - - // 2. 输出到日志文件中 - QDateTime now = QDateTime::currentDateTime(); - QString date = now.toString("yyyy-MM-dd"); - - // 2.1 原始字节数组数据 - QString filename = "netBytes.log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + startCmd; - QLogUtil::writeRawDataLogByDate(date, filename, content); } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); clientUtil->sendData(stopCmd.toLocal8Bit()); - - // 2. 输出到日志文件中 - QDateTime now = QDateTime::currentDateTime(); - QString date = now.toString("yyyy-MM-dd"); - - // 2.1 原始字节数组数据 - QString filename = "netBytes.log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + stopCmd; - QLogUtil::writeRawDataLogByDate(date, filename, content); } void PhaseDevice::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - // 2. 输出到日志文件中 - QDateTime now = QDateTime::currentDateTime(); - QString date = now.toString("yyyy-MM-dd"); - - // 2.1 原始字节数组数据 - QString filename = "netBytes.log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + QByteUtil::binToHexString(data); - QLogUtil::writeRawDataLogByDate(date, filename, content); - PhaseDataDto * phaseData = new PhaseDataDto(this); if (PhaseProtocolBM::checkFrame(this->dataBuff) == true) { @@ -116,6 +85,13 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QVector vectorZero(5); QVector vector(5); @@ -131,18 +107,9 @@ // 3.2 将通道数据写日志 QString chFilename = QString("CH_%1.log").arg(i + 1, 2, 10, QLatin1Char('0')); -// QString channelDataStr = QString("%1 [%2] %3 %4 %5") -// .arg(phaseData->timestamp) -// .arg(phaseData->frameId) -// .arg(phaseData->channelDataStr.at(i)) -// .arg(QString::number(channelDelay)) -// .arg(QString::number(phaseData->rawPhaseDiffData.at(i), 'f', 0)); -// std::cout << channelDataStr.toStdString() << std::endl; - QString channelDataStr = QString("%1 %2") .arg(phaseData->timestamp) .arg(QString::number(phaseData->channelBeforeDelay.at(i), 'e', 6)); - QLogUtil::writeChannelDataLogByDate(phaseData->timestamp.mid(0, 10), chFilename, channelDataStr); // 3.3 将补偿前的时差数据存入数据栈, 用于计算allen方差 @@ -154,12 +121,12 @@ mutex.unlock(); // 3.4 分别计算不同时间维度的稳定度 - int size = phaseVector[i].size() - SettingConfig::getInstance().SKIP_HEADER; - if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, SettingConfig::getInstance().SKIP_HEADER); else vector[0] = 0; - if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, SettingConfig::getInstance().SKIP_HEADER); else vector[1] = 0; - if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, SettingConfig::getInstance().SKIP_HEADER); else vector[2] = 0; - if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, SettingConfig::getInstance().SKIP_HEADER); else vector[3] = 0; - if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, SettingConfig::getInstance().SKIP_HEADER); else vector[4] = 0; + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::calAllan(i, 1, size); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::calAllan(i, 10, size); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::calAllan(i, 100, size); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::calAllan(i, 1000, size); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::calAllan(i, 10000, size); else vector[4] = 0; // 3.5 将稳定度计算结果存入 channelAllan[i] = vector; @@ -172,24 +139,3 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } - -void PhaseDevice::mockPhaseData() -{ - QDateTime now = QDateTime::currentDateTime(); - - QString frameId = now.toString("HHmmsszzz"); - - QByteArray buffer; - buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - - for (int i = 1; i <= 16; i++) - { - int value = base + qrand() % 40; - base = value; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); - } - - buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); - - this->dataReceivedHandler(buffer); -} diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index eb9a2f4..5b709f6 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -78,40 +78,37 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - if (phaseVector[index].size() > SettingConfig::getInstance().SKIP_HEADER) + double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); + QVector vecPoints; + + for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) { - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + // 新的数据点 + QCPGraphData onePoint; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) - { - minValue = phaseVector[index][i].at(1).toDouble(); - } - - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); - } + minValue = phaseVector[index][i].at(1).toDouble(); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 3370847..f6cede4 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -37,8 +37,7 @@ void ChannelItem::updatePhaseMeasureData(PhaseDataDto * phaseData) { - int size = phaseVector.at(index).size() - SettingConfig::getInstance().SKIP_HEADER; - if (size < 0) size = 0; + int size = phaseVector.at(index).size(); double ps = phaseData->channelBeforeDelay.at(index) * 1e12; // 显示ps数据 ui->rawValue->setText(QString::number(ps, 'f', 3) + "ps"); // 原始数据显示单位为ps ui->channelValue->setText(QString::number(ps + channelDelay, 'f', 3) + "ps"); // 补偿值的单位也是ps, 补偿后也显示为ps diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 0364a76..7d7fd39 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -2,6 +2,7 @@ #include extern QVector> phaseVector; +extern QVector> channelAllenSigma; DataProcessAlgorithm::DataProcessAlgorithm(QObject *parent) : QObject(parent) { @@ -10,7 +11,7 @@ double DataProcessAlgorithm::allan(int index, int d, int aN, int start) { - int i = start - 1; // 从start处开始取数进行计算,避免开始采集时的数据不稳定带来的影响 + int i = 0; // 从start处开始取数进行计算,避免开始采集时的数据不稳定带来的影响 double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; @@ -30,3 +31,31 @@ delete[] y; return allan[1]; } + +double DataProcessAlgorithm::calAllan(int index, int d, int aN) +{ + int i = 0; + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double sum = 0.0; + double allan[2] = {0.0}; + double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 + + int logd = log10(d); + + for (int j = 3; j > 0; j--) + { + i = aN - 2*d - j; + double v2 = phaseVector[index][i+2*d].at(1).toDouble(); + double v1 = phaseVector[index][i+d].at(1).toDouble(); + double v0 = phaseVector[index][i].at(1).toDouble(); + double sigma = pow(v2 - 2 * v1 + v0, 2); + + sum = channelAllenSigma[index][logd] + sigma; + channelAllenSigma[index][logd] = sum; + } + + allan[0] = sum/(2*tau_2*(aN-2*d)); //delta的平方 + allan[1] = sqrt(sum/(2*tau_2*(aN-2*d))); //delta + + return allan[1]; +} diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 16e5fcd..9da73f0 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -11,6 +11,7 @@ explicit DataProcessAlgorithm(QObject *parent = nullptr); static double allan(int index,int d, int aN, int start); //double x[], + static double calAllan(int index, int d, int aN); signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index 76678f0..52e9a2c 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -10,20 +10,16 @@ QVector> phaseVector(PHASE_MESSURE_CHANNEL, QVector()); // allan方差值 - 1s ~ 10000s -QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0,0)); +QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); +QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); + +int frameCount = 0; PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - - base = (qrand() % 100000) * 1000; - -// QTimer * timer = new QTimer(this); -// connect(timer, &QTimer::timeout, -// this, &PhaseDevice::mockPhaseData); -// timer->start(1000); } PhaseDevice::~PhaseDevice() @@ -36,45 +32,18 @@ { QString startCmd = PhaseProtocolBM::startMessure(); clientUtil->sendData(startCmd.toLocal8Bit()); - - // 2. 输出到日志文件中 - QDateTime now = QDateTime::currentDateTime(); - QString date = now.toString("yyyy-MM-dd"); - - // 2.1 原始字节数组数据 - QString filename = "netBytes.log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + startCmd; - QLogUtil::writeRawDataLogByDate(date, filename, content); } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); clientUtil->sendData(stopCmd.toLocal8Bit()); - - // 2. 输出到日志文件中 - QDateTime now = QDateTime::currentDateTime(); - QString date = now.toString("yyyy-MM-dd"); - - // 2.1 原始字节数组数据 - QString filename = "netBytes.log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + stopCmd; - QLogUtil::writeRawDataLogByDate(date, filename, content); } void PhaseDevice::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - // 2. 输出到日志文件中 - QDateTime now = QDateTime::currentDateTime(); - QString date = now.toString("yyyy-MM-dd"); - - // 2.1 原始字节数组数据 - QString filename = "netBytes.log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + QByteUtil::binToHexString(data); - QLogUtil::writeRawDataLogByDate(date, filename, content); - PhaseDataDto * phaseData = new PhaseDataDto(this); if (PhaseProtocolBM::checkFrame(this->dataBuff) == true) { @@ -116,6 +85,13 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QVector vectorZero(5); QVector vector(5); @@ -131,18 +107,9 @@ // 3.2 将通道数据写日志 QString chFilename = QString("CH_%1.log").arg(i + 1, 2, 10, QLatin1Char('0')); -// QString channelDataStr = QString("%1 [%2] %3 %4 %5") -// .arg(phaseData->timestamp) -// .arg(phaseData->frameId) -// .arg(phaseData->channelDataStr.at(i)) -// .arg(QString::number(channelDelay)) -// .arg(QString::number(phaseData->rawPhaseDiffData.at(i), 'f', 0)); -// std::cout << channelDataStr.toStdString() << std::endl; - QString channelDataStr = QString("%1 %2") .arg(phaseData->timestamp) .arg(QString::number(phaseData->channelBeforeDelay.at(i), 'e', 6)); - QLogUtil::writeChannelDataLogByDate(phaseData->timestamp.mid(0, 10), chFilename, channelDataStr); // 3.3 将补偿前的时差数据存入数据栈, 用于计算allen方差 @@ -154,12 +121,12 @@ mutex.unlock(); // 3.4 分别计算不同时间维度的稳定度 - int size = phaseVector[i].size() - SettingConfig::getInstance().SKIP_HEADER; - if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, SettingConfig::getInstance().SKIP_HEADER); else vector[0] = 0; - if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, SettingConfig::getInstance().SKIP_HEADER); else vector[1] = 0; - if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, SettingConfig::getInstance().SKIP_HEADER); else vector[2] = 0; - if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, SettingConfig::getInstance().SKIP_HEADER); else vector[3] = 0; - if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, SettingConfig::getInstance().SKIP_HEADER); else vector[4] = 0; + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::calAllan(i, 1, size); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::calAllan(i, 10, size); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::calAllan(i, 100, size); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::calAllan(i, 1000, size); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::calAllan(i, 10000, size); else vector[4] = 0; // 3.5 将稳定度计算结果存入 channelAllan[i] = vector; @@ -172,24 +139,3 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } - -void PhaseDevice::mockPhaseData() -{ - QDateTime now = QDateTime::currentDateTime(); - - QString frameId = now.toString("HHmmsszzz"); - - QByteArray buffer; - buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - - for (int i = 1; i <= 16; i++) - { - int value = base + qrand() % 40; - base = value; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); - } - - buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); - - this->dataReceivedHandler(buffer); -} diff --git a/PhaseDevice.h b/PhaseDevice.h index 683077d..0950f54 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -23,9 +23,6 @@ QByteArray dataBuff; - void mockPhaseData(); - qlonglong base; - signals: void sendDataToDraw(PhaseDataDto * phaseData);