commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r11602 - in gnuradio/branches/developers/n4hy/pfb_iir2


From: n4hy
Subject: [Commit-gnuradio] r11602 - in gnuradio/branches/developers/n4hy/pfb_iir2: gnuradio-core/src/lib/general gnuradio-examples/python/apps/filter_design_tool
Date: Sun, 16 Aug 2009 09:04:25 -0600 (MDT)

Author: n4hy
Date: 2009-08-16 09:04:25 -0600 (Sun, 16 Aug 2009)
New Revision: 11602

Modified:
   
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.cc
   
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.h
   
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.i
   
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-examples/python/apps/filter_design_tool/iirdestest.py
Log:
swig is not my friend

Modified: 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.cc
===================================================================
--- 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.cc
       2009-08-16 01:03:39 UTC (rev 11601)
+++ 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.cc
       2009-08-16 15:04:25 UTC (rev 11602)
@@ -21,7 +21,8 @@
  *
  * Derived from Octave functions butterord, butter, chebord1, chebord2,
  * cheby1, cheby2, ellipord, ellip, freqz, sos2tf, sos2zp, tf2sos,zp2sos,
- * These functions are Copyright Julius O. Smith III and Paul Kienzle.
+ * These functions are, primarily, copyright Julius O. Smith III and
+ * Paul Kienzle.
  * The octave files used for the derivation are released under GPL v2.
  */
 
@@ -31,11 +32,12 @@
 
 using std::vector;
 
-#define IIReps 2.2e-14 /* threshold for zero or integer taken from Octave 
filter*/
+#define IIReps 2.2e-14 /* threshold for zero or integer taken from Octave
+                         iir filter design (JOS) */
 
 
 
-gr_iirdes::transfer_function
+vector<double>
 gr_iirdes::iirdes(gr_iirdes::filter_design_type fdtype,
                  vector<double> Wpassband,
                  vector<double> Wstopband,
@@ -190,12 +192,12 @@
   return (vector<double>) NULL;
 }
 
-gr_iirdes::transfer_function
+vector<double>
 gr_iirdes::butter_tf(gr_iirdes::filter_response fresp,
                     vector<double> Wc)
 {
 
-  gr_iirdes::transfer_function rtn;
+  vector<double> rtn;
 
   switch (fresp) {
   case gr_iirdes::LOWPASS:  {
@@ -221,11 +223,11 @@
   return rtn;
 }
 
-gr_iirdes::transfer_function
+vector<double>
 gr_iirdes::chebyshev_tf(gr_iirdes::filter_response fresp,
          vector<double> Wc)
 {
-  gr_iirdes::transfer_function rtn;
+  vector<double> rtn;
   return rtn;
 }
 
@@ -241,11 +243,11 @@
   return rtn;
 }
 
-gr_iirdes::transfer_function
+vector<double>
 gr_iirdes::invchebyshev_tf(gr_iirdes::filter_response fresp,
             vector<double> Wc)
 {
-  gr_iirdes::transfer_function rtn;
+  vector<double> rtn;
   return rtn;
 }
 
@@ -261,11 +263,11 @@
   return rtn;
 }
 
-gr_iirdes::transfer_function
+vector<double>
 gr_iirdes::ellip_tf(gr_iirdes::filter_response fresp,
       vector<double> Wc)
 {
-  gr_iirdes::transfer_function rtn;
+  vector<double> rtn;
   return rtn;
 }
 
@@ -281,34 +283,39 @@
   return rtn;
 }
 
-gr_iirdes::transfer_function
+vector<double>
 gr_iirdes::bessel_tf(gr_iirdes::filter_response fresp,
                     vector<double> Wc)
 {
-  gr_iirdes::transfer_function rtn;
+  vector<double> rtn;
   return rtn;
 }
 
-gr_iirdes::sos
-gr_iirdes::tf2sos(gr_iirdes::transfer_function tf)
+vector<double>
+gr_iirdes::tf2sos(vector<double> tf)
 {
-  gr_iirdes::sos rtn;
+  vector<double> rtn;
   return rtn;
 }
 
