PDA

View Full Version : Help with changing axis scale with QwtSpectrogram



bubble
10th February 2014, 10:54
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:



...
d_spectrogram = new QwtPlotSpectrogram();
d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count

d_spectrogram->setColorMap( new ColorMap() );
d_spectrogram->setCachePolicy( QwtPlotRasterItem::PaintCache );

d_spectrogram->setData(new DSPFunc() );
d_spectrogram->attach(ui->tab_Visualization->ui->qwtPlot_dataView);

ui->tab_Visualization->ui->qwtPlot_dataView->replot();
...



Here is the header of the function:


class DSPFunc : public QwtRasterData
{

public:
DSPFunc();
virtual double value( double x, double y ) const;
};

#endif // DSPFUNC_H



Here is the code



DSPFunc::DSPFunc()
{

setInterval( Qt::XAxis, QwtInterval( 0.0, 1024.0 ) );
setInterval( Qt::YAxis, QwtInterval( 0.0, 256.0 ) );
setInterval( Qt::ZAxis, QwtInterval( 0.0, 10.0 ) );


}

double DSPFunc::value( double x, double y ) const
{




if ((y >= 0.0) && (y <= double(256)) && (x >= 0.0) && (x <= double(1024)))

return Abs[quint16(floor(x))][quint16(floor(y))];

else
return 0.0;
}



Here is the visualization part:



Visualization::Visualization(QWidget *parent) :
QDialog(parent),
ui(new Ui::Visualization)
{

ui->setupUi(this);

ui->qwtPlot_dataView->setAxisTitle(QwtPlot::yLeft, QwtText("FREQUENCY [Hz]"));
ui->qwtPlot_dataView->setAxisScale(QwtPlot::yLeft, -2560, 2560);
ui->qwtPlot_dataView->setAxisTitle(QwtPlot::xBottom, QwtText("TIME [µs]"));
ui->qwtPlot_dataView->setAxisScale(QwtPlot::xBottom, 0, 2048 );

}

Visualization::~Visualization()
{
delete ui;
}



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.

Uwe
11th February 2014, 21:31
X-AXIS: 0 to 2048us with step 2us
Y-AXIS: -2560 to 2560Hz with step 20Hz
Then you have to write:


DSPFunc::DSPFunc()
{
setInterval( Qt::XAxis, QwtInterval( 0.0, 2048.0 ) );
setInterval( Qt::YAxis, QwtInterval( -2560, 2560 ) );
}

and



double DSPFunc::value( double x, double y ) const
{
const int ix = x / 2;
const int iy = ( 2560 + y ) / 20;

if ( ix < 0 || iy < 0 || ... )
return qQNaN();

return Abs[ix][iy];
}

QRectF DspFunc::pixelHint( const QRectF & ) const
{
return QRectF( 0.0, 0.0, 2.0, 20.0 );
}