root / gr-qtgui / lib / spectrumdisplayform.cc @ c414f1ef
History | View | Annotate | Download (22.4 kB)
| 1 | /* -*- c++ -*- */
|
|---|---|
| 2 | /*
|
| 3 | * Copyright 2008-2011 Free Software Foundation, Inc. |
| 4 | * |
| 5 | * This file is part of GNU Radio |
| 6 | * |
| 7 | * GNU Radio is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * GNU Radio is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Radio; see the file COPYING. If not, write to |
| 19 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <cmath> |
| 24 | #include <QColorDialog> |
| 25 | #include <QMessageBox> |
| 26 | #include <spectrumdisplayform.h> |
| 27 | #include "qtgui_types.h" |
| 28 | |
| 29 | SpectrumDisplayForm::SpectrumDisplayForm(QWidget* parent) |
| 30 | : QWidget(parent) |
| 31 | {
|
| 32 | setupUi(this);
|
| 33 | |
| 34 | _systemSpecifiedFlag = false;
|
| 35 | _intValidator = new QIntValidator(this); |
| 36 | _intValidator->setBottom(0);
|
| 37 | _frequencyDisplayPlot = new FrequencyDisplayPlot(1, FrequencyPlotDisplayFrame); |
| 38 | _waterfallDisplayPlot = new WaterfallDisplayPlot(1, WaterfallPlotDisplayFrame); |
| 39 | _timeDomainDisplayPlot = new TimeDomainDisplayPlot(2, TimeDomainDisplayFrame); |
| 40 | _constellationDisplayPlot = new ConstellationDisplayPlot(1, ConstellationDisplayFrame); |
| 41 | _numRealDataPoints = 1024;
|
| 42 | _realFFTDataPoints = new double[_numRealDataPoints]; |
| 43 | _averagedValues = new double[_numRealDataPoints]; |
| 44 | _historyVector = new std::vector<double*>; |
| 45 | |
| 46 | _timeDomainDisplayPlot->setTitle(0, "real"); |
| 47 | _timeDomainDisplayPlot->setTitle(1, "imag"); |
| 48 | |
| 49 | AvgLineEdit->setRange(0, 500); // Set range of Average box value from 0 to 500 |
| 50 | MinHoldCheckBox_toggled( false );
|
| 51 | MaxHoldCheckBox_toggled( false );
|
| 52 | |
| 53 | WaterfallMaximumIntensitySlider->setRange(-200, 0); |
| 54 | WaterfallMinimumIntensitySlider->setRange(-200, 0); |
| 55 | WaterfallMinimumIntensitySlider->setValue(-200);
|
| 56 | |
| 57 | _peakFrequency = 0;
|
| 58 | _peakAmplitude = -HUGE_VAL; |
| 59 | |
| 60 | _noiseFloorAmplitude = -HUGE_VAL; |
| 61 | |
| 62 | connect(_waterfallDisplayPlot, SIGNAL(UpdatedLowerIntensityLevel(const double)), |
| 63 | _frequencyDisplayPlot, SLOT(SetLowerIntensityLevel(const double))); |
| 64 | connect(_waterfallDisplayPlot, SIGNAL(UpdatedUpperIntensityLevel(const double)), |
| 65 | _frequencyDisplayPlot, SLOT(SetUpperIntensityLevel(const double))); |
| 66 | |
| 67 | _frequencyDisplayPlot->SetLowerIntensityLevel(-200);
|
| 68 | _frequencyDisplayPlot->SetUpperIntensityLevel(-200);
|
| 69 | |
| 70 | // Load up the acceptable FFT sizes...
|
| 71 | FFTSizeComboBox->clear(); |
| 72 | for(long fftSize = SpectrumGUIClass::MIN_FFT_SIZE; fftSize <= SpectrumGUIClass::MAX_FFT_SIZE; fftSize *= 2){ |
| 73 | FFTSizeComboBox->insertItem(FFTSizeComboBox->count(), QString("%1").arg(fftSize));
|
| 74 | } |
| 75 | Reset(); |
| 76 | |
| 77 | ToggleTabFrequency(false);
|
| 78 | ToggleTabWaterfall(false);
|
| 79 | ToggleTabTime(false);
|
| 80 | ToggleTabConstellation(false);
|
| 81 | |
| 82 | _historyEntry = 0;
|
| 83 | _historyEntryCount = 0;
|
| 84 | |
| 85 | // Create a timer to update plots at the specified rate
|
| 86 | displayTimer = new QTimer(this); |
| 87 | connect(displayTimer, SIGNAL(timeout()), this, SLOT(UpdateGuiTimer()));
|
| 88 | |
| 89 | // Connect double click signals up
|
| 90 | connect(_frequencyDisplayPlot, SIGNAL(plotPointSelected(const QPointF)),
|
| 91 | this, SLOT(onFFTPlotPointSelected(const QPointF))); |
| 92 | |
| 93 | connect(_waterfallDisplayPlot, SIGNAL(plotPointSelected(const QPointF)),
|
| 94 | this, SLOT(onWFallPlotPointSelected(const QPointF))); |
| 95 | |
| 96 | connect(_timeDomainDisplayPlot, SIGNAL(plotPointSelected(const QPointF)),
|
| 97 | this, SLOT(onTimePlotPointSelected(const QPointF))); |
| 98 | |
| 99 | connect(_constellationDisplayPlot, SIGNAL(plotPointSelected(const QPointF)),
|
| 100 | this, SLOT(onConstPlotPointSelected(const QPointF))); |
| 101 | } |
| 102 | |
| 103 | SpectrumDisplayForm::~SpectrumDisplayForm() |
| 104 | {
|
| 105 | // Qt deletes children when parent is deleted
|
| 106 | |
| 107 | // Don't worry about deleting Display Plots - they are deleted when parents are deleted
|
| 108 | delete _intValidator;
|
| 109 | |
| 110 | delete[] _realFFTDataPoints;
|
| 111 | delete[] _averagedValues;
|
| 112 | |
| 113 | for(unsigned int count = 0; count < _historyVector->size(); count++){ |
| 114 | delete[] _historyVector->operator[](count); |
| 115 | } |
| 116 | |
| 117 | delete _historyVector;
|
| 118 | |
| 119 | displayTimer->stop(); |
| 120 | delete displayTimer;
|
| 121 | } |
| 122 | |
| 123 | void
|
| 124 | SpectrumDisplayForm::setSystem( SpectrumGUIClass * newSystem, |
| 125 | const uint64_t numFFTDataPoints,
|
| 126 | const uint64_t numTimeDomainDataPoints )
|
| 127 | {
|
| 128 | ResizeBuffers(numFFTDataPoints, numTimeDomainDataPoints); |
| 129 | |
| 130 | if(newSystem != NULL){ |
| 131 | _system = newSystem; |
| 132 | _systemSpecifiedFlag = true;
|
| 133 | } |
| 134 | else{
|
| 135 | _systemSpecifiedFlag = false;
|
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /***********************************************************************
|
| 140 | * This is kind of gross because we're combining three operations: |
| 141 | * Conversion from float to double (which is what the plotter wants) |
| 142 | * Finding the peak and mean |
| 143 | * Doing the "FFT shift" to put 0Hz at the center of the plot |
| 144 | * I feel like this might want to be part of the sink block |
| 145 | **********************************************************************/ |
| 146 | static void fftshift_and_sum(double *outFFT, const float *inFFT, uint64_t num_points, double &sum_mean, double &peak_ampl, int &peak_bin) { |
| 147 | const float* inptr = inFFT+num_points/2; |
| 148 | double* outptr = outFFT;
|
| 149 | |
| 150 | sum_mean = 0;
|
| 151 | peak_ampl = -HUGE_VAL; |
| 152 | peak_bin = 0;
|
| 153 | |
| 154 | // Run this twice to perform the fftshift operation on the data here as well
|
| 155 | for(uint64_t point = 0; point < num_points/2; point++){ |
| 156 | float pt = (*inptr);
|
| 157 | *outptr = pt; |
| 158 | if(*outptr > peak_ampl) {
|
| 159 | peak_bin = point; |
| 160 | peak_ampl = *outptr; |
| 161 | } |
| 162 | sum_mean += *outptr; |
| 163 | |
| 164 | inptr++; |
| 165 | outptr++; |
| 166 | } |
| 167 | |
| 168 | // This loop takes the first half of the input data and puts it in the
|
| 169 | // second half of the plotted data
|
| 170 | inptr = inFFT; |
| 171 | for(uint64_t point = 0; point < num_points/2; point++){ |
| 172 | float pt = (*inptr);
|
| 173 | *outptr = pt; |
| 174 | if(*outptr > peak_ampl) {
|
| 175 | peak_bin = point; |
| 176 | peak_ampl = *outptr; |
| 177 | } |
| 178 | sum_mean += *outptr; |
| 179 | |
| 180 | inptr++; |
| 181 | outptr++; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | void
|
| 186 | SpectrumDisplayForm::newFrequencyData( const SpectrumUpdateEvent* spectrumUpdateEvent)
|
| 187 | {
|
| 188 | //_lastSpectrumEvent = (SpectrumUpdateEvent)(*spectrumUpdateEvent);
|
| 189 | const float* fftMagDataPoints = spectrumUpdateEvent->getFFTPoints(); |
| 190 | const uint64_t numFFTDataPoints = spectrumUpdateEvent->getNumFFTDataPoints();
|
| 191 | const uint64_t numTimeDomainDataPoints = spectrumUpdateEvent->getNumTimeDomainDataPoints();
|
| 192 | const gruel::high_res_timer_type dataTimestamp = spectrumUpdateEvent->getDataTimestamp();
|
| 193 | const bool repeatDataFlag = spectrumUpdateEvent->getRepeatDataFlag(); |
| 194 | const bool lastOfMultipleUpdatesFlag = spectrumUpdateEvent->getLastOfMultipleUpdateFlag(); |
| 195 | const gruel::high_res_timer_type generatedTimestamp = spectrumUpdateEvent->getEventGeneratedTimestamp();
|
| 196 | double* realTimeDomainDataPoints = (double*)spectrumUpdateEvent->getRealTimeDomainPoints(); |
| 197 | double* imagTimeDomainDataPoints = (double*)spectrumUpdateEvent->getImagTimeDomainPoints(); |
| 198 | |
| 199 | std::vector<double*> timeDomainDataPoints;
|
| 200 | timeDomainDataPoints.push_back(realTimeDomainDataPoints); |
| 201 | timeDomainDataPoints.push_back(imagTimeDomainDataPoints); |
| 202 | |
| 203 | // REMEMBER: The dataTimestamp is NOT valid when the repeat data flag is true...
|
| 204 | ResizeBuffers(numFFTDataPoints, numTimeDomainDataPoints); |
| 205 | |
| 206 | const double fftBinSize = (_stopFrequency-_startFrequency) / |
| 207 | static_cast<double>(numFFTDataPoints); |
| 208 | |
| 209 | //this does the fftshift, conversion to double, and calculation of sum, peak amplitude, peak freq.
|
| 210 | double sum_mean, peak_ampl;
|
| 211 | int peak_bin;
|
| 212 | fftshift_and_sum(_realFFTDataPoints, fftMagDataPoints, numFFTDataPoints, sum_mean, peak_ampl, peak_bin); |
| 213 | double peak_freq = peak_bin * fftBinSize;
|
| 214 | |
| 215 | // Don't update the averaging history if this is repeated data
|
| 216 | if(!repeatDataFlag){
|
| 217 | _AverageHistory(_realFFTDataPoints); |
| 218 | |
| 219 | // Only use the local info if we are not repeating data
|
| 220 | _peakAmplitude = peak_ampl; |
| 221 | _peakFrequency = peak_freq; |
| 222 | |
| 223 | // calculate the spectral mean
|
| 224 | // +20 because for the comparison below we only want to throw out bins
|
| 225 | // that are significantly higher (and would, thus, affect the mean more)
|
| 226 | const double meanAmplitude = (sum_mean / numFFTDataPoints) + 20.0; |
| 227 | |
| 228 | // now throw out any bins higher than the mean
|
| 229 | sum_mean = 0.0; |
| 230 | uint64_t newNumDataPoints = numFFTDataPoints; |
| 231 | for(uint64_t number = 0; number < numFFTDataPoints; number++){ |
| 232 | if (_realFFTDataPoints[number] <= meanAmplitude)
|
| 233 | sum_mean += _realFFTDataPoints[number]; |
| 234 | else
|
| 235 | newNumDataPoints--; |
| 236 | } |
| 237 | |
| 238 | if (newNumDataPoints == 0) // in the odd case that all |
| 239 | _noiseFloorAmplitude = meanAmplitude; // amplitudes are equal!
|
| 240 | else
|
| 241 | _noiseFloorAmplitude = sum_mean / newNumDataPoints; |
| 242 | } |
| 243 | |
| 244 | if(lastOfMultipleUpdatesFlag){
|
| 245 | int tabindex = SpectrumTypeTab->currentIndex();
|
| 246 | if(tabindex == d_plot_fft) {
|
| 247 | _frequencyDisplayPlot->PlotNewData(_averagedValues, numFFTDataPoints, |
| 248 | _noiseFloorAmplitude, _peakFrequency, |
| 249 | _peakAmplitude, d_update_time); |
| 250 | } |
| 251 | if(tabindex == d_plot_time) {
|
| 252 | _timeDomainDisplayPlot->PlotNewData(timeDomainDataPoints, |
| 253 | numTimeDomainDataPoints, |
| 254 | d_update_time); |
| 255 | } |
| 256 | if(tabindex == d_plot_constellation) {
|
| 257 | _constellationDisplayPlot->PlotNewData(realTimeDomainDataPoints, |
| 258 | imagTimeDomainDataPoints, |
| 259 | numTimeDomainDataPoints, |
| 260 | d_update_time); |
| 261 | } |
| 262 | |
| 263 | // Don't update the repeated data for the waterfall
|
| 264 | if(!repeatDataFlag){
|
| 265 | if(tabindex == d_plot_waterfall) {
|
| 266 | _waterfallDisplayPlot->PlotNewData(_realFFTDataPoints, numFFTDataPoints, |
| 267 | d_update_time, dataTimestamp, |
| 268 | spectrumUpdateEvent->getDroppedFFTFrames()); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | // Tell the system the GUI has been updated
|
| 273 | if(_systemSpecifiedFlag){
|
| 274 | _system->SetLastGUIUpdateTime(generatedTimestamp); |
| 275 | _system->DecrementPendingGUIUpdateEvents(); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | void
|
| 281 | SpectrumDisplayForm::resizeEvent( QResizeEvent *e ) |
| 282 | {
|
| 283 | QSize s; |
| 284 | s.setWidth(FrequencyPlotDisplayFrame->width()); |
| 285 | s.setHeight(FrequencyPlotDisplayFrame->height()); |
| 286 | emit _frequencyDisplayPlot->resizeSlot(&s); |
| 287 | |
| 288 | s.setWidth(TimeDomainDisplayFrame->width()); |
| 289 | s.setHeight(TimeDomainDisplayFrame->height()); |
| 290 | emit _timeDomainDisplayPlot->resizeSlot(&s); |
| 291 | |
| 292 | s.setWidth(WaterfallPlotDisplayFrame->width()); |
| 293 | s.setHeight(WaterfallPlotDisplayFrame->height()); |
| 294 | emit _waterfallDisplayPlot->resizeSlot(&s); |
| 295 | |
| 296 | s.setWidth(ConstellationDisplayFrame->width()); |
| 297 | s.setHeight(ConstellationDisplayFrame->height()); |
| 298 | emit _constellationDisplayPlot->resizeSlot(&s); |
| 299 | } |
| 300 | |
| 301 | void
|
| 302 | SpectrumDisplayForm::customEvent( QEvent * e) |
| 303 | {
|
| 304 | if(e->type() == QEvent::User+3){ |
| 305 | if(_systemSpecifiedFlag){
|
| 306 | WindowComboBox->setCurrentIndex(_system->GetWindowType()); |
| 307 | FFTSizeComboBox->setCurrentIndex(_system->GetFFTSizeIndex()); |
| 308 | } |
| 309 | |
| 310 | waterfallMinimumIntensityChangedCB(WaterfallMinimumIntensitySlider->value()); |
| 311 | waterfallMaximumIntensityChangedCB(WaterfallMaximumIntensitySlider->value()); |
| 312 | |
| 313 | // Clear any previous display
|
| 314 | Reset(); |
| 315 | } |
| 316 | else if(e->type() == SpectrumUpdateEventType){ |
| 317 | SpectrumUpdateEvent* spectrumUpdateEvent = (SpectrumUpdateEvent*)e; |
| 318 | newFrequencyData(spectrumUpdateEvent); |
| 319 | } |
| 320 | else if(e->type() == SpectrumWindowCaptionEventType){ |
| 321 | setWindowTitle(((SpectrumWindowCaptionEvent*)e)->getLabel()); |
| 322 | } |
| 323 | else if(e->type() == SpectrumWindowResetEventType){ |
| 324 | Reset(); |
| 325 | if(_systemSpecifiedFlag){
|
| 326 | _system->ResetPendingGUIUpdateEvents(); |
| 327 | } |
| 328 | } |
| 329 | else if(e->type() == SpectrumFrequencyRangeEventType){ |
| 330 | _startFrequency = ((SpectrumFrequencyRangeEvent*)e)->GetStartFrequency(); |
| 331 | _stopFrequency = ((SpectrumFrequencyRangeEvent*)e)->GetStopFrequency(); |
| 332 | _centerFrequency = ((SpectrumFrequencyRangeEvent*)e)->GetCenterFrequency(); |
| 333 | |
| 334 | UseRFFrequenciesCB(UseRFFrequenciesCheckBox->isChecked()); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | void
|
| 339 | SpectrumDisplayForm::UpdateGuiTimer() |
| 340 | {
|
| 341 | // This is called by the displayTimer and redraws the canvases of
|
| 342 | // all of the plots.
|
| 343 | _frequencyDisplayPlot->canvas()->update(); |
| 344 | _waterfallDisplayPlot->canvas()->update(); |
| 345 | _timeDomainDisplayPlot->canvas()->update(); |
| 346 | _constellationDisplayPlot->canvas()->update(); |
| 347 | } |
| 348 | |
| 349 | |
| 350 | void
|
| 351 | SpectrumDisplayForm::AvgLineEdit_valueChanged( int value )
|
| 352 | {
|
| 353 | SetAverageCount(value); |
| 354 | } |
| 355 | |
| 356 | |
| 357 | void
|
| 358 | SpectrumDisplayForm::MaxHoldCheckBox_toggled( bool newState )
|
| 359 | {
|
| 360 | MaxHoldResetBtn->setEnabled(newState); |
| 361 | _frequencyDisplayPlot->SetMaxFFTVisible(newState); |
| 362 | MaxHoldResetBtn_clicked(); |
| 363 | } |
| 364 | |
| 365 | |
| 366 | void
|
| 367 | SpectrumDisplayForm::MinHoldCheckBox_toggled( bool newState )
|
| 368 | {
|
| 369 | MinHoldResetBtn->setEnabled(newState); |
| 370 | _frequencyDisplayPlot->SetMinFFTVisible(newState); |
| 371 | MinHoldResetBtn_clicked(); |
| 372 | } |
| 373 | |
| 374 | |
| 375 | void
|
| 376 | SpectrumDisplayForm::MinHoldResetBtn_clicked() |
| 377 | {
|
| 378 | _frequencyDisplayPlot->ClearMinData(); |
| 379 | _frequencyDisplayPlot->replot(); |
| 380 | } |
| 381 | |
| 382 | |
| 383 | void
|
| 384 | SpectrumDisplayForm::MaxHoldResetBtn_clicked() |
| 385 | {
|
| 386 | _frequencyDisplayPlot->ClearMaxData(); |
| 387 | _frequencyDisplayPlot->replot(); |
| 388 | } |
| 389 | |
| 390 | |
| 391 | void
|
| 392 | SpectrumDisplayForm::TabChanged(int index)
|
| 393 | {
|
| 394 | // This might be dangerous to call this with NULL
|
| 395 | resizeEvent(NULL);
|
| 396 | } |
| 397 | |
| 398 | void
|
| 399 | SpectrumDisplayForm::SetFrequencyRange(const double newCenterFrequency, |
| 400 | const double newStartFrequency, |
| 401 | const double newStopFrequency) |
| 402 | {
|
| 403 | double fdiff;
|
| 404 | if(UseRFFrequenciesCheckBox->isChecked()) {
|
| 405 | fdiff = newCenterFrequency; |
| 406 | } |
| 407 | else {
|
| 408 | fdiff = std::max(fabs(newStartFrequency), fabs(newStopFrequency)); |
| 409 | } |
| 410 | |
| 411 | if(fdiff > 0) { |
| 412 | std::string strunits[4] = {"Hz", "kHz", "MHz", "GHz"}; |
| 413 | std::string strtime[4] = {"sec", "ms", "us", "ns"}; |
| 414 | double units10 = floor(log10(fdiff));
|
| 415 | double units3 = std::max(floor(units10 / 3.0), 0.0); |
| 416 | double units = pow(10, (units10-fmod(units10, 3.0))); |
| 417 | int iunit = static_cast<int>(units3); |
| 418 | |
| 419 | _startFrequency = newStartFrequency; |
| 420 | _stopFrequency = newStopFrequency; |
| 421 | _centerFrequency = newCenterFrequency; |
| 422 | |
| 423 | _frequencyDisplayPlot->SetFrequencyRange(_startFrequency, |
| 424 | _stopFrequency, |
| 425 | _centerFrequency, |
| 426 | UseRFFrequenciesCheckBox->isChecked(), |
| 427 | units, strunits[iunit]); |
| 428 | _waterfallDisplayPlot->SetFrequencyRange(_startFrequency, |
| 429 | _stopFrequency, |
| 430 | _centerFrequency, |
| 431 | UseRFFrequenciesCheckBox->isChecked(), |
| 432 | units, strunits[iunit]); |
| 433 | _timeDomainDisplayPlot->SetSampleRate(_stopFrequency - _startFrequency, |
| 434 | units, strtime[iunit]); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | int
|
| 439 | SpectrumDisplayForm::GetAverageCount() |
| 440 | {
|
| 441 | return _historyVector->size();
|
| 442 | } |
| 443 | |
| 444 | void
|
| 445 | SpectrumDisplayForm::SetAverageCount(const int newCount) |
| 446 | {
|
| 447 | if(newCount > -1){ |
| 448 | if(newCount != static_cast<int>(_historyVector->size())){ |
| 449 | std::vector<double*>::iterator pos;
|
| 450 | while(newCount < static_cast<int>(_historyVector->size())){ |
| 451 | pos = _historyVector->begin(); |
| 452 | delete[] (*pos);
|
| 453 | _historyVector->erase(pos); |
| 454 | } |
| 455 | |
| 456 | while(newCount > static_cast<int>(_historyVector->size())){ |
| 457 | _historyVector->push_back(new double[_numRealDataPoints]); |
| 458 | } |
| 459 | AverageDataReset(); |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | void
|
| 465 | SpectrumDisplayForm::_AverageHistory(const double* newBuffer) |
| 466 | {
|
| 467 | if(_numRealDataPoints > 0){ |
| 468 | if(_historyVector->size() > 0){ |
| 469 | memcpy(_historyVector->operator[](_historyEntry), newBuffer,
|
| 470 | _numRealDataPoints*sizeof(double)); |
| 471 | |
| 472 | // Increment the next location to store data
|
| 473 | _historyEntryCount++; |
| 474 | if(_historyEntryCount > static_cast<int>(_historyVector->size())){ |
| 475 | _historyEntryCount = _historyVector->size(); |
| 476 | } |
| 477 | _historyEntry += 1;
|
| 478 | _historyEntry = _historyEntry % _historyVector->size(); |
| 479 | |
| 480 | // Total up and then average the values
|
| 481 | double sum;
|
| 482 | for(uint64_t location = 0; location < _numRealDataPoints; location++){ |
| 483 | sum = 0;
|
| 484 | for(int number = 0; number < _historyEntryCount; number++){ |
| 485 | sum += _historyVector->operator[](number)[location];
|
| 486 | } |
| 487 | _averagedValues[location] = sum/static_cast<double>(_historyEntryCount); |
| 488 | } |
| 489 | } |
| 490 | else{
|
| 491 | memcpy(_averagedValues, newBuffer, _numRealDataPoints*sizeof(double)); |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | void
|
| 497 | SpectrumDisplayForm::ResizeBuffers( const uint64_t numFFTDataPoints,
|
| 498 | const uint64_t /*numTimeDomainDataPoints*/ ) |
| 499 | {
|
| 500 | // Convert from Complex to Real for certain Displays
|
| 501 | if(_numRealDataPoints != numFFTDataPoints){
|
| 502 | _numRealDataPoints = numFFTDataPoints; |
| 503 | delete[] _realFFTDataPoints;
|
| 504 | delete[] _averagedValues;
|
| 505 | |
| 506 | _realFFTDataPoints = new double[_numRealDataPoints]; |
| 507 | _averagedValues = new double[_numRealDataPoints]; |
| 508 | memset(_realFFTDataPoints, 0x0, _numRealDataPoints*sizeof(double)); |
| 509 | |
| 510 | const int historySize = _historyVector->size(); |
| 511 | SetAverageCount(0); // Clear the existing history |
| 512 | SetAverageCount(historySize); |
| 513 | |
| 514 | Reset(); |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | void
|
| 519 | SpectrumDisplayForm::Reset() |
| 520 | {
|
| 521 | AverageDataReset(); |
| 522 | |
| 523 | _waterfallDisplayPlot->Reset(); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | void
|
| 528 | SpectrumDisplayForm::AverageDataReset() |
| 529 | {
|
| 530 | _historyEntry = 0;
|
| 531 | _historyEntryCount = 0;
|
| 532 | |
| 533 | memset(_averagedValues, 0x0, _numRealDataPoints*sizeof(double)); |
| 534 | |
| 535 | MaxHoldResetBtn_clicked(); |
| 536 | MinHoldResetBtn_clicked(); |
| 537 | } |
| 538 | |
| 539 | |
| 540 | void
|
| 541 | SpectrumDisplayForm::closeEvent( QCloseEvent *e ) |
| 542 | {
|
| 543 | if(_systemSpecifiedFlag){
|
| 544 | _system->SetWindowOpenFlag(false);
|
| 545 | } |
| 546 | |
| 547 | qApp->processEvents(); |
| 548 | |
| 549 | QWidget::closeEvent(e); //equivalent to e->accept()
|
| 550 | } |
| 551 | |
| 552 | |
| 553 | void
|
| 554 | SpectrumDisplayForm::WindowTypeChanged( int newItem )
|
| 555 | {
|
| 556 | if(_systemSpecifiedFlag){
|
| 557 | _system->SetWindowType(newItem); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | |
| 562 | void
|
| 563 | SpectrumDisplayForm::UseRFFrequenciesCB( bool useRFFlag )
|
| 564 | {
|
| 565 | SetFrequencyRange(_centerFrequency, _startFrequency, _stopFrequency); |
| 566 | } |
| 567 | |
| 568 | |
| 569 | void
|
| 570 | SpectrumDisplayForm::waterfallMaximumIntensityChangedCB( double newValue )
|
| 571 | {
|
| 572 | if(newValue > WaterfallMinimumIntensitySlider->value()){
|
| 573 | WaterfallMaximumIntensityLabel->setText(QString("%1 dB").arg(newValue, 0, 'f', 0)); |
| 574 | } |
| 575 | else{
|
| 576 | WaterfallMinimumIntensitySlider->setValue(newValue - 2);
|
| 577 | } |
| 578 | |
| 579 | _waterfallDisplayPlot->SetIntensityRange(WaterfallMinimumIntensitySlider->value(), |
| 580 | WaterfallMaximumIntensitySlider->value()); |
| 581 | } |
| 582 | |
| 583 | |
| 584 | void
|
| 585 | SpectrumDisplayForm::waterfallMinimumIntensityChangedCB( double newValue )
|
| 586 | {
|
| 587 | if(newValue < WaterfallMaximumIntensitySlider->value()){
|
| 588 | WaterfallMinimumIntensityLabel->setText(QString("%1 dB").arg(newValue, 0, 'f', 0)); |
| 589 | } |
| 590 | else{
|
| 591 | WaterfallMaximumIntensitySlider->setValue(newValue + 2);
|
| 592 | } |
| 593 | |
| 594 | _waterfallDisplayPlot->SetIntensityRange(WaterfallMinimumIntensitySlider->value(), |
| 595 | WaterfallMaximumIntensitySlider->value()); |
| 596 | } |
| 597 | |
| 598 | void
|
| 599 | SpectrumDisplayForm::FFTComboBoxSelectedCB( const QString &fftSizeString )
|
| 600 | {
|
| 601 | if(_systemSpecifiedFlag){
|
| 602 | _system->SetFFTSize(fftSizeString.toLong()); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | |
| 607 | void
|
| 608 | SpectrumDisplayForm::WaterfallAutoScaleBtnCB() |
| 609 | {
|
| 610 | double minimumIntensity = _noiseFloorAmplitude - 5; |
| 611 | if(minimumIntensity < WaterfallMinimumIntensitySlider->minValue()){
|
| 612 | minimumIntensity = WaterfallMinimumIntensitySlider->minValue(); |
| 613 | } |
| 614 | WaterfallMinimumIntensitySlider->setValue(minimumIntensity); |
| 615 | double maximumIntensity = _peakAmplitude + 10; |
| 616 | if(maximumIntensity > WaterfallMaximumIntensitySlider->maxValue()){
|
| 617 | maximumIntensity = WaterfallMaximumIntensitySlider->maxValue(); |
| 618 | } |
| 619 | WaterfallMaximumIntensitySlider->setValue(maximumIntensity); |
| 620 | waterfallMaximumIntensityChangedCB(maximumIntensity); |
| 621 | } |
| 622 | |
| 623 | void
|
| 624 | SpectrumDisplayForm::WaterfallIntensityColorTypeChanged( int newType )
|
| 625 | {
|
| 626 | QColor lowIntensityColor; |
| 627 | QColor highIntensityColor; |
| 628 | if(newType == INTENSITY_COLOR_MAP_TYPE_USER_DEFINED){
|
| 629 | // Select the Low Intensity Color
|
| 630 | lowIntensityColor = _waterfallDisplayPlot->GetUserDefinedLowIntensityColor(); |
| 631 | if(!lowIntensityColor.isValid()){
|
| 632 | lowIntensityColor = Qt::black; |
| 633 | } |
| 634 | QMessageBox::information(this, "Low Intensity Color Selection", "In the next window, select the low intensity color for the waterfall display", QMessageBox::Ok); |
| 635 | lowIntensityColor = QColorDialog::getColor(lowIntensityColor, this);
|
| 636 | |
| 637 | // Select the High Intensity Color
|
| 638 | highIntensityColor = _waterfallDisplayPlot->GetUserDefinedHighIntensityColor(); |
| 639 | if(!highIntensityColor.isValid()){
|
| 640 | highIntensityColor = Qt::white; |
| 641 | } |
| 642 | QMessageBox::information(this, "High Intensity Color Selection", "In the next window, select the high intensity color for the waterfall display", QMessageBox::Ok); |
| 643 | highIntensityColor = QColorDialog::getColor(highIntensityColor, this);
|
| 644 | } |
| 645 | |
| 646 | _waterfallDisplayPlot->SetIntensityColorMapType(0, newType, lowIntensityColor, highIntensityColor);
|
| 647 | } |
| 648 | |
| 649 | void
|
| 650 | SpectrumDisplayForm::ToggleTabFrequency(const bool state) |
| 651 | {
|
| 652 | if(state == true) { |
| 653 | if(d_plot_fft == -1) { |
| 654 | SpectrumTypeTab->addTab(FrequencyPage, "Frequency Display");
|
| 655 | d_plot_fft = SpectrumTypeTab->count()-1;
|
| 656 | } |
| 657 | } |
| 658 | else {
|
| 659 | SpectrumTypeTab->removeTab(SpectrumTypeTab->indexOf(FrequencyPage)); |
| 660 | d_plot_fft = -1;
|
| 661 | } |
| 662 | } |
| 663 | |
| 664 | void
|
| 665 | SpectrumDisplayForm::ToggleTabWaterfall(const bool state) |
| 666 | {
|
| 667 | if(state == true) { |
| 668 | if(d_plot_waterfall == -1) { |
| 669 | SpectrumTypeTab->addTab(WaterfallPage, "Waterfall Display");
|
| 670 | d_plot_waterfall = SpectrumTypeTab->count()-1;
|
| 671 | } |
| 672 | } |
| 673 | else {
|
| 674 | SpectrumTypeTab->removeTab(SpectrumTypeTab->indexOf(WaterfallPage)); |
| 675 | d_plot_waterfall = -1;
|
| 676 | } |
| 677 | } |
| 678 | |
| 679 | void
|
| 680 | SpectrumDisplayForm::ToggleTabTime(const bool state) |
| 681 | {
|
| 682 | if(state == true) { |
| 683 | if(d_plot_time == -1) { |
| 684 | SpectrumTypeTab->addTab(TimeDomainPage, "Time Domain Display");
|
| 685 | d_plot_time = SpectrumTypeTab->count()-1;
|
| 686 | } |
| 687 | } |
| 688 | else {
|
| 689 | SpectrumTypeTab->removeTab(SpectrumTypeTab->indexOf(TimeDomainPage)); |
| 690 | d_plot_time = -1;
|
| 691 | } |
| 692 | } |
| 693 | |
| 694 | void
|
| 695 | SpectrumDisplayForm::ToggleTabConstellation(const bool state) |
| 696 | {
|
| 697 | if(state == true) { |
| 698 | if(d_plot_constellation == -1) { |
| 699 | SpectrumTypeTab->addTab(ConstellationPage, "Constellation Display");
|
| 700 | d_plot_constellation = SpectrumTypeTab->count()-1;
|
| 701 | } |
| 702 | } |
| 703 | else {
|
| 704 | SpectrumTypeTab->removeTab(SpectrumTypeTab->indexOf(ConstellationPage)); |
| 705 | d_plot_constellation = -1;
|
| 706 | } |
| 707 | } |
| 708 | |
| 709 | |
| 710 | void
|
| 711 | SpectrumDisplayForm::SetTimeDomainAxis(double min, double max) |
| 712 | {
|
| 713 | _timeDomainDisplayPlot->setYaxis(min, max); |
| 714 | } |
| 715 | |
| 716 | void
|
| 717 | SpectrumDisplayForm::SetConstellationAxis(double xmin, double xmax, |
| 718 | double ymin, double ymax) |
| 719 | {
|
| 720 | _constellationDisplayPlot->set_axis(xmin, xmax, ymin, ymax); |
| 721 | } |
| 722 | |
| 723 | void
|
| 724 | SpectrumDisplayForm::SetConstellationPenSize(int size)
|
| 725 | {
|
| 726 | _constellationDisplayPlot->set_pen_size( size ); |
| 727 | } |
| 728 | |
| 729 | void
|
| 730 | SpectrumDisplayForm::SetFrequencyAxis(double min, double max) |
| 731 | {
|
| 732 | _frequencyDisplayPlot->set_yaxis(min, max); |
| 733 | } |
| 734 | |
| 735 | void
|
| 736 | SpectrumDisplayForm::SetUpdateTime(double t)
|
| 737 | {
|
| 738 | d_update_time = t; |
| 739 | // QTimer class takes millisecond input
|
| 740 | displayTimer->start(d_update_time*1000);
|
| 741 | } |
| 742 | |
| 743 | void
|
| 744 | SpectrumDisplayForm::onFFTPlotPointSelected(const QPointF p)
|
| 745 | {
|
| 746 | emit plotPointSelected(p, 1);
|
| 747 | } |
| 748 | |
| 749 | void
|
| 750 | SpectrumDisplayForm::onWFallPlotPointSelected(const QPointF p)
|
| 751 | {
|
| 752 | emit plotPointSelected(p, 2);
|
| 753 | } |
| 754 | |
| 755 | void
|
| 756 | SpectrumDisplayForm::onTimePlotPointSelected(const QPointF p)
|
| 757 | {
|
| 758 | emit plotPointSelected(p, 3);
|
| 759 | } |
| 760 | |
| 761 | void
|
| 762 | SpectrumDisplayForm::onConstPlotPointSelected(const QPointF p)
|
| 763 | {
|
| 764 | emit plotPointSelected(p, 4);
|
| 765 | } |