commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r4553 - gnuradio/branches/developers/n4hy/qt/gr-qtgui/


From: n4hy
Subject: [Commit-gnuradio] r4553 - gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib
Date: Tue, 20 Feb 2007 20:39:56 -0700 (MST)

Author: n4hy
Date: 2007-02-20 20:39:55 -0700 (Tue, 20 Feb 2007)
New Revision: 4553

Modified:
   gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/Makefile.am
   gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/fftdisplay.cc
   gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/fftdisplay.h
   gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/qt_examples.cc
Log:
FFT Display progress

Modified: gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/Makefile.am   
2007-02-20 23:48:33 UTC (rev 4552)
+++ gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/Makefile.am   
2007-02-21 03:39:55 UTC (rev 4553)
@@ -21,8 +21,21 @@
 
 include $(top_srcdir)/Makefile.common
 
-INCLUDES= $(QT_CFLAGS) $(QWT_CFLAGS) 
+INCLUDES = $(STD_DEFINES_AND_INCLUDES) \
+          $(QT_CFLAGS)                 \
+          $(QWT_CFLAGS) 
 
+# This rule lets GNU create any moc_*.cc files from the equivalent *.h
+moc_%.cc: %.h
+       moc $< -o $@
+
+# Generate the .h and .cc files from the .ui file
+%.h: %.ui
+       uic $< -o $@
+
+%.cc: %.ui
+       uic -impl $*.h $< -o $@
+
 include_HEADERS =
        fftdisplay.h                    \
        fftdisplaysink.h
@@ -30,9 +43,13 @@
 noinst_PROGRAMS =                      \
        qt_examples     
 
+qt_examples_MOC =                      \
+       moc_fftdisplay.cc
+
 qt_examples_SOURCES =                  \
-       fftdisplay.cc                   \
-       qt_examples.cc
+       fftdisplay.cc                   \
+       qt_examples.cc                  \
+       $(qt_examples_MOC)
 
 qt_examples_LDADD = $(QWT_LIBS) $(QT_LIBS)
 qt_examples_LDFLAGS = $(QT_CFLAGS) $(QWT_CFLAGS)

Modified: gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/fftdisplay.cc
===================================================================
--- gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/fftdisplay.cc 
2007-02-20 23:48:33 UTC (rev 4552)
+++ gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/fftdisplay.cc 
2007-02-21 03:39:55 UTC (rev 4553)
@@ -1,14 +1,95 @@
 #ifndef FFT_DISPLAY_CC
 #define FFT_DISPLAY_CC
 
+#include <qwt_painter.h>
+#include <qwt_plot_canvas.h>
+#include <qapplication.h>
 #include <fftdisplay.h>
 
