int main(){

	const int N = 32;		// Number of position domain samples
	RFFT<float> fft(N);		//
	float sig[N];			// Time/position domain signal
	float buf[N];			// Transform buffer
	
	// Create signal
	for(int i=0; i<N; ++i){
		float p = float(i)/N*M_2PI;
		sig[i] = 1 + cos(p) + cos(2*p) + sin(3*p);
		sig[i]+= i&1?-1:1;
	}
	
	// Copy signal to transform buffer
	for(int i=0; i<N; ++i) buf[i] = sig[i];

	// Perform real-to-complex forward transform
	fft.forward(buf);

	// Print out frequency domain samples
	int numBins = N/2 + 1;

	for(int i=0; i<numBins; ++i){
		Complex<float> c;
		if		(  0 == i)	c(buf[  0], 0);
		else if	(N/2 == i)	c(buf[N-1], 0);
		else				c(buf[i*2-1], buf[i*2]);
		
		printf("[%2d] ", i);
		printf("% 5.2f % 5.2f ", c[0], c[1]);
		printPlot(c[0], 32);
		printPlot(c[1], 32);
		printf("\n");
	}

	// Perform complex-to-real inverse transform
	fft.inverse(buf);

	// Print out original signal versus forward/inverse transformed signal
	printf("\n");
	for(int i=0; i<N; ++i){
		printf("[%2d] ", i);
		printf("% 5.2f % 5.2f ", sig[i], buf[i]);
		printPlot(sig[i]/5, 32);
		printPlot(buf[i]/5, 32);
		printf("\n");
	}
}
Beispiel #2
0
Plot3D::Plot3D(QWidget *parent, Data *dat) : QMainWindow(parent)
{
    // pointers
    data = dat;

    // create 3D surface
    setData();

    // design widget
    QToolBar *toolBar = new QToolBar(this);

    QToolButton *btnSpectrogram = new QToolButton(toolBar);
    QToolButton *btnContour = new QToolButton(toolBar);
    QToolButton *btnPrint = new QToolButton(toolBar);

    btnPrint->setText("Print");
    btnPrint->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    toolBar->addWidget(btnPrint);

    addToolBar(toolBar);

    connect(btnPrint, SIGNAL(clicked()), this, SLOT(printPlot()));

    btnSpectrogram->setChecked(true);
    btnContour->setChecked(false);
}
Beispiel #3
0
MainWindow::MainWindow( QWidget *parent ):
    QMainWindow( parent )
{
    d_plot = new Plot( this );

    setCentralWidget( d_plot );

    QToolBar *toolBar = new QToolBar( this );

#ifndef QT_NO_PRINTER
    QToolButton *btnPrint = new QToolButton( toolBar );
    btnPrint->setText( "Print" );
    btnPrint->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
    toolBar->addWidget( btnPrint );
    connect( btnPrint, SIGNAL( clicked() ),
        d_plot, SLOT( printPlot() ) );

    toolBar->addSeparator();
#endif

    toolBar->addWidget( new QLabel("Color Map " ) );
    QComboBox *mapBox = new QComboBox( toolBar );
    mapBox->addItem( "RGB" );
    mapBox->addItem( "Indexed Colors" );
    mapBox->addItem( "Hue" );
    mapBox->addItem( "Alpha" );
    mapBox->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
    toolBar->addWidget( mapBox );
    connect( mapBox, SIGNAL( currentIndexChanged( int ) ),
             d_plot, SLOT( setColorMap( int ) ) );

    toolBar->addWidget( new QLabel( " Opacity " ) );
    QSlider *slider = new QSlider( Qt::Horizontal );
    slider->setRange( 0, 255 );
    slider->setValue( 255 );
    connect( slider, SIGNAL( valueChanged( int ) ), 
        d_plot, SLOT( setAlpha( int ) ) );

    toolBar->addWidget( slider );
    toolBar->addWidget( new QLabel("   " ) );

    QCheckBox *btnSpectrogram = new QCheckBox( "Spectrogram", toolBar );
    toolBar->addWidget( btnSpectrogram );
    connect( btnSpectrogram, SIGNAL( toggled( bool ) ),
        d_plot, SLOT( showSpectrogram( bool ) ) );

    QCheckBox *btnContour = new QCheckBox( "Contour", toolBar );
    toolBar->addWidget( btnContour );
    connect( btnContour, SIGNAL( toggled( bool ) ),
        d_plot, SLOT( showContour( bool ) ) );

    addToolBar( toolBar );

    btnSpectrogram->setChecked( true );
    btnContour->setChecked( false );

}
Beispiel #4
0
    PlotTab( bool parametric,  QWidget *parent ):
        QMainWindow( parent )
    {
        Plot *plot = new Plot( parametric, this );
        setCentralWidget( plot );
    
        QToolBar *toolBar = new QToolBar( this );

#ifndef QT_NO_PRINTER
        ToolButton *btnPrint = new ToolButton( "Print", toolBar );
        toolBar->addWidget( btnPrint );
        QObject::connect( btnPrint, SIGNAL( clicked() ),
            plot, SLOT( printPlot() ) );
#endif
    
        ToolButton *btnOverlay = new ToolButton( "Overlay", toolBar );
        btnOverlay->setCheckable( true );
        toolBar->addWidget( btnOverlay );
        QObject::connect( btnOverlay, SIGNAL( toggled( bool ) ),
            plot, SLOT( setOverlaying( bool ) ) );
    
        if ( parametric )
        {
            QComboBox *parameterBox = new QComboBox( toolBar );

            parameterBox->addItem( "Uniform" );
            parameterBox->addItem( "Centripetral" );
            parameterBox->addItem( "Chordal" );
            parameterBox->addItem( "Manhattan" );
            toolBar->addWidget( parameterBox );
            connect( parameterBox, SIGNAL( activated( const QString & ) ),
                plot, SLOT( setParametric( const QString & ) ) );

            parameterBox->setCurrentIndex( 2 ); // chordal
            plot->setParametric( parameterBox->currentText() );

            ToolButton *btnClosed = new ToolButton( "Closed", toolBar );
            btnClosed->setCheckable( true );
            toolBar->addWidget( btnClosed );
            QObject::connect( btnClosed, SIGNAL( toggled( bool ) ),
                plot, SLOT( setClosed( bool ) ) );
        }

        QComboBox *boundaryBox = new QComboBox( toolBar );

        boundaryBox->addItem( "Natural" );
        boundaryBox->addItem( "Linear Runout" );
        boundaryBox->addItem( "Parabolic Runout" );
        boundaryBox->addItem( "Cubic Runout" );
        boundaryBox->addItem( "Not a Knot" );

        toolBar->addWidget( boundaryBox );
        connect( boundaryBox, SIGNAL( activated( const QString & ) ),
            plot, SLOT( setBoundaryCondition( const QString & ) ) );
    
        addToolBar( toolBar );
    }
