Results 1 to 2 of 2

Thread: QwtSpectogram "realtime" plotting

  1. #1
    Join Date
    Jan 2019
    Posts
    1

    Default QwtSpectogram "realtime" plotting

    Hello,

    first of all thanks for this great forum!
    I'm developing a program to modify audio data in "realtime".
    Actual I can plot different audio signals with curves, but for
    the next step I need a spectogram.
    I connected the data with QwtMatrixRasterData to QwtSpectogram.
    For Y-Axis I have 256 values, with the related Z-Axis value.
    Quantity of values for X-Axis depends on the TimerInterval.
    For now i use 500 values for 5 seconds (TimerInterval = 10ms).
    The QwtSpectrogram is a child of a QwtPlot which is a child of QSplitter.

    My actual problem is that QwtSpectrogram is only replotted if I shift the splitter.
    So I don't know why the "replot()" in the "timerEvent()" didn't work.
    I hope you can help me
    Thank you in advance!

    Christian Wagner



    Qt Code:
    1. SignalSpecDomainPlot::SignalSpecDomainPlot(tPlotData *pPlotData,
    2. QWidget *parent)
    3. : QwtPlot(parent)
    4. , d_interval(0)
    5. , d_timerId(-1)
    6. , d_timerCount(0)
    7. , mpPlotData(pPlotData)
    8. {
    9. d_spectrogram = new QwtPlotSpectrogram();
    10. d_spectrogram->setRenderThreadCount(0);
    11. d_spectrogram->setCachePolicy(QwtPlotRasterItem::PaintCache);
    12.  
    13. data = new QwtMatrixRasterData();
    14. data->setInterval(Qt::ZAxis, QwtInterval(-80, 20));
    15. data->setInterval(Qt::YAxis, QwtInterval(0, 256));
    16. data->setInterval(Qt::XAxis, QwtInterval(0, 500));
    17. data->setResampleMode(static_cast<QwtMatrixRasterData::ResampleMode>(1));
    18.  
    19. d_spectrogram->setData(data);
    20. d_spectrogram->attach(this);
    21.  
    22. /*-------------------------------------------------------------------------------*
    23. * Set axis
    24. *-------------------------------------------------------------------------------*/
    25. QwtText XAxisLabel;
    26. XAxisLabel.setText("Time [s]");
    27. setAxisTitle(QwtPlot::xBottom, XAxisLabel);
    28. setAxisScale(QwtPlot::xBottom, 0, 5);
    29.  
    30. QwtText YAxisLabel;
    31. YAxisLabel.setText("Frequency[kHz]");
    32. setAxisTitle(QwtPlot::yLeft, YAxisLabel);
    33. setAxisScale(QwtPlot::yLeft, 0, 8);
    34.  
    35. //color bar on the right axis
    36. QwtText Y2AxisLabel;
    37. QwtScaleWidget *rightAxis = axisWidget(QwtPlot::yRight);
    38. Y2AxisLabel.setText("Intensity[dB]");
    39. setAxisTitle(QwtPlot::yRight, Y2AxisLabel);
    40. setAxisScale(QwtPlot::yRight, -80, 20);
    41. rightAxis->setColorBarEnabled(true);
    42.  
    43. enableAxis(yLeft + yRight);
    44.  
    45. setColorMap(SignalSpecDomainPlot::RGBMap);
    46.  
    47. /*-------------------------------------------------------------------------------*
    48. * Set timer interval (in ms)
    49. *-------------------------------------------------------------------------------*/
    50. setTimerInterval(10.0);
    51. }
    52.  
    53. void SignalSpecDomainPlot::setTimerInterval(double ms)
    54. {
    55. d_interval = qRound(ms);
    56.  
    57. if (d_timerId >= 0)
    58. {
    59. killTimer(d_timerId);
    60. d_timerId = -1;
    61. }
    62. if (d_interval >= 0)
    63. d_timerId = startTimer(d_interval);
    64. }
    65.  
    66. void SignalSpecDomainPlot::timerEvent(QTimerEvent *)
    67. {
    68. if (d_timerCount == 0)
    69. {
    70. QVector<double> values;
    71. for (uint i = 0; i <= 500 * 256; i++)
    72. values += 0;
    73. data->setInterval(Qt::XAxis, QwtInterval(0, 5));
    74. data->setInterval(Qt::YAxis, QwtInterval(0, 8));
    75. data->setValueMatrix(values, 500);
    76. }
    77.  
    78. if(d_timerCount < 500)
    79. {
    80. d_timerCount++;
    81. }
    82. else
    83. {
    84. d_timerCount = 1;
    85. }
    86.  
    87. for(uint j = 0; j < 256; j++)
    88. {
    89. data->setValue(j, d_timerCount-1, mpPlotData->pppdFreqMemory[0][0][j]);
    90. }
    91.  
    92. if (d_timerCount % 100 == 0)
    93. {
    94. replot();
    95. }
    96. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtSpectogram "realtime" plotting

    When modifying data without telling the spectrogram ( = using setData ) you have to invalidate the internal pixmap cache: see https://qwt.sourceforge.io/class_qwt...6cfbd509ef65b5
    It is also possible to disable caching see: QwtPlotRasterItem::CachePolicy: see https://qwt.sourceforge.io/class_qwt...3b0f18289e4c7f

    Note, that there are some relevant improvements in Qwt >= 6.2 ( f.e https://sourceforge.net/p/qwt/code/H...nches/qwt-6.2/ )

    HTH,
    Uwe

Similar Threads

  1. Replies: 1
    Last Post: 20th November 2015, 11:02
  2. Replies: 3
    Last Post: 16th March 2015, 08:31
  3. Replies: 1
    Last Post: 5th May 2014, 08:49
  4. Replies: 4
    Last Post: 2nd June 2012, 08:04
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.