diff --git a/trace_ex.cpp b/trace_ex.cpp index 689f753..9700249 100644 --- a/trace_ex.cpp +++ b/trace_ex.cpp @@ -47,7 +47,7 @@ void trace_ex::traceread(int trpos){ filepos=3200+400+(240+4*tlength)*(trpos-1); f.seek(filepos); //we must seek to the right trace header reading QByteArray thead(f.read(240)); //reading the trace header (we don't need to do this now) - QVector trace(tlength), traceposi(tlength), time(tlength); //Initializing vector with trace and time axis + QVector trace(tlength), time(tlength), traceposi(tlength), timeposi(tlength); //Initializing vector with trace and time axis @@ -91,13 +91,8 @@ void trace_ex::traceread(int trpos){ } trace[j]=sign*(mantissa/2)*pow(16,exponent-64); - if(trace[j]>=0){ - traceposi[j]=trace[j]; - } - else{ - traceposi[j]=0; - } time[j]=j*intsample*1e-3;//just adding the time vector + timeposi[j]=j*intsample*1e-3;//just adding the time vector // qDebug() << "trace" << trpos << j << time[j] << trace[j] << tlength; tr_temp=0; @@ -107,6 +102,27 @@ void trace_ex::traceread(int trpos){ } + for(int j=0; j0 && trace[j+1]<0){ + traceposi[j]=0; + double yp=time[j+1]-trace[j+1]*(time[j+1]-time[j])/(trace[j+1]-trace[j]); + timeposi[j]=yp; + } + else if(trace[j-1] < 0 && trace[j] > 0){ + traceposi[j]=0; + double yp=time[j-1]-trace[j-1]*(time[j]-time[j-1])/(trace[j]-trace[j-1]); + timeposi[j]=yp; + } + else if(trace[j] > 0 && trace[j+1] > 0){ + traceposi[j]=0; + } + else{ + traceposi[j]=trace[j]; + } + } + + + // This section calculates the bytes to display the header attributes (4-bytes words) @@ -264,18 +280,19 @@ void trace_ex::traceread(int trpos){ -// // This section plots the trace data adding the blank trace to achieve the wiggle effect +//// // This section plots the trace data adding the blank trace to achieve the wiggle effect ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); QPen pennone; pennone.setStyle(Qt::NoPen); +// pennone.setStyle(Qt::SolidLine); pennone.setWidth(1); - pennone.setColor(QColor(1,1,1)); + pennone.setColor(QColor(1,255,255,255)); ui->tracePlot->graph(1)->setName("Trace"+QString::number(trpos)); - ui->tracePlot->graph(1)->setData(time,traceposi); //adding a graph + ui->tracePlot->graph(1)->setData(timeposi,traceposi); //adding a graph ui->tracePlot->graph(1)->setPen(pennone); - ui->tracePlot->graph(1)->setBrush(QBrush(QColor(0,0,1))); -// ui->tracePlot->graph(0)->setChannelFillGraph(ui->tracePlot->graph(1)); + ui->tracePlot->graph(0)->setBrush(QBrush(QColor(0,0,1))); + ui->tracePlot->graph(0)->setChannelFillGraph(ui->tracePlot->graph(1)); connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); @@ -303,6 +320,7 @@ void trace_ex::traceread(int trpos){ freq[0]=0; for(int i=1;iwvPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); +// ui->wvPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); ui->wvPlot->axisRect()->setupFullAxesBox(true); ui->wvPlot->xAxis->setLabel("Time (ms)"); ui->wvPlot->yAxis->setLabel("Frequency (Hz)"); ui->wvPlot->yAxis->setRange(0,*std::max_element(freq.begin(),freq.end())); ui->wvPlot->xAxis->setRange(0,*std::max_element(time.begin(),time.end())); QCPColorMap *colormap = new QCPColorMap(ui->wvPlot->xAxis,ui->wvPlot->yAxis); - ui->wvPlot->axisRect(0)->setRangeZoom(Qt::Vertical); - ui->wvPlot->axisRect(0)->setRangeDrag(Qt::Vertical); +// ui->wvPlot->axisRect(0)->setRangeZoom(Qt::Vertical); +// ui->wvPlot->axisRect(0)->setRangeDrag(Qt::Vertical); colormap->data()->clear(); colormap->data()->setSize(tlength,N); colormap->data()->setRange(QCPRange(0,*std::max_element(time.begin(),time.end())),QCPRange(0,*std::max_element(freq.begin(),freq.end()))); @@ -476,7 +482,6 @@ void trace_ex::traceread(int trpos){ colormap->setGradient(QCPColorGradient::gpJet); colormap->rescaleDataRange(); ui->wvPlot->replot(); -// if(trpos!=1){colormap->data()->clear();} @@ -537,8 +542,8 @@ void trace_ex::traceread(int trpos){ trace[j]=sign*(1+mantissa)*pow(2,exponent-127); - time[j]=j;//just adding some bullshittime so we can plot something -// qDebug() << trace[j]; + time[j]=j*intsample*1e-3;//just adding the time vector + timeposi[j]=j*intsample*1e-3;//just adding the time vector tr_temp=0; exponent=0; @@ -547,6 +552,24 @@ void trace_ex::traceread(int trpos){ } + for(int j=0; j0 && trace[j+1]<0){ + traceposi[j]=0; + double yp=time[j+1]-trace[j+1]*(time[j+1]-time[j])/(trace[j+1]-trace[j]); + timeposi[j]=yp; + } + else if(trace[j-1] < 0 && trace[j] > 0){ + traceposi[j]=0; + double yp=time[j-1]-trace[j-1]*(time[j]-time[j-1])/(trace[j]-trace[j-1]); + timeposi[j]=yp; + } + else if(trace[j] > 0 && trace[j+1] > 0){ + traceposi[j]=0; + } + else{ + traceposi[j]=trace[j]; + } + } @@ -693,42 +716,43 @@ void trace_ex::traceread(int trpos){ - // This section plots the trace data------------------------------- - ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); - QPen pen; - pen.setStyle(Qt::SolidLine); - pen.setWidth(1); - pen.setColor(QColor(1,1,1)); - ui->tracePlot->graph(0)->setName("Trace"+QString::number(trpos)); - ui->tracePlot->graph(0)->setData(time,trace); //adding a graph - ui->tracePlot->xAxis->setLabel("Amplitude"); //adding labels - ui->tracePlot->yAxis->setLabel("Time (ms)"); - ui->tracePlot->graph(0)->setPen(pen); - ui->tracePlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); - ui->tracePlot->axisRect(0)->setRangeDrag(Qt::Vertical); - ui->tracePlot->axisRect(0)->setRangeZoom(Qt::Vertical); +// This section plots the trace data------------------------------- + ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); + QPen pen; + pen.setStyle(Qt::SolidLine); + pen.setWidth(1); + pen.setColor(QColor(1,1,1)); + ui->tracePlot->graph(0)->setName("Trace"+QString::number(trpos)); + ui->tracePlot->graph(0)->setData(time,trace); //adding a graph + ui->tracePlot->xAxis->setLabel("Amplitude"); //adding labels + ui->tracePlot->yAxis->setLabel("Time (ms)"); + ui->tracePlot->graph(0)->setPen(pen); + ui->tracePlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); + ui->tracePlot->axisRect(0)->setRangeDrag(Qt::Vertical); + ui->tracePlot->axisRect(0)->setRangeZoom(Qt::Vertical); - // // This section plots the trace data adding the blank trace to achieve the wiggle effect - ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); - QPen pennone; - pennone.setStyle(Qt::NoPen); - pennone.setWidth(1); - pennone.setColor(QColor(1,1,1)); - ui->tracePlot->graph(1)->setName("Trace"+QString::number(trpos)); - ui->tracePlot->graph(1)->setData(time,traceposi); //adding a graph - ui->tracePlot->graph(1)->setPen(pennone); +//// // This section plots the trace data adding the blank trace to achieve the wiggle effect + ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); + QPen pennone; + pennone.setStyle(Qt::NoPen); +// pennone.setStyle(Qt::SolidLine); + pennone.setWidth(1); + pennone.setColor(QColor(1,255,255,255)); + ui->tracePlot->graph(1)->setName("Trace"+QString::number(trpos)); + ui->tracePlot->graph(1)->setData(timeposi,traceposi); //adding a graph + ui->tracePlot->graph(1)->setPen(pennone); - ui->tracePlot->graph(1)->setBrush(QBrush(QColor(0,0,1))); - // ui->tracePlot->graph(0)->setChannelFillGraph(ui->tracePlot->graph(1)); + ui->tracePlot->graph(0)->setBrush(QBrush(QColor(0,0,1))); + ui->tracePlot->graph(0)->setChannelFillGraph(ui->tracePlot->graph(1)); - connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); - ui->tracePlot->yAxis->setRangeReversed(true); - ui->tracePlot->rescaleAxes(); - ui->tracePlot->replot(); - // This section plots the trace data-----------END----------------- + connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); + ui->tracePlot->yAxis->setRangeReversed(true); + ui->tracePlot->rescaleAxes(); + ui->tracePlot->replot(); +// This section plots the trace data-----------END----------------- @@ -784,56 +808,57 @@ void trace_ex::traceread(int trpos){ // Here we create sigh wich will contain the analytical signal (size of the array is a fft number) - std::complex sigh[N]={0,0}; - QVector WV(tlength*N); + std::complex sigh[N]={0,0}; + QVector WV(tlength*N); + + + for(int i=0;iwvPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); - ui->wvPlot->axisRect()->setupFullAxesBox(true); - ui->wvPlot->xAxis->setLabel("Time (ms)"); - ui->wvPlot->yAxis->setLabel("Frequency (Hz)"); - ui->wvPlot->yAxis->setRange(0,*std::max_element(freq.begin(),freq.end())); - ui->wvPlot->xAxis->setRange(0,*std::max_element(time.begin(),time.end())); - QCPColorMap *colormap = new QCPColorMap(ui->wvPlot->xAxis,ui->wvPlot->yAxis); - colormap->data()->clear(); - colormap->data()->setSize(tlength,N); - colormap->data()->setRange(QCPRange(0,*std::max_element(time.begin(),time.end())),QCPRange(0,*std::max_element(freq.begin(),freq.end()))); - - for(int t=0;tdata()->setCell(t,i,WV[t*N+i]); - colormap->data()->setCell(t,i,std::abs(WV[t*N+i])/amplNorm); - } - } + ui->wvPlot->axisRect()->setupFullAxesBox(true); + ui->wvPlot->xAxis->setLabel("Time (ms)"); + ui->wvPlot->yAxis->setLabel("Frequency (Hz)"); + ui->wvPlot->yAxis->setRange(0,*std::max_element(freq.begin(),freq.end())); + ui->wvPlot->xAxis->setRange(0,*std::max_element(time.begin(),time.end())); + QCPColorMap *colormap = new QCPColorMap(ui->wvPlot->xAxis,ui->wvPlot->yAxis); +// ui->wvPlot->axisRect(0)->setRangeZoom(Qt::Vertical); +// ui->wvPlot->axisRect(0)->setRangeDrag(Qt::Vertical); + colormap->data()->clear(); + colormap->data()->setSize(tlength,N); + colormap->data()->setRange(QCPRange(0,*std::max_element(time.begin(),time.end())),QCPRange(0,*std::max_element(freq.begin(),freq.end()))); - WV.clear(); + for(int t=0;tdata()->setCell(t,i,std::real(WV[t*N+i])); // This should be the real value - see papers. + colormap->data()->setCell(t,i,std::abs(WV[t*N+i])); //plotting the module of the amplitude instead of the amplitude of the real part looks better on the graph and normalizing the graph from 0 to 1. + } + } + WV.clear(); - QCPColorScale *colorScale = new QCPColorScale(ui->wvPlot); - ui->wvPlot->plotLayout()->addElement(0,1,colorScale); - colorScale->setType(QCPAxis::atRight); - colormap->setColorScale(colorScale); - colormap->setGradient(QCPColorGradient::gpJet); - colormap->rescaleDataRange(); - ui->wvPlot->replot(); - if(trpos!=1){colormap->data()->clear();} + QCPColorScale *colorScale = new QCPColorScale(ui->wvPlot); + ui->wvPlot->plotLayout()->addElement(0,1,colorScale); + colorScale->setType(QCPAxis::atRight); + colormap->setColorScale(colorScale); + colormap->setGradient(QCPColorGradient::gpJet); + colormap->rescaleDataRange(); + ui->wvPlot->replot(); @@ -860,7 +885,6 @@ trace_ex::trace_ex(QWidget *parent) : ui->horizontalSlider->setTracking(false); QFile f(modelname); QDataStream in(&f); -// f.open(QFile::ReadOnly|QFile::Text); f.open(QFile::ReadOnly); fillen=f.size(); qDebug() << fillen << tlength; @@ -885,13 +909,30 @@ void trace_ex::onYRangeChanged(const QCPRange &range) { QCPRange boundedRange = range; double lowerRangeBound = 0; + double upperRangeBound = tlength*intsample/(1.e3); + - if(boundedRange.lower < lowerRangeBound) { // restrict max zoom in + if(boundedRange.lower < lowerRangeBound || qFuzzyCompare(boundedRange.size(),upperRangeBound-lowerRangeBound)) { // restrict max zoom in boundedRange.lower = lowerRangeBound; boundedRange.upper = lowerRangeBound + boundedRange.size(); + if(boundedRange.upper > upperRangeBound){ + boundedRange.upper = upperRangeBound; + ui->wvPlot->xAxis->setRange(boundedRange); + } + } + else if(boundedRange.upper > upperRangeBound || qFuzzyCompare(boundedRange.size(),upperRangeBound-lowerRangeBound)) { // restrict max zoom in + boundedRange.upper = upperRangeBound; + boundedRange.lower = upperRangeBound - boundedRange.size(); + if(boundedRange.lower < lowerRangeBound){ + boundedRange.lower = lowerRangeBound; + ui->wvPlot->xAxis->setRange(boundedRange); + } } ui->tracePlot->yAxis->setRange(boundedRange); + ui->wvPlot->xAxis->setRange(boundedRange); + ui->wvPlot->replot(); + } @@ -899,13 +940,29 @@ void trace_ex::onspecXRangeChanged(const QCPRange &range) { QCPRange boundedRange = range; double lowerRangeBound = 0; + double upperRangeBound = 1.e6/(2.0*intsample); - if(boundedRange.lower < lowerRangeBound) { // restrict max zoom in + if(boundedRange.lower < lowerRangeBound || qFuzzyCompare(boundedRange.size(),upperRangeBound-lowerRangeBound)) { // restrict max zoom in boundedRange.lower = lowerRangeBound; boundedRange.upper = lowerRangeBound + boundedRange.size(); + if(boundedRange.upper > upperRangeBound){ + boundedRange.upper = upperRangeBound; + ui->wvPlot->yAxis->setRange(boundedRange); + } + } + + else if(boundedRange.upper > upperRangeBound || qFuzzyCompare(boundedRange.size(),upperRangeBound-lowerRangeBound)) { // restrict max zoom in + boundedRange.upper = upperRangeBound; + boundedRange.lower = upperRangeBound - boundedRange.size(); + if(boundedRange.lower < lowerRangeBound){ + boundedRange.lower = lowerRangeBound; + ui->wvPlot->yAxis->setRange(boundedRange); + } } ui->specPlot->xAxis->setRange(boundedRange); + ui->wvPlot->yAxis->setRange(boundedRange); + ui->wvPlot->replot(); } diff --git a/trace_group_ex.cpp b/trace_group_ex.cpp index e26936c..1fd3933 100644 --- a/trace_group_ex.cpp +++ b/trace_group_ex.cpp @@ -21,6 +21,7 @@ extern int inittr; extern int numtr; int grp_trpos; double grp_gain; +double grp_clip; int grp_numtr; quint32 grp_filepos; int grp_sign; @@ -40,16 +41,16 @@ trace_group_ex::trace_group_ex(QWidget *parent) : ui(new Ui::trace_group_ex) { ui->setupUi(this); - setWindowTitle("Trace view"); + setWindowTitle("Trace Group Explorer"); QFile f(modelname); QDataStream in(&f); f.open(QFile::ReadOnly); grp_fillen=f.size(); ui->spinBox->setMinimum(1); + ui->pushButton->setVisible(false); f.close(); - } @@ -61,30 +62,52 @@ trace_group_ex::trace_group_ex(QWidget *parent) : -void trace_group_ex::traceread(int grp_trpos, int grp_numtr){ + + + + +void trace_group_ex::traceread(int grp_trpos, int grp_numtr) +{ + + if(ui->spinBox->value()>(grp_fillen-3200-400)/(240+4*tlength)){ + ui->spinBox->setValue((grp_fillen-3200-400)/(240+4*tlength)); + } grp_trpos=ui->spinBox->value(); grp_numtr=ui->spinBox_2->value(); grp_gain=ui->spinBox_3->value(); + grp_clip=ui->spinBox_4->value(); + + if (grp_numtr + grp_trpos > (grp_fillen-3200-400)/(240+4*tlength)+1) { + grp_numtr = (grp_fillen-3200-400)/(240+4*tlength)-grp_trpos+1; + ui->spinBox_2->setValue(grp_numtr); + } +// qDebug() << "Entering trace read group" << grp_trpos << grp_numtr << (grp_fillen-3200-400)/(240+4*tlength)-1; + QFile f(modelname); f.open(QFile::ReadOnly); - QVector trace(tlength); //Initializing vector with trace - QVector time(tlength); //Initializing vector time axis + QVector trace(tlength),traceposi(tlength); //Initializing vector with trace + QVector time(tlength), timeposi(tlength); //Initializing vector time axis QPen pen; pen.setStyle(Qt::SolidLine); pen.setWidth(1); pen.setColor(QColor(1,1,1)); -// ui->tracePlot->graph(l)->setName("Trace"+QString::number(grp_trpos)); + QPen pennone; + pennone.setStyle(Qt::NoPen); + pennone.setWidth(1); + pennone.setColor(QColor(0,0,255,255)); + + ui->tracePlot->clearGraphs(); ui->tracePlot->yAxis->setLabel("Time (ms)"); //adding labels ui->tracePlot->xAxis->setVisible(false); for(int l=0;l0 && trace[j+1]<0){ + traceposi[j]=0; + double yp=time[j+1]-trace[j+1]*(time[j+1]-time[j])/(trace[j+1]-trace[j]); + timeposi[j]=yp; + } + else if(trace[j-1] < 0 && trace[j] > 0){ + traceposi[j]=0; + double yp=time[j-1]-trace[j-1]*(time[j]-time[j-1])/(trace[j]-trace[j-1]); + timeposi[j]=yp; + } + else if(trace[j] > 0 && trace[j+1] > 0){ + traceposi[j]=0; + } + else{ + traceposi[j]=trace[j]; + } + } + + for(int j=0; jtracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); - ui->tracePlot->graph(l)->setData(time,trace); //adding a graph - ui->tracePlot->graph(l)->setPen(pen); + ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); + qDebug() << l << 2*l << 2*l+1; + ui->tracePlot->graph(2*l)->setData(time,trace); //adding a graph + ui->tracePlot->graph(2*l)->setPen(pen); + + ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); + ui->tracePlot->graph(2*l+1)->setData(timeposi,traceposi); //adding a graph + ui->tracePlot->graph(2*l+1)->setPen(pennone); + + ui->tracePlot->graph(2*l)->setBrush(QBrush(QColor(0,0,1))); + ui->tracePlot->graph(2*l)->setChannelFillGraph(ui->tracePlot->graph(2*l+1)); + + + connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); + ui->tracePlot->yAxis->setRangeReversed(true); + + + + @@ -153,7 +222,7 @@ void trace_group_ex::traceread(int grp_trpos, int grp_numtr){ // This loop will make groups of 4 bytes int j =0; // for (int i = 0 ; i < 4*tlength ;i = i + 4) { - for (int i = 0 ; i < 4 ;i = i + 4) { + for (quint32 i = 0 ; i < 4 ;i = i + 4) { tr_group_temp.append(btrace[i]); tr_group_temp.append(btrace[i+1]); tr_group_temp.append(btrace[i+2]); @@ -185,6 +254,8 @@ void trace_group_ex::traceread(int grp_trpos, int grp_numtr){ trace[j]=grp_gain*grp_sign*(1+grp_mantissa)*pow(2,grp_exponent-127); time[j]=j*intsample*1e-3;//just adding the time vector + timeposi[j]=j*intsample*1e-3;//just adding the time vector + tr_group_temp=0; grp_exponent=0; @@ -193,41 +264,48 @@ void trace_group_ex::traceread(int grp_trpos, int grp_numtr){ } + for(int j=0; j0 && trace[j+1]<0){ + traceposi[j]=0; + double yp=time[j+1]-trace[j+1]*(time[j+1]-time[j])/(trace[j+1]-trace[j]); + timeposi[j]=yp; + } + else if(trace[j-1] < 0 && trace[j] > 0){ + traceposi[j]=0; + double yp=time[j-1]-trace[j-1]*(time[j]-time[j-1])/(trace[j]-trace[j-1]); + timeposi[j]=yp; + } + else if(trace[j] > 0 && trace[j+1] > 0){ + traceposi[j]=0; + } + else{ + traceposi[j]=trace[j]; + } + } + + for(int j=0; jtracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); - ui->tracePlot->graph(l)->setData(time,trace); //adding a graph - ui->tracePlot->graph(l)->setPen(QPen(Qt::blue)); - - - - - - - } // end 4-byte IEEE floating-point - else if (code==8){QByteArray btrace(f.read(tlength));} // 1-byte two's complement integer - - - - } - + ui->tracePlot->graph(2*l)->setData(time,trace); //adding a graph + ui->tracePlot->graph(2*l)->setPen(pen); - ui->tracePlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); - ui->tracePlot->axisRect(0)->setRangeDrag(Qt::Vertical|Qt::Horizontal); - ui->tracePlot->axisRect(0)->setRangeZoom(Qt::Vertical|Qt::Horizontal); - connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); - ui->tracePlot->rescaleAxes(); - ui->tracePlot->yAxis->setRangeReversed(true); - ui->tracePlot->replot(); - - -} + ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); + ui->tracePlot->graph(2*l+1)->setData(time,trace); //adding a graph + ui->tracePlot->graph(2*l+1)->setPen(pennone); + ui->tracePlot->graph(2*l)->setBrush(QBrush(QColor(0,0,1))); + ui->tracePlot->graph(2*l)->setChannelFillGraph(ui->tracePlot->graph(2*l+1)); + connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); + ui->tracePlot->yAxis->setRangeReversed(true); @@ -236,6 +314,8 @@ void trace_group_ex::traceread(int grp_trpos, int grp_numtr){ + } // end 4-byte IEEE floating-point + else if (code==8){QByteArray btrace(f.read(tlength));} // 1-byte two's complement integer @@ -245,11 +325,20 @@ void trace_group_ex::traceread(int grp_trpos, int grp_numtr){ + } + ui->tracePlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); + ui->tracePlot->axisRect(0)->setRangeDrag(Qt::Vertical|Qt::Horizontal); + ui->tracePlot->axisRect(0)->setRangeZoom(Qt::Vertical|Qt::Horizontal); + connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); + ui->tracePlot->rescaleAxes(); + ui->tracePlot->yAxis->setRangeReversed(true); + ui->tracePlot->replot(); +} @@ -285,11 +374,16 @@ void trace_group_ex::traceread(int grp_trpos, int grp_numtr){ void trace_group_ex::on_pushButton_clicked() { + if(ui->spinBox->value()>(grp_fillen-3200-400)/(240+4*tlength)){ + ui->spinBox->setValue((grp_fillen-3200-400)/(240+4*tlength)); + } + grp_trpos=ui->spinBox->value(); grp_numtr=ui->spinBox_2->value(); grp_gain=ui->spinBox_3->value(); + grp_clip=ui->spinBox_4->value(); - if (grp_numtr + grp_trpos >= (grp_fillen-3200-400)/(240+4*tlength)+1) { + if (grp_numtr + grp_trpos > (grp_fillen-3200-400)/(240+4*tlength)+1) { grp_numtr = (grp_fillen-3200-400)/(240+4*tlength)-grp_trpos+1; ui->spinBox_2->setValue(grp_numtr); } @@ -299,14 +393,18 @@ void trace_group_ex::on_pushButton_clicked() QFile f(modelname); f.open(QFile::ReadOnly); - QVector trace(tlength); //Initializing vector with trace - QVector time(tlength); //Initializing vector time axis + QVector trace(tlength),traceposi(tlength); //Initializing vector with trace + QVector time(tlength), timeposi(tlength); //Initializing vector time axis QPen pen; pen.setStyle(Qt::SolidLine); pen.setWidth(1); pen.setColor(QColor(1,1,1)); + QPen pennone; + pennone.setStyle(Qt::NoPen); + pennone.setWidth(1); + pennone.setColor(QColor(0,0,255,255)); ui->tracePlot->clearGraphs(); ui->tracePlot->yAxis->setLabel("Time (ms)"); //adding labels @@ -323,7 +421,7 @@ void trace_group_ex::on_pushButton_clicked() // This loop will make groups of 4 bytes int j =0; - for (int i = 0 ; i < 4*tlength ;i = i + 4) { + for (quint32 i = 0 ; i < 4*tlength ;i = i + 4) { tr_group_temp.append(btrace[i]); tr_group_temp.append(btrace[i+1]); tr_group_temp.append(btrace[i+2]); @@ -354,22 +452,59 @@ void trace_group_ex::on_pushButton_clicked() grp_exponent += (tr_group_temp.at(k)-48)*pow(2,6-k); } - trace[j]=grp_gain*(grp_sign*(grp_mantissa/2)*pow(16,grp_exponent-64))+l*1.000005; + trace[j]=grp_gain*(grp_sign*(grp_mantissa/2)*pow(16,grp_exponent-64)); time[j]=j*intsample*1e-3;//just adding the time vector -// qDebug() << l << j << trace[j] << grp_gain << grp_sign*(grp_mantissa/2)*pow(16,grp_exponent-64); + timeposi[j]=j*intsample*1e-3; + tr_group_temp=0; grp_exponent=0; grp_mantissa=0; j=j+1; } + for(int j=0; j0 && trace[j+1]<0){ + traceposi[j]=0; + double yp=time[j+1]-trace[j+1]*(time[j+1]-time[j])/(trace[j+1]-trace[j]); + timeposi[j]=yp; + } + else if(trace[j-1] < 0 && trace[j] > 0){ + traceposi[j]=0; + double yp=time[j-1]-trace[j-1]*(time[j]-time[j-1])/(trace[j]-trace[j-1]); + timeposi[j]=yp; + } + else if(trace[j] > 0 && trace[j+1] > 0){ + traceposi[j]=0; + } + else{ + traceposi[j]=trace[j]; + } + } + + for(int j=0; jtracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); - ui->tracePlot->graph(l)->setData(time,trace); //adding a graph - ui->tracePlot->graph(l)->setPen(pen); + ui->tracePlot->graph(2*l)->setData(time,trace); //adding a graph + ui->tracePlot->graph(2*l)->setPen(pen); + + ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); + ui->tracePlot->graph(2*l+1)->setData(timeposi,traceposi); //adding a graph + ui->tracePlot->graph(2*l+1)->setPen(pennone); + + + ui->tracePlot->graph(2*l)->setBrush(QBrush(QColor(0,0,1))); + ui->tracePlot->graph(2*l)->setChannelFillGraph(ui->tracePlot->graph(2*l+1)); + + connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); + ui->tracePlot->yAxis->setRangeReversed(true); + @@ -389,7 +524,7 @@ void trace_group_ex::on_pushButton_clicked() // This loop will make groups of 4 bytes int j =0; // for (int i = 0 ; i < 4*tlength ;i = i + 4) { - for (int i = 0 ; i < 4 ;i = i + 4) { + for (quint32 i = 0 ; i < 4 ;i = i + 4) { tr_group_temp.append(btrace[i]); tr_group_temp.append(btrace[i+1]); tr_group_temp.append(btrace[i+2]); @@ -419,8 +554,9 @@ void trace_group_ex::on_pushButton_clicked() } - trace[j]=trace[j]=grp_gain*grp_sign*(1+grp_mantissa)*pow(2,grp_exponent-127)+l*1.000005; + trace[j]=grp_gain*grp_sign*(1+grp_mantissa)*pow(2,grp_exponent-127); time[j]=j*intsample*1e-3;//just adding the time vector + timeposi[j]=j*intsample*1e-3;//just adding the time vector tr_group_temp=0; @@ -430,247 +566,174 @@ void trace_group_ex::on_pushButton_clicked() } + for(int j=0; j0 && trace[j+1]<0){ + traceposi[j]=0; + double yp=time[j+1]-trace[j+1]*(time[j+1]-time[j])/(trace[j+1]-trace[j]); + timeposi[j]=yp; + } + else if(trace[j-1] < 0 && trace[j] > 0){ + traceposi[j]=0; + double yp=time[j-1]-trace[j-1]*(time[j]-time[j-1])/(trace[j]-trace[j-1]); + timeposi[j]=yp; + } + else if(trace[j] > 0 && trace[j+1] > 0){ + traceposi[j]=0; + } + else{ + traceposi[j]=trace[j]; + } + } - // This section plots the trace data - ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); - ui->tracePlot->graph(l)->setData(time,trace); //adding a graph - ui->tracePlot->graph(l)->setPen(QPen(Qt::blue)); - - - - - } // end 4-byte IEEE floating-point - else if (code==8){QByteArray btrace(f.read(tlength));} // 1-byte two's complement integer + for(int j=0; jtracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); + ui->tracePlot->graph(2*l)->setData(time,trace); //adding a graph + ui->tracePlot->graph(2*l)->setPen(pen); - ui->tracePlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); - ui->tracePlot->axisRect(0)->setRangeDrag(Qt::Vertical|Qt::Horizontal); - ui->tracePlot->axisRect(0)->setRangeZoom(Qt::Vertical|Qt::Horizontal); - connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); - ui->tracePlot->rescaleAxes(); - ui->tracePlot->yAxis->setRangeReversed(true); - ui->tracePlot->replot(); + ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); + ui->tracePlot->graph(2*l+1)->setData(timeposi,traceposi); //adding a graph + ui->tracePlot->graph(2*l+1)->setPen(pennone); + ui->tracePlot->graph(2*l)->setBrush(QBrush(QColor(0,0,1))); + ui->tracePlot->graph(2*l)->setChannelFillGraph(ui->tracePlot->graph(2*l+1)); + connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); + ui->tracePlot->yAxis->setRangeReversed(true); -} + } // end 4-byte IEEE floating-point + else if (code==8){QByteArray btrace(f.read(tlength));} // 1-byte two's complement integer -void trace_group_ex::onYRangeChanged(const QCPRange &range) -{ - QCPRange boundedRange = range; - double lowerRangeBound = 0; - if(boundedRange.lower < lowerRangeBound) { // restrict max zoom in - boundedRange.lower = lowerRangeBound; - boundedRange.upper = lowerRangeBound + boundedRange.size(); - } - ui->tracePlot->yAxis->setRange(boundedRange); -} -void trace_group_ex::on_spinBox_3_editingFinished() -{ - grp_trpos=ui->spinBox->value(); - grp_numtr=ui->spinBox_2->value(); - grp_gain=ui->spinBox_3->value(); - if (grp_numtr + grp_trpos > (grp_fillen-3200-400)/(240+4*tlength)) { - grp_numtr = (grp_fillen-3200-400)/(240+4*tlength)-grp_trpos+1; - ui->spinBox_2->setValue(grp_numtr+1); } -// qDebug() << "Entering trace read group" << grp_trpos << grp_numtr << (grp_fillen-3200-400)/(240+4*tlength)-1; - - QFile f(modelname); - f.open(QFile::ReadOnly); - QVector trace(tlength); //Initializing vector with trace - QVector time(tlength); //Initializing vector time axis - - - QPen pen; - pen.setStyle(Qt::SolidLine); - pen.setWidth(1); - pen.setColor(QColor(1,1,1)); - - ui->tracePlot->clearGraphs(); - ui->tracePlot->yAxis->setLabel("Time (ms)"); //adding labels - ui->tracePlot->xAxis->setVisible(false); - - - for(int l=0;ltracePlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); + ui->tracePlot->axisRect(0)->setRangeDrag(Qt::Vertical|Qt::Horizontal); + ui->tracePlot->axisRect(0)->setRangeZoom(Qt::Vertical|Qt::Horizontal); + connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); +// ui->tracePlot->rescaleAxes(); + ui->tracePlot->yAxis->setRangeReversed(true); + ui->tracePlot->replot(); - trace[j]=grp_gain*(grp_sign*(grp_mantissa/2)*pow(16,grp_exponent-64))+l*1.000005; - time[j]=j*intsample*1e-3;//just adding the time vector +} - tr_group_temp=0; - grp_exponent=0; - grp_mantissa=0; - j=j+1; - } - // This section plots the trace data - ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); - ui->tracePlot->graph(l)->setData(time,trace); //adding a graph - ui->tracePlot->graph(l)->setPen(pen); - } // end 4-byte IBM floating point - else if (code==2){ - QByteArray btrace(f.read(4*tlength));}// 4-byte two's complement integer - else if (code==3){QByteArray trace(f.read(2*tlength));} // 2-byte two's complement integer - else if (code==4){QByteArray trace(f.read(4*tlength));} // 4-byte fixed-point with gain - else if (code==5){ // start 4-byte IEEE floating-point - QByteArray btrace(f.read(4*tlength)); - -// This loop will make groups of 4 bytes - int j =0; -// for (int i = 0 ; i < 4*tlength ;i = i + 4) { - for (int i = 0 ; i < 4 ;i = i + 4) { - tr_group_temp.append(btrace[i]); - tr_group_temp.append(btrace[i+1]); - tr_group_temp.append(btrace[i+2]); - tr_group_temp.append(btrace[i+3]); - tr_group_temp=QByteArray::number(tr_group_temp.toHex().toLongLong(nullptr,16),2); //converting the array to a binary 0,1 - while(tr_group_temp.length()<32) { - tr_group_temp.insert(0,"0"); // inserting leading zeroes - } - if(tr_group_temp.at(0)=='1') grp_sign =-1; else grp_sign=1; // if bit 0 is 1 number is negative - tr_group_temp.remove(0,1); //removing from element 0 with length 1 - // // remove grp_sign bit - - - - QByteArray fraction = tr_group_temp.right(23); //get the fractional part - grp_mantissa=0; - for(int i=0 ; i < 23; i++) { - // iterate through the fraction to claculate the grp_mantissa - if(fraction.at(i)=='1') grp_mantissa += 1.0/(pow(2,i)); - } - - grp_exponent=0; - - for(int i=0; i < tr_group_temp.length()-23; i++) { - // iterate through the array to calculate the grp_exponent - grp_exponent += (tr_group_temp.at(i)-48)*pow(2,7-i); - } - - - trace[j]=trace[j]=grp_gain*grp_sign*(1+grp_mantissa)*pow(2,grp_exponent-127)+l*1.000005; - time[j]=j*intsample*1e-3;//just adding the time vector - - - tr_group_temp=0; - grp_exponent=0; - grp_mantissa=0; - j=j+1; - } - +void trace_group_ex::onYRangeChanged(const QCPRange &range) +{ + QCPRange boundedRange = range; + double lowerRangeBound = 0; + double upperRangeBound = tlength*intsample/(1.e3); - // This section plots the trace data - ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis); - ui->tracePlot->graph(l)->setData(time,trace); //adding a graph - ui->tracePlot->graph(l)->setPen(QPen(Qt::blue)); + if(boundedRange.lower < lowerRangeBound || qFuzzyCompare(boundedRange.size(),upperRangeBound-lowerRangeBound)) { // restrict max zoom in + boundedRange.lower = lowerRangeBound; + boundedRange.upper = lowerRangeBound + boundedRange.size(); + if(boundedRange.upper > upperRangeBound){ + boundedRange.upper = upperRangeBound; + ui->tracePlot->yAxis->setRange(boundedRange); + } + } + else if(boundedRange.upper > upperRangeBound || qFuzzyCompare(boundedRange.size(),upperRangeBound-lowerRangeBound)) { // restrict max zoom in + boundedRange.upper = upperRangeBound; + boundedRange.lower = upperRangeBound - boundedRange.size(); + if(boundedRange.lower < lowerRangeBound){ + boundedRange.lower = lowerRangeBound; + ui->tracePlot->yAxis->setRange(boundedRange); + } + } + ui->tracePlot->yAxis->setRange(boundedRange); +} - } // end 4-byte IEEE floating-point - else if (code==8){QByteArray btrace(f.read(tlength));} // 1-byte two's complement integer - } +void trace_group_ex::on_spinBox_3_editingFinished() +{ +ui->pushButton->click(); +} - ui->tracePlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); - ui->tracePlot->axisRect(0)->setRangeDrag(Qt::Vertical|Qt::Horizontal); - ui->tracePlot->axisRect(0)->setRangeZoom(Qt::Vertical|Qt::Horizontal); - connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange))); -// ui->tracePlot->rescaleAxes(); - ui->tracePlot->yAxis->setRangeReversed(true); - ui->tracePlot->replot(); +void trace_group_ex::on_spinBox_editingFinished() +{ + ui->pushButton->click(); } +void trace_group_ex::on_spinBox_2_editingFinished() +{ + ui->pushButton->click(); +} +trace_group_ex::~trace_group_ex() +{ + delete ui; +} +//void trace_group_ex::on_spinBox_valueChanged(int arg1) +//{ +// ui->pushButton->click(); +//} +//void trace_group_ex::on_spinBox_2_valueChanged(int arg1) +//{ +// ui->pushButton->click(); +//} +//void trace_group_ex::on_spinBox_3_valueChanged(double arg1) +//{ +// ui->pushButton->click(); +//} - -trace_group_ex::~trace_group_ex() +void trace_group_ex::on_pushButton_2_clicked() { - delete ui; + ui->tracePlot->rescaleAxes(); + ui->tracePlot->replot(); } - diff --git a/trace_group_ex.h b/trace_group_ex.h index 2b24d5d..4d072e2 100644 --- a/trace_group_ex.h +++ b/trace_group_ex.h @@ -30,6 +30,12 @@ public slots: private slots: void on_pushButton_clicked(); void on_spinBox_3_editingFinished(); + void on_spinBox_2_editingFinished(); + void on_spinBox_editingFinished(); +// void on_spinBox_valueChanged(int arg1); +// void on_spinBox_2_valueChanged(int arg1); +// void on_spinBox_3_valueChanged(double arg1); + void on_pushButton_2_clicked(); }; #endif // TRACE_GROUP_EX_H