Results 1 to 2 of 2

Thread: Help with changing axis scale with QwtSpectrogram

  1. #1
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Help with changing axis scale with QwtSpectrogram

    Hello everybody!
    My name is Chris, I´m new here and would like to express my greatest gratitude to however can help me out as I´m stuck on something I´m not really good at.

    My problem: I just started using Qwt since 1 week.
    My specific problem:

    I have absolute values of a digital process stored in: extern long Abs[1024][256];
    I have 1024 values I want to plot on the X-Axis and 256 values on the Y-Axis, using the Spectrogram but I want them not to be scaled 0-1023 and 0-255 but with FREQUENCY and TIME, so

    X-AXIS: 0 to 2048us with step 2us
    Y-AXIS: -2560 to 2560Hz with step 20Hz

    In the GUI, the tab called Visualization is where I see my plot:

    Qt Code:
    1. ...
    2. d_spectrogram = new QwtPlotSpectrogram();
    3. d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count
    4.  
    5. d_spectrogram->setColorMap( new ColorMap() );
    6. d_spectrogram->setCachePolicy( QwtPlotRasterItem::PaintCache );
    7.  
    8. d_spectrogram->setData(new DSPFunc() );
    9. d_spectrogram->attach(ui->tab_Visualization->ui->qwtPlot_dataView);
    10.  
    11. ui->tab_Visualization->ui->qwtPlot_dataView->replot();
    12. ...
    To copy to clipboard, switch view to plain text mode 


    Here is the header of the function:

    Qt Code:
    1. class DSPFunc : public QwtRasterData
    2. {
    3.  
    4. public:
    5. DSPFunc();
    6. virtual double value( double x, double y ) const;
    7. };
    8.  
    9. #endif // DSPFUNC_H
    To copy to clipboard, switch view to plain text mode 


    Here is the code

    Qt Code:
    1. DSPFunc::DSPFunc()
    2. {
    3.  
    4. setInterval( Qt::XAxis, QwtInterval( 0.0, 1024.0 ) );
    5. setInterval( Qt::YAxis, QwtInterval( 0.0, 256.0 ) );
    6. setInterval( Qt::ZAxis, QwtInterval( 0.0, 10.0 ) );
    7.  
    8.  
    9. }
    10.  
    11. double DSPFunc::value( double x, double y ) const
    12. {
    13.  
    14.  
    15.  
    16.  
    17. if ((y >= 0.0) && (y <= double(256)) && (x >= 0.0) && (x <= double(1024)))
    18.  
    19. return Abs[quint16(floor(x))][quint16(floor(y))];
    20.  
    21. else
    22. return 0.0;
    23. }
    To copy to clipboard, switch view to plain text mode 


    Here is the visualization part:


    Qt Code:
    1. Visualization::Visualization(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::Visualization)
    4. {
    5.  
    6. ui->setupUi(this);
    7.  
    8. ui->qwtPlot_dataView->setAxisTitle(QwtPlot::yLeft, QwtText("FREQUENCY [Hz]"));
    9. ui->qwtPlot_dataView->setAxisScale(QwtPlot::yLeft, -2560, 2560);
    10. ui->qwtPlot_dataView->setAxisTitle(QwtPlot::xBottom, QwtText("TIME [µs]"));
    11. ui->qwtPlot_dataView->setAxisScale(QwtPlot::xBottom, 0, 2048 );
    12.  
    13. }
    14.  
    15. Visualization::~Visualization()
    16. {
    17. delete ui;
    18. }
    To copy to clipboard, switch view to plain text mode 



    Right now I see a plot that has the correct axis but data is not scaled correcty. I would like to know If I need to operate my changes on the
    values returned here:
    return Abs[quint16(floor(x))][quint16(floor(y))];

    and if so how would I need to proceed.

    Thanks and sorry for this simple and probably stupid question but Qwt is still a bit difficult for me and I really need help.

  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: Help with changing axis scale with QwtSpectrogram

    Quote Originally Posted by bubble View Post
    X-AXIS: 0 to 2048us with step 2us
    Y-AXIS: -2560 to 2560Hz with step 20Hz
    Then you have to write:

    Qt Code:
    1. DSPFunc::DSPFunc()
    2. {
    3. setInterval( Qt::XAxis, QwtInterval( 0.0, 2048.0 ) );
    4. setInterval( Qt::YAxis, QwtInterval( -2560, 2560 ) );
    5. }
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. double DSPFunc::value( double x, double y ) const
    2. {
    3. const int ix = x / 2;
    4. const int iy = ( 2560 + y ) / 20;
    5.  
    6. if ( ix < 0 || iy < 0 || ... )
    7. return qQNaN();
    8.  
    9. return Abs[ix][iy];
    10. }
    11.  
    12. QRectF DspFunc::pixelHint( const QRectF & ) const
    13. {
    14. return QRectF( 0.0, 0.0, 2.0, 20.0 );
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Uwe; 11th February 2014 at 22:36.

Similar Threads

  1. Replies: 1
    Last Post: 9th September 2013, 08:50
  2. Replies: 0
    Last Post: 18th January 2012, 08:41
  3. qwt axis scale
    By Markus_AC in forum Qwt
    Replies: 0
    Last Post: 15th December 2011, 10:45
  4. Replies: 4
    Last Post: 16th January 2011, 11:32
  5. Replies: 8
    Last Post: 25th April 2010, 22:19

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.