From 4085285a821d6dcf003d8a0fab1329599790f2be Mon Sep 17 00:00:00 2001
From: Tom <trondeau@vt.edu>
Date: Sun, 23 Aug 2009 21:57:34 -0400
Subject: Plotting phase of filter in its own tab now.

---
 gr-utils/src/python/gr_filter_design.py | 83 +++++++++++++++++++++++----------
 gr-utils/src/python/pyqt_filter.py      |  4 +-
 2 files changed, 60 insertions(+), 27 deletions(-)

(limited to 'gr-utils/src')

diff --git a/gr-utils/src/python/gr_filter_design.py b/gr-utils/src/python/gr_filter_design.py
index cc24afbba7..82af6d900e 100755
--- a/gr-utils/src/python/gr_filter_design.py
+++ b/gr-utils/src/python/gr_filter_design.py
@@ -66,6 +66,12 @@ class gr_plot_filter(QtGui.QMainWindow):
         self.freqcurve = Qwt.QwtPlotCurve("PSD")
         self.freqcurve.attach(self.gui.freqPlot)
 
+        self.phasecurve = Qwt.QwtPlotCurve("Phase")
+        self.phasecurve.attach(self.gui.phasePlot)
+
+        self.groupcurve = Qwt.QwtPlotCurve("Group Delay")
+        self.groupcurve.attach(self.gui.groupPlot)
+
         # Create zoom functionality for the plots
         self.timeZoomer = Qwt.QwtPlotZoomer(self.gui.timePlot.xBottom,
                                             self.gui.timePlot.yLeft,
@@ -96,7 +102,9 @@ class gr_plot_filter(QtGui.QMainWindow):
         blueBrush = Qt.QBrush(Qt.QColor(blue))
         self.freqcurve.setPen(Qt.QPen(blueBrush, 2))
         self.rcurve.setPen(Qt.QPen(blueBrush, 2))
-
+        self.phasecurve.setPen(Qt.QPen(blueBrush, 2))
+        self.groupcurve.setPen(Qt.QPen(blueBrush, 2))
+        
         self.filterWindows = {"Hamming Window" : gr.firdes.WIN_HAMMING,
                               "Hann Window" : gr.firdes.WIN_HANN,
                               "Blackman Window" : gr.firdes.WIN_BLACKMAN,
@@ -165,11 +173,13 @@ class gr_plot_filter(QtGui.QMainWindow):
                             "Band Pass" : self.design_win_bpf,
                             "High Pass" :  self.design_win_hpf}        
                 wintype = self.filterWindows[winstr]
-                taps,r = designer[ftype](fs, gain, wintype)
+                self.taps,r = designer[ftype](fs, gain, wintype)
 
             if(r):
-                self.update_time_curves(taps)
-                self.update_freq_curves(taps, self.nfftpts)
+                self.get_fft(self.taps, self.nfftpts)
+                self.update_time_curves()
+                self.update_freq_curves()
+                self.update_phase_curves()
         
 
     # Filter design functions using a window
@@ -291,23 +301,31 @@ class gr_plot_filter(QtGui.QMainWindow):
         infft,r = nfft.toInt()
         if(r and (infft != self.nfftpts)):
             self.nfftpts = infft
-            self.update_freq_curves(self.taps, self.nfftpts)
+            self.update_freq_curves()
 
     def tab_changed(self, tab):
         if(tab == 0):
-            self.update_freq_curves(self.taps, self.nfftpts)
+            self.update_freq_curves()
         if(tab == 1):
-            self.update_time_curves(self.taps)
+            self.update_time_curves()
+        if(tab == 2):
+            self.update_phase_curves()
         
-    def update_time_curves(self, taps):
-        self.taps = taps
-        ntaps = len(taps)
+    def get_fft(self, taps, Npts):
+        fftpts = fftpack.fft(taps, Npts)
+        self.freq = scipy.arange(0, Npts)
+        
+        self.fftdB = 20.0*scipy.log10(abs(fftpts))
+        self.fftDeg = scipy.unwrap(scipy.angle(fftpts))
+        
+    def update_time_curves(self):
+        ntaps = len(self.taps)
         if(ntaps > 0):
-            self.rcurve.setData(scipy.arange(ntaps), taps)
+            self.rcurve.setData(scipy.arange(ntaps), self.taps)
             
             # Reset the x-axis to the new time scale
-            ymax = 1.5 * max(taps)
-            ymin = 1.5 * min(taps)
+            ymax = 1.5 * max(self.taps)
+            ymin = 1.5 * min(self.taps)
             self.gui.timePlot.setAxisScale(self.gui.timePlot.xBottom,
                                            0, ntaps)
             self.gui.timePlot.setAxisScale(self.gui.timePlot.yLeft,
@@ -318,21 +336,17 @@ class gr_plot_filter(QtGui.QMainWindow):
             
             self.gui.timePlot.replot()
         
-    def update_freq_curves(self, taps, Npts=1000):
-        if(len(taps) > 0):
-            fftpts = fftpack.fft(taps, Npts)
-            freq = scipy.arange(0, Npts)
-            
-            fftdB = 20.0*scipy.log10(abs(fftpts))
-            
-            self.freqcurve.setData(freq, fftdB)
+    def update_freq_curves(self):
+        npts = len(self.fftdB)
+        if(npts > 0):
+            self.freqcurve.setData(self.freq, self.fftdB)
             
             # Reset the x-axis to the new time scale
-            ymax = 1.5 * max(fftdB)
-            ymin = 1.5 * min(fftdB)
+            ymax = 1.5 * max(self.fftdB[0:npts/2])
+            ymin = 1.1 * min(self.fftdB[0:npts/2])
             self.gui.freqPlot.setAxisScale(self.gui.freqPlot.xBottom,
-                                           0, Npts/2)
-            self.gui.timePlot.setAxisScale(self.gui.timePlot.yLeft,
+                                           0, npts/2)
+            self.gui.freqPlot.setAxisScale(self.gui.freqPlot.yLeft,
                                            ymin, ymax)
             
             # Set the zoomer base to unzoom to the new axis
@@ -341,6 +355,25 @@ class gr_plot_filter(QtGui.QMainWindow):
             self.gui.freqPlot.replot()
 
 
+    def update_phase_curves(self):
+        npts = len(self.fftDeg)
+        if(npts > 0):
+            self.phasecurve.setData(self.freq, self.fftDeg)
+            
+            # Reset the x-axis to the new time scale
+            ymax = 1.5 * max(self.fftDeg[0:npts/2])
+            ymin = 1.1 * min(self.fftDeg[0:npts/2])
+            self.gui.phasePlot.setAxisScale(self.gui.phasePlot.xBottom,
+                                            0, npts/2)
+            self.gui.phasePlot.setAxisScale(self.gui.phasePlot.yLeft,
+                                            ymin, ymax)
+            
+            # Set the zoomer base to unzoom to the new axis
+            self.phaseZoomer.setZoomBase()
+            
+            self.gui.phasePlot.replot()
+
+
 def setup_options():
     usage="%prog: [options] (input_filename)"
     description = ""
diff --git a/gr-utils/src/python/pyqt_filter.py b/gr-utils/src/python/pyqt_filter.py
index 0152326430..6b95e03bbe 100644
--- a/gr-utils/src/python/pyqt_filter.py
+++ b/gr-utils/src/python/pyqt_filter.py
@@ -2,7 +2,7 @@
 
 # Form implementation generated from reading ui file 'pyqt_filter.ui'
 #
-# Created: Sun Aug 23 21:18:30 2009
+# Created: Sun Aug 23 21:53:02 2009
 #      by: PyQt4 UI code generator 4.4.4
 #
 # WARNING! All changes made in this file will be lost!
@@ -234,7 +234,7 @@ class Ui_MainWindow(object):
 
         self.retranslateUi(MainWindow)
         self.filterTypeWidget.setCurrentIndex(2)
-        self.tabGroup.setCurrentIndex(3)
+        self.tabGroup.setCurrentIndex(0)
         QtCore.QObject.connect(self.action_exit, QtCore.SIGNAL("activated()"), MainWindow.close)
         QtCore.QMetaObject.connectSlotsByName(MainWindow)
         MainWindow.setTabOrder(self.filterTypeComboBox, self.filterDesignTypeComboBox)
-- 
cgit v1.2.3