X-Git-Url: https://git.gag.com/?p=debian%2Fgnuradio;a=blobdiff_plain;f=gr-qtgui%2Fsrc%2Flib%2FFrequencyDisplayPlot.cc;fp=gr-qtgui%2Fsrc%2Flib%2FFrequencyDisplayPlot.cc;h=f2cde322efd1569f2ccaf8d1a5c46bee6fdebb5a;hp=154c8d2341a62fea73fae9e9ed6f7fc87e076b07;hb=35e43e8d8c271e6842191cac3fc3f2f88a861183;hpb=ea29b08aeb54227e6628f655ccfdb96fe4d8c378 diff --git a/gr-qtgui/src/lib/FrequencyDisplayPlot.cc b/gr-qtgui/src/lib/FrequencyDisplayPlot.cc index 154c8d23..f2cde322 100644 --- a/gr-qtgui/src/lib/FrequencyDisplayPlot.cc +++ b/gr-qtgui/src/lib/FrequencyDisplayPlot.cc @@ -73,13 +73,22 @@ public: updateDisplay(); } + void SetUnitType(const std::string &type) + { + _unitType = type; + } + protected: virtual QwtText trackerText( const QwtDoublePoint& p ) const { - QwtText t(QString("%1 %2, %3 dB").arg(p.x(), 0, 'f', GetFrequencyPrecision()).arg( (GetFrequencyPrecision() == 0) ? "Hz" : "kHz").arg(p.y(), 0, 'f', 2)); - + QwtText t(QString("%1 %2, %3 dB"). + arg(p.x(), 0, 'f', GetFrequencyPrecision()). + arg(_unitType.c_str()).arg(p.y(), 0, 'f', 2)); return t; } + +private: + std::string _unitType; }; FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) @@ -91,9 +100,7 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) timespec_reset(&_lastReplot); resize(parent->width(), parent->height()); - - _displayIntervalTime = (1.0/10.0); // 1/10 of a second between updates - + _useCenterFrequencyFlag = false; _numPoints = 1024; @@ -113,9 +120,8 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) palette.setColor(canvas()->backgroundRole(), QColor("white")); canvas()->setPalette(palette); - setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(0)); - setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency); setAxisTitle(QwtPlot::xBottom, "Frequency (Hz)"); + setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(0)); _minYAxis = -120; _maxYAxis = 10; @@ -148,7 +154,7 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) _upper_intensity_marker = new QwtPlotMarker(); _upper_intensity_marker->setLineStyle(QwtPlotMarker::HLine); - _upper_intensity_marker->setLinePen(QPen(Qt::green)); + _upper_intensity_marker->setLinePen(QPen(Qt::green, 0, Qt::DotLine)); _upper_intensity_marker->attach(this); memset(_dataPoints, 0x0, _numPoints*sizeof(double)); @@ -159,9 +165,6 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) _maxFFTPoints[number] = -280.0; } - _resetXAxisPoints(); - - // set up peak marker QwtSymbol symbol; @@ -211,6 +214,9 @@ FrequencyDisplayPlot::FrequencyDisplayPlot(QWidget* parent) const QColor c(Qt::darkRed); _zoomer->setRubberBandPen(c); _zoomer->setTrackerPen(c); + + // Do this after the zoomer has been built + _resetXAxisPoints(); } FrequencyDisplayPlot::~FrequencyDisplayPlot() @@ -256,20 +262,26 @@ FrequencyDisplayPlot::SetFrequencyRange(const double constStartFreq, stopFreq = (stopFreq + centerFreq); } - _startFrequency = startFreq; - _stopFrequency = stopFreq; - _resetXAxisPoints(); - - setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency); - setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(2)); - setAxisTitle(QwtPlot::xBottom, QString("Frequency (%1)").arg(strunits.c_str())); - ((FreqDisplayZoomer*)_zoomer)->SetFrequencyPrecision(2); - - // Load up the new base zoom settings - _zoomer->setZoomBase(); - - // Zooms back to the base and clears any other zoom levels - _zoomer->zoom(0); + bool reset = false; + if((startFreq != _startFrequency) || (stopFreq != _stopFrequency)) + reset = true; + + if(stopFreq > startFreq) { + _startFrequency = startFreq; + _stopFrequency = stopFreq; + + if((axisScaleDraw(QwtPlot::xBottom) != NULL) && (_zoomer != NULL)){ + double display_units = ceil(log10(units)/2.0); + setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(display_units)); + setAxisTitle(QwtPlot::xBottom, QString("Frequency (%1)").arg(strunits.c_str())); + + if(reset) + _resetXAxisPoints(); + + ((FreqDisplayZoomer*)_zoomer)->SetFrequencyPrecision(display_units); + ((FreqDisplayZoomer*)_zoomer)->SetUnitType(strunits); + } + } } @@ -288,8 +300,6 @@ FrequencyDisplayPlot::GetStopFrequency() const void FrequencyDisplayPlot::replot() { - const timespec startTime = get_highres_clock(); - _markerNoiseFloorAmplitude->setYValue(_noiseFloorAmplitude); // Make sure to take into account the start frequency @@ -302,26 +312,26 @@ FrequencyDisplayPlot::replot() _markerPeakAmplitude->setYValue(_peakAmplitude); QwtPlot::replot(); - - double differenceTime = (diff_timespec(get_highres_clock(), startTime)); - - differenceTime *= 99.0; - // Require at least a 10% duty cycle - if(differenceTime > (1.0/10.0)){ - _displayIntervalTime = differenceTime; - } +} + +void +FrequencyDisplayPlot::resizeSlot( QSize *s ) +{ + resize(s->width(), s->height()); } void FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDataPoints, const double noiseFloorAmplitude, const double peakFrequency, - const double peakAmplitude) + const double peakAmplitude, const double timeInterval) { - if(numDataPoints > 0){ - - if(numDataPoints != _numPoints){ + // Only update plot if there is data and if the time interval has elapsed + if((numDataPoints > 0) && + (diff_timespec(get_highres_clock(), _lastReplot) > timeInterval)) { + + if(numDataPoints != _numPoints) { _numPoints = numDataPoints; - + delete[] _dataPoints; delete[] _minFFTPoints; delete[] _maxFFTPoints; @@ -334,11 +344,12 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat _fft_plot_curve->setRawData(_xAxisPoints, _dataPoints, _numPoints); _min_fft_plot_curve->setRawData(_xAxisPoints, _minFFTPoints, _numPoints); _max_fft_plot_curve->setRawData(_xAxisPoints, _maxFFTPoints, _numPoints); - + _resetXAxisPoints(); ClearMaxData(); ClearMinData(); } + memcpy(_dataPoints, dataPoints, numDataPoints*sizeof(double)); for(int64_t point = 0; point < numDataPoints; point++){ if(dataPoints[point] < _minFFTPoints[point]){ @@ -353,14 +364,10 @@ FrequencyDisplayPlot::PlotNewData(const double* dataPoints, const int64_t numDat _peakFrequency = peakFrequency; _peakAmplitude = peakAmplitude; - } + SetUpperIntensityLevel(_peakAmplitude); - // Allow at least a 50% duty cycle - if(diff_timespec(get_highres_clock(), _lastReplot) > _displayIntervalTime){ - // Only replot the screen if it is visible - if(isVisible()){ - replot(); - } + replot(); + _lastReplot = get_highres_clock(); } } @@ -369,7 +376,7 @@ void FrequencyDisplayPlot::ClearMaxData() { for(int64_t number = 0; number < _numPoints; number++){ - _maxFFTPoints[number] = _maxYAxis; + _maxFFTPoints[number] = _minYAxis; } } @@ -377,7 +384,7 @@ void FrequencyDisplayPlot::ClearMinData() { for(int64_t number = 0; number < _numPoints; number++){ - _minFFTPoints[number] = _minYAxis; + _minFFTPoints[number] = _maxYAxis; } } @@ -402,6 +409,17 @@ FrequencyDisplayPlot::_resetXAxisPoints() _xAxisPoints[loc] = freqValue; freqValue += fft_bin_size; } + + setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency); + + // Set up zoomer base for maximum unzoom x-axis + // and reset to maximum unzoom level + QwtDoubleRect zbase = _zoomer->zoomBase(); + zbase.setLeft(_startFrequency); + zbase.setRight(_stopFrequency); + _zoomer->zoom(zbase); + _zoomer->setZoomBase(zbase); + _zoomer->zoom(0); } void