Beispiel #5
0
int Plot::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QwtPlot::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: showContour((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 1: showSpectrogram((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 2: printPlot(); break;
        default: ;
        }
        _id -= 3;
    }
    return _id;
}
Beispiel #6
0
void PlotWindow::createActions()
{
  mpaToggleLogX = new QAction("Log &X", this);
  mpaToggleLogX->setCheckable(true);
  mpaToggleLogX->setToolTip("Toggle x-axis logscale.");
  connect(mpaToggleLogX, SIGNAL(toggled(bool)), this, SLOT(toggleLogX(bool)));

  mpaToggleLogY = new QAction("Log &Y", this);
  mpaToggleLogY->setCheckable(true);
  mpaToggleLogY->setToolTip("Toggle y-axis logscale.");
  connect(mpaToggleLogY, SIGNAL(toggled(bool)), this, SLOT(toggleLogY(bool)));

  mpaPrint = new QAction("Print", this);
  mpaPrint ->setToolTip("Print Plot");
  mpaPrint -> setShortcut(Qt::CTRL + Qt::Key_P);
  connect(mpaPrint, SIGNAL(triggered()), this, SLOT(printPlot()));

  mpaSaveImage = new QAction("Save Image", this);
  mpaSaveImage ->setShortcut(Qt::CTRL + Qt::Key_S);
  mpaSaveImage ->setToolTip("Save Plot as Image");
  connect(mpaSaveImage, SIGNAL(triggered()), this, SLOT(printAsImage()));

  mpaSaveData = new QAction("Save Data", this);
  mpaSaveData ->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_S);
  mpaSaveData ->setToolTip("Save Data");
  connect(mpaSaveData, SIGNAL(triggered()), this, SLOT(slotSaveData()));

  mpaZoomOut = new QAction("Zoom out", this);
  mpaZoomOut ->setShortcut(Qt::CTRL + Qt::Key_0);
  mpaZoomOut ->setToolTip("Zoom out");
  connect(mpaZoomOut, SIGNAL(triggered()), this, SLOT(slotZoomOut()));

  mpaShowAll = new QAction("Show All", this);
  mpaShowAll ->setShortcut(Qt::CTRL + Qt::Key_A);
  mpaShowAll ->setToolTip("Show all curves");
  connect(mpaShowAll, SIGNAL(triggered()), this, SLOT(slotSelectAll()));

  mpaHideAll = new QAction("Hide All", this);
  mpaHideAll ->setShortcut(Qt::CTRL + Qt::Key_D);
  mpaHideAll ->setToolTip("Hide all curves");
  connect(mpaHideAll, SIGNAL(triggered()), this, SLOT(slotDeselectAll()));

  mpaCloseWindow = new QAction("Close", this);
  mpaCloseWindow->setObjectName("close");
  mpaCloseWindow->setShortcut(Qt::CTRL + Qt::Key_W);
  connect(mpaCloseWindow, SIGNAL(triggered()), this, SLOT(slotCloseWindow()));
}
Beispiel #7
0
int main(){

	const int N = 16;			// Number of position domain samples
	CFFT<float> fft(N);			//
	Complex<float> sig[N];		// Time/position domain signal
	Complex<float> buf[N];		// Transform buffer

	// Create signal
	for(int i=0; i<N; ++i){
		float p = float(i)/N*M_2PI;
		sig[i] = 1;
		sig[i]+= Polar<float>(p);
		sig[i]+= Polar<float>(2*p);
	}
	
	// Copy signal to transform buffer
	for(int i=0; i<N; ++i) buf[i] = sig[i];

	// Perform forward transform
	fft.forward(buf);

	// Print out frequency domain samples
	for(int i=0; i<N; ++i){
		Complex<float> c = buf[i];
		
		printf("[%2d] ", i);
		printf("% 5.2f % 5.2f ", c[0], c[1]);
		printPlot(c[0], 32);
		printPlot(c[1], 32);
		printf("\n");
	}

	// Perform complex-to-real inverse transform
	fft.inverse(buf);

	// Print out original signal versus forward/inverse transformed signal
	printf("\n");
	for(int i=0; i<N; ++i){
		float sr = sig[i].r;
		float si = sig[i].i;
		float br = buf[i].r;
		float bi = buf[i].i;
		printf("[%2d] ", i);
		printf("(% 5.2f, % 5.2f) (% 5.2f, % 5.2f) ", sr, si, br, bi);
		printPlot(sr/3, 16); printPlot(si/3, 16);
		printPlot(br/3, 16); printPlot(bi/3, 16);
		printf("\n");
	}

	return 0;
}
Beispiel #8
0
MainWindow::MainWindow(QWidget *parent):
    QMainWindow(parent)
{
    d_plot = new Plot(this);

    setCentralWidget(d_plot);

    QToolBar *toolBar = new QToolBar(this);

    QToolButton *btnSpectrogram = new QToolButton(toolBar);
    QToolButton *btnContour = new QToolButton(toolBar);
    QToolButton *btnPrint = new QToolButton(toolBar);

#if QT_VERSION >= 0x040000
    btnSpectrogram->setText("Spectrogram");
    //btnSpectrogram->setIcon(QIcon());
    btnSpectrogram->setCheckable(true);
    btnSpectrogram->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    toolBar->addWidget(btnSpectrogram);

    btnContour->setText("Contour");
    //btnContour->setIcon(QIcon());
    btnContour->setCheckable(true);
    btnContour->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    toolBar->addWidget(btnContour);

	btnPrint->setText("Print");
    btnPrint->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    toolBar->addWidget(btnPrint);
#else
    btnSpectrogram->setTextLabel("Spectrogram");
    //btnSpectrogram->setPixmap(zoom_xpm);
    btnSpectrogram->setToggleButton(true);
    btnSpectrogram->setUsesTextLabel(true);

    btnContour->setTextLabel("Contour");
    //btnContour->setPixmap(zoom_xpm);
    btnContour->setToggleButton(true);
    btnContour->setUsesTextLabel(true);

    btnPrint->setTextLabel("Print");
    btnPrint->setUsesTextLabel(true);
#endif

    addToolBar(toolBar);

    connect(btnSpectrogram, SIGNAL(toggled(bool)), 
        d_plot, SLOT(showSpectrogram(bool)));
    connect(btnContour, SIGNAL(toggled(bool)), 
        d_plot, SLOT(showContour(bool)));
    connect(btnPrint, SIGNAL(clicked()), 
        d_plot, SLOT(printPlot()) );

#if QT_VERSION >= 0x040000
    btnSpectrogram->setChecked(true);
    btnContour->setChecked(false);
#else
    btnSpectrogram->setOn(true);
    btnContour->setOn(false);
#endif
}
Beispiel #9
0
  /**
   * Set up the menus for the ScatterPlotWindow.
   * Called from the constructor.
   */
  void ScatterPlotWindow::setupMenus(){
    p_menubar = p_scatterPlotWindow->menuBar();
    p_toolBar = new QToolBar(p_scatterPlotWindow);

    p_scatterPlotWindow->addToolBar(Qt::TopToolBarArea,p_toolBar);

    QAction *fitLine = new QAction(p_plot);
    fitLine->setText("Line Fit");
    fitLine->setIcon(QPixmap("/usgs/cpkgs/isis3/data/base/icons/linefit.png"));
    QObject::connect(fitLine, SIGNAL(activated()), this, SLOT(showContour()));

    p_colorize = new QAction(p_plot);
    p_colorize->setText("Colorize");
    p_colorize->setIcon(QPixmap("/usgs/cpkgs/isis3/data/base/icons/rgb.png"));
    QString text  =
      "Colorize";
    p_colorize->setWhatsThis(text);
    QObject::connect(p_colorize,SIGNAL(activated()),this,SLOT(colorPlot()));

    QAction *save = new QAction(p_plot);
    save->setText("&Save Plot As");
    save->setIcon(QPixmap("/usgs/cpkgs/isis3/data/base/icons/filesaveas.png"));
    text  =
      "<b>Function:</b>  Save the plot as a png, jpg, or tif file.";
    save->setWhatsThis(text);
    QObject::connect(save,SIGNAL(activated()),this,SLOT(savePlot()));

    QAction *prt = new QAction(p_plot);
    prt->setText("&Print Plot");
    prt->setIcon(QPixmap("/usgs/cpkgs/isis3/data/base/icons/fileprint.png"));
    text  =
      "<b>Function:</b>  Sends the plot image to the printer";
    prt->setWhatsThis(text);
    QObject::connect(prt,SIGNAL(activated()),this,SLOT(printPlot()));

    QAction *track = new QAction(p_plot);
    track->setText("Show Mouse &Tracking");
    track->setIcon(QPixmap("/usgs/cpkgs/isis3/data/base/icons/goto.png"));
    track->setCheckable(true);
    text  =
      "<b>Function:</b>  Displays the x,y coordinates as the cursor moves \
      around on the plot.";
    track->setWhatsThis(text);
    QObject::connect(track,SIGNAL(activated()),this,SLOT(trackerEnabled()));

    QAction *changeLabels = new QAction(p_plot);
    changeLabels->setText("Rename Plot &Labels");
    changeLabels->setIcon(QPixmap("/usgs/cpkgs/isis3/data/base/icons/plot_renameLabels.png"));
    text  =
      "<b>Function:</b>  Edit the plot title, x and y axis labels.";
    changeLabels->setWhatsThis(text);
    QObject::connect(changeLabels,SIGNAL(activated()),this,SLOT(reLabel()));

    QAction *changeScale = new QAction(p_plot);
    changeScale->setText("Set &Display Range");
    changeScale->setIcon(QPixmap("/usgs/cpkgs/isis3/data/base/icons/plot_setScale.png"));
    text  =
      "<b>Function:</b>  Adjust the scale for the x and y axis on the plot.";
    changeScale->setWhatsThis(text);
    QObject::connect(changeScale,SIGNAL(activated()),this, SLOT(setDisplayRange()));

    QAction *resetScaleButton = new QAction(p_plot);
    resetScaleButton->setText("Reset Scale");
    resetScaleButton->setIcon(QPixmap("/usgs/cpkgs/isis3/data/base/icons/plot_resetscale.png"));
    text  =
      "<b>Function:</b>  Reset the plot's scale.";
    resetScaleButton->setWhatsThis(text);
    QObject::connect(resetScaleButton, SIGNAL(activated()),this, SLOT(resetScale()));

    QAction *close = new QAction(p_plot);
    close->setText("Close");
    QObject::connect(close,SIGNAL(activated()),p_scatterPlotWindow, SLOT(close()));

    /*setup menus*/
    QMenu *options = new QMenu("&Options");
    options->addAction(track);
    options->addAction(changeLabels);
    options->addAction(changeScale);

    QMenu *file = new QMenu("&File");
    file->addAction(save);
    file->addAction(prt);
    file->addAction(close);

     p_menubar->addMenu(file);
     p_menubar->addMenu(options);
     
     p_toolBar->addAction(track);
     p_toolBar->addAction(changeLabels);
     p_toolBar->addAction(changeScale);
     p_toolBar->addAction(p_colorize);
     p_toolBar->addAction(fitLine);
  }