-fft_display::fft_display(){
+const int fft_display_event::EVENT_TYPE_ID = QEvent::User+100;
 
+fft_display_event::fft_display_event():QCustomEvent(fft_display_event::EVENT_TYPE_ID){
+
 }
 
+fft_display_event::~fft_display_event(){
+
+}
+
+
+fft_display::fft_display(const unsigned int fftSize, QWidget* parent):
+       QwtPlot(parent)
+{
+       // Disable polygon clipping
+       QwtPainter::setDeviceClipping(false);
+
+       // We don't need the cache here
+       canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
+       canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
+
+       d_plot_data.resize(fftSize+1);
+       for( unsigned int i = 0; i < fftSize+1; i++){
+               d_plot_data[i] = 0.0;
+       }
+       
+       d_start_frequency = 0.0;
+       d_stop_frequency = 4000.0;
+
+       setTitle("Spectral Display");
+}
+
 fft_display::~fft_display(){
+}
 
+
+void fft_display::set_data(const std::vector<gr_complex>& input_data){
+       unsigned int min_points = d_plot_data.size();
+       if(min_points < input_data.size()){
+               min_points = input_data.size();
+       }
+       for(unsigned int point = 0; point < min_points; point++){
+               d_plot_data[point] = input_data[point];
+       }
 }
 
+void fft_display::update_display(){
+
+       // Tell the event loop to display the new data - the event loop handles 
deleting this object
+       qApp->postEvent(this, new fft_display_event());
+
+}
+
+void fft_display::customEvent(QCustomEvent* e){
+       if(e->type() == fft_display_event::EVENT_TYPE_ID){
+               // Write out the FFT data to the display here
+               printf("HEY GOT THE EVENT\n");
+
+               // Axis 
+               setAxisTitle(QwtPlot::xBottom, "Frequency (Hz)");
+               setAxisScale(QwtPlot::xBottom, get_start_frequency(), 
get_stop_frequency());
+
+               setAxisTitle(QwtPlot::yLeft, "Values");
+               setAxisScale(QwtPlot::yLeft, -1.5, 1.5);
+
+               replot();
+       }
+}
+
+void fft_display::set_start_frequency(const float new_freq){
+       d_start_frequency = new_freq;
+}
+
+float fft_display::get_start_frequency()const{
+       return d_start_frequency;
+}
+
+void fft_display::set_stop_frequency(const float new_freq){
+       d_stop_frequency = new_freq;
+}
+
+float fft_display::get_stop_frequency()const{
+       return d_stop_frequency;
+}
+
+
 #endif /* FFT_DISPLAY_CC */

Modified: gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/fftdisplay.h
===================================================================
--- gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/fftdisplay.h  
2007-02-20 23:48:33 UTC (rev 4552)
+++ gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/fftdisplay.h  
2007-02-21 03:39:55 UTC (rev 4553)
@@ -1,14 +1,51 @@
 #ifndef FFT_DISPLAY_H
 #define FFT_DISPLAY_H
 
-class fft_display{
-public:        
-       fft_display();
-       ~fft_display();
+#include <gr_complex.h>
+
+#include <vector>
+
+#include <qwidget.h>
+#include <qwt_plot.h>
+#include <qevent.h>
+
+class fft_display_event:public QCustomEvent{
+public:
+       fft_display_event();
+       ~fft_display_event();
+
+       static const int EVENT_TYPE_ID;
 protected:
 
 private:
 
 };
 
+class fft_display:public QwtPlot{
+       Q_OBJECT
+public:        
+       fft_display(const unsigned int, QWidget* = ((QWidget*)0));
+       virtual ~fft_display();
+
+       virtual void customEvent(QCustomEvent*);
+
+       void set_start_frequency(const float);
+       float get_start_frequency()const;
+
+       void set_stop_frequency(const float);
+       float get_stop_frequency()const;
+
+public slots:
+       virtual void set_data( const std::vector<gr_complex>& );
+       virtual void update_display();
+
+protected:
+
+private:
+       std::vector<gr_complex> d_plot_data;
+       unsigned int d_fft_bin_size;
+       float d_start_frequency;
+       float d_stop_frequency;
+};
+
 #endif /* FFT_DISPLAY_H */

Modified: gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/qt_examples.cc
===================================================================
--- gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/qt_examples.cc        
2007-02-20 23:48:33 UTC (rev 4552)
+++ gnuradio/branches/developers/n4hy/qt/gr-qtgui/src/lib/qt_examples.cc        
2007-02-21 03:39:55 UTC (rev 4553)
@@ -1,43 +1,59 @@
 #include <stdio.h>
+#include <unistd.h>
 
 #include <qapplication.h>
-#include <qwt_plot.h>
-#include <qwt_plot_curve.h>
+#include <vector>
 
 #include <fftdisplay.h>
 
 int main (int argc, char* argv[]){
+       extern char* optarg;
+       extern int optind, optopt;
+       float start_frequency = 0.0;
+       float stop_frequency = 4000.0;
+       int c;
 
+       const unsigned int FFT_SIZE = 1024;
+
+       while ((c = getopt(argc, argv, "s:p:")) != -1){
+               switch(c){
+               case 's': start_frequency = strtod(optarg, NULL); break;
+               case 'p': stop_frequency = strtod(optarg, NULL); break;
+               case ':': /* -s or -p w/o operand */
+               fprintf(stderr, "Option -%c requires an arguement\n", optopt); 
break;
+               case '?': fprintf(stderr, "Unrecognized option: -%c\n", 
optopt); exit(-1); break;
+               }
+       }
+
+       // Verify the stop frequency is greater than the stop frequency
+       if(stop_frequency < start_frequency){
+               fprintf(stderr, "Stop Frequency (%0.0f Hz) was less than the 
Start Frequency (%0.0f Hz)\n", stop_frequency, start_frequency);
+               exit(-1);
+       }
+
        // Create the QApplication - this MUST be done before ANY QObjects are 
created
        QApplication* qApp = new QApplication(argc, argv);
 
-       fft_display* fftDisplay = new fft_display();
+       // Set up the thread to read the data from stdin
+       fft_display* fftDisplay = new fft_display(FFT_SIZE); // No Parent 
Specified
 
-       QwtPlot *myPlot;        
-       double x[100], y1[100], y2[100];        // x and y values
-       
-       myPlot = new QwtPlot(QwtText("Two Curves"), ((QWidget*)0)); // No 
Parent Value
- 
-       // add curves
-       QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
-       QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
-       
-       for(int number = 0; number < 100; number++){
-         x[number] = static_cast<double>(number);
-         y1[number] = pow(-1, static_cast<double>(number))*1000.0;
-         y2[number] = pow(-1, static_cast<double>(number)+1)*-1000.0;
+       // Resize the Display
+       fftDisplay->resize(640,240);
+
+       // Set the start and stop frequency
+       fftDisplay->set_start_frequency(start_frequency);
+       fftDisplay->set_stop_frequency(stop_frequency);
+
+       std::vector<gr_complex> fftData(FFT_SIZE);
+       for(unsigned int number = 0; number < fftData.size(); number++){
+               fftData[number] = gr_complex(static_cast<float>(number), 
static_cast<float>(number));
        }
-               
-       // copy the data into the curves
-       curve1->setData(x, y1, 100);
-       curve2->setData(x, y2, 100);
        
-       curve1->attach(myPlot);
-       curve2->attach(myPlot);
-       
+       fftDisplay->set_data(fftData);
+
        // finally, refresh the plot
-       myPlot->replot();
-       myPlot->show();
+       fftDisplay->update_display();
+       fftDisplay->show();
 
        // Make the closing of the last window call the quit()
        QObject::connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()));





reply via email to

[Prev in Thread] Current Thread [Next in Thread]