-gr_iirdes::zpk
-gr_iirdes::tf2zpg(gr_iirdes::transfer_function tf)
+vector<gr_complexd>
+gr_iirdes::tf2zpg(vector<double> tf)
 {
-  int size = tf.order;
+
+  int size = tf.size()/2;
   gsl_poly_complex_workspace *w;
-  gr_iirdes::zpk rtn;
+  double a[size],b[size];
   double *z;
+  vector<gr_complexd> rtn;
   
   if (size < 2) throw std::invalid_argument
                  ("transfer function to pole, zero, gain calculation requires 
order 2 or greater");
 
-  rtn.z = new gr_complexd(size);
-  rtn.p = new gr_complexd(size);
+  for (int i=0;i<size;i++) {
+    a[i]=tf[i];
+    b[i]=tf[i+size];
+  }
+
   w = gsl_poly_complex_workspace_alloc(size);
   z = new double(2*size);
 
@@ -319,28 +326,27 @@
   }
   
   // compute zeros
-  gsl_poly_complex_solve (tf.a, size, w, z);
+  gsl_poly_complex_solve (a, size, w, z);
   // store them in the zeros in the zpk array
   for (int i=0;i<size;i++)
-    rtn.z[i] = gr_complexd(z[2*i],z[2*i+1]);
+    rtn[i] = gr_complexd(z[2*i],z[2*i+1]);
 
   // compute poles
-  gsl_poly_complex_solve (tf.b, size, w, z);
+  gsl_poly_complex_solve (b, size, w, z);
   for (int i=0;i<size;i++)
-    rtn.p[i] = gr_complexd(z[2*i],z[2*i+1]);
+    rtn[i+size] = gr_complexd(z[2*i],z[2*i+1]);
 
   delete z;
 
-  rtn.k = tf.b[0]/tf.a[0];
 
   return rtn;
 }
 
-gr_iirdes::zpk
-gr_iirdes::sftrans(gr_iirdes::zpk ZeroPoleK,
+vector<gr_complexd>
+gr_iirdes::sftrans(vector<gr_complexd> zeropolek,
                   vector<double> W,
                   bool stop)
 {
-  gr_iirdes::zpk rtn;
+  vector<gr_complexd> rtn;
   return rtn;
 }

Modified: 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.h
===================================================================
--- 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.h
        2009-08-16 01:03:39 UTC (rev 11601)
+++ 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.h
        2009-08-16 15:04:25 UTC (rev 11602)
@@ -69,38 +69,28 @@
    */
 
 
+
   static std::vector<double>
+  tf2sos(std::vector<double> tf);
+
+
+  static std::vector<gr_complexd>
+  tf2zpg(std::vector<double> tf);
+
+ 
+  static std::vector<gr_complexd>
+  sftrans(std::vector<gr_complexd> zeropolek,
+         std::vector<double> W,
+         bool stop);
+
+  static std::vector<double>
   butterord(filter_response ft,
            std::vector<double> Wp,
            std::vector<double> Ws,
            double Rp,
            double Rs);
 
-
-  typedef struct _transfer_function {
-    int order;
-    double *b;
-    double *a;
-  } transfer_function;
-
-
-
-  typedef struct _zpk {
-    gr_complexd *z;
-    gr_complexd *p;
-    int order;
-    double k;
-  } zpk;
-
-  typedef struct _sos {
-    double num[3];
-    double den[3];
-    double g;
-  } sos;
-
-
-
-  static transfer_function
+  static std::vector<double>
   butter_tf(filter_response ft,
            std::vector<double> Wc);
 
@@ -111,7 +101,7 @@
               double Rp,
               double Rs);
 
-  static transfer_function
+  static std::vector<double>
   chebyshev_tf(filter_response ft,
               std::vector<double> Wc);
 
@@ -122,7 +112,7 @@
                  double Rp,
                  double Rs);
 
-  static transfer_function
+  static std::vector<double>
   invchebyshev_tf(filter_response ft,
                  std::vector<double> Wc);
 
@@ -133,7 +123,7 @@
           double Rp,
           double Rs);
 
-  static transfer_function
+  static std::vector<double>
   ellip_tf(filter_response ft,
           std::vector<double> Wc);
 
@@ -144,30 +134,17 @@
            double Rp,
            double Rs);
 
-  static transfer_function
+  static std::vector<double>
   bessel_tf(filter_response ft,
            std::vector<double> Wc);
 
-  static sos
-  tf2sos(transfer_function tf);
-
-
-  static zpk
-  tf2zpg(transfer_function tf);
-
-  static transfer_function
+  static std::vector<double>
   iirdes(filter_design_type fdtype,
         std::vector<double> Wp,
         std::vector<double> Ws,
         double Rp,
         double Rs);
 