Beispiel #10
0
void createPlot( char * funcFile, double minX, double maxX) {
    int nvals = MAXCOLS;
    double yy[MAXCOLS];

    clearPlot();

    // Evaluate function and store in vector yy
    double n;
    //for (int i = minX; i <= maxX * (80 / (2.0 * maxX)); i++) {
    int count = 0;
    double step = (maxX - minX) / MAXCOLS;
    //printf("%lf\n" , step);
    for (double i = minX; count < 80; i = (i + step)) {
        //printf("Step %lf\n", i);
        yy[count] = rpn_eval(funcFile, i);
        count++;
        //printf("count: %d x: %lf y: %lf\n", count, i, yy[count - 1]);
    }

    //Compute maximum and minimum y in vector yy
    double maxY = yy[0];
    for (int i = 1; i < MAXCOLS; i++) {
        if (yy[i] > maxY)
            maxY = yy[i];
    }
    //printf("%lf\n", maxY);
    double minY = yy[0];
    for (int i = 1; i < MAXCOLS; i++) {
        if (yy[i] < minY)
            minY = yy[i];
    }
    //printf("%lf\n", minY);

    for (int i = 0; i < MAXCOLS; i++) {
        yy[i] = (yy[i] - minY) * (MAXROWS / (maxY - minY));
        //printf("x: %d y: %lf\n", i, yy[i]);
    }

    //Plot x axis
    //Plot y axis
    
    if (minY >= 0) {
        for (int i = 0; i < MAXROWS; i++) {
            for (int j = 0; j < MAXCOLS; j++) {
                if (i == 39) {
                    plot[i][j] = '_';
                } else if (j == 40) {
                    plot[i][j] = '|';
                }
            }
        }
    } else {
        for (int i = 0; i < MAXROWS; i++) {
            for (int j = 0; j < MAXCOLS; j++) {
                if (i == 19) {
                    plot[i][j] = '_';
                } else if (j == 40) {
                    plot[i][j] = '|';
                }
            }
        }
    }

    int yVal;
    for (int i = 0; i < 80; i++) {
        yVal = (int) yy[i];
        //printf("x: %d y: %d\n", i, yVal);
        if (yVal < 0) {
            yVal = yVal * -1;
            plot[yVal][i] = '*';
        } else {
            plot[39 - yVal][i] = '*';
        }
    }

    // minX is plotted at column 0 and maxX is plotted ar MAXCOLS-1
    // minY is plotted at row 0 and maxY is plotted at MAXROWS-1

    printPlot();

}