- 
-  static zpk
-  sftrans(zpk ZeroPoleK,
-         std::vector<double> W,
-         bool stop);
-
  // ... class members and methods ... (private)
 
 

Modified: 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.i
===================================================================
--- 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.i
        2009-08-16 01:03:39 UTC (rev 11601)
+++ 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-core/src/lib/general/gr_iirdes.i
        2009-08-16 15:04:25 UTC (rev 11602)
@@ -26,11 +26,13 @@
 
 %rename(iirdes) gr_iirdes;
 
-
 class gr_iirdes {
 
-public:
 
+ public:
+
+  // ... class types ... (public)
+
   enum filter_response {
     LOWPASS  = 0,        // Lowpass  filter, cutoff in (0,.5)
     HIGHPASS = 1,        // Highpass filter, cutoff in (0,.5)
@@ -63,17 +65,81 @@
 
 
   static std::vector<double>
+  tf2sos(std::vector<double> tf);
+
+
+  static std::vector<gr_complexd>
+  tf2zpg(std::vector<double> tf);
+
+ 
+  static std::vector<gr_complexd>
+  sftrans(std::vector<gr_complexd> zeropolek,
+         std::vector<double> W,
+         bool stop);
+
+  static std::vector<double>
   butterord(filter_response ft,
            std::vector<double> Wp,
            std::vector<double> Ws,
            double Rp,
            double Rs);
 
+  static std::vector<double>
+  butter_tf(filter_response ft,
+           std::vector<double> Wc);
 
-  typedef struct transfer_function {
-    int order;
-    double *b;
-    double *a;
-  } transfer_function;
+  static std::vector<double>
+  chebyshevord(filter_response ft,
+              std::vector<double> Wp,
+              std::vector<double> Ws,
+              double Rp,
+              double Rs);
 
+  static std::vector<double>
+  chebyshev_tf(filter_response ft,
+              std::vector<double> Wc);
+
+  static std::vector<double>
+  invchebyshevord(filter_response ft,
+                 std::vector<double> Wp,
+                 std::vector<double> Ws,
+                 double Rp,
+                 double Rs);
+
+  static std::vector<double>
+  invchebyshev_tf(filter_response ft,
+                 std::vector<double> Wc);
+
+  static std::vector<double>
+  ellipord(filter_response ft,
+          std::vector<double> Wp,
+          std::vector<double> Ws,
+          double Rp,
+          double Rs);
+
+  static std::vector<double>
+  ellip_tf(filter_response ft,
+          std::vector<double> Wc);
+
+  static std::vector<double>
+  besselord(filter_response ft,
+           std::vector<double> Wp,
+           std::vector<double> Ws,
+           double Rp,
+           double Rs);
+
+  static std::vector<double>
+  bessel_tf(filter_response ft,
+           std::vector<double> Wc);
+
+  static std::vector<double>
+  iirdes(filter_design_type fdtype,
+        std::vector<double> Wp,
+        std::vector<double> Ws,
+        double Rp,
+        double Rs);
+
+ // ... class members and methods ... (private)
+
+
 };

Modified: 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-examples/python/apps/filter_design_tool/iirdestest.py
===================================================================
--- 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-examples/python/apps/filter_design_tool/iirdestest.py
   2009-08-16 01:03:39 UTC (rev 11601)
+++ 
gnuradio/branches/developers/n4hy/pfb_iir2/gnuradio-examples/python/apps/filter_design_tool/iirdestest.py
   2009-08-16 15:04:25 UTC (rev 11602)
@@ -22,12 +22,16 @@
 
 from gnuradio import gr
 
-numbers = gr.iirdes.butterord(gr.iirdes.BANDPASS,
-                              [.2, .3],
-                              [.1, .4],
-                              .1,
-                              30)
-print numbers
+#numbers = gr.iirdes.butterord(gr.iirdes.BANDPASS,
+#                              [.2, .3],
+#                              [.1, .4],
+#                              .1,
+#                              30)
+#print numbers
 
 
+tf=[0.0976, 0.1953, 0.0976, 1.0, -0.9428, 0.3333]
+zpg = gr.iirdes.tf2zpg(tf)
+#print zpg
+print tf
 





reply via email to

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