.

Fork of Cntrlol_Lib by Ruprecht Altenburger

Revision:
5:d00752fcad65
Parent:
0:e2a7d7f91e49
Child:
6:0c473884d24a
--- a/GPA.cpp	Fri Oct 19 13:14:32 2018 +0000
+++ b/GPA.cpp	Thu Oct 25 09:54:24 2018 +0000
@@ -123,7 +123,7 @@
     pi2 = 2.0*pi;
     pi2Ts = pi2*(double)Ts;
     piDiv2 = pi/2.0;
-
+    
     sU = (double*)malloc(3*sizeof(double));
     sY = (double*)malloc(3*sizeof(double));
     reset();
@@ -192,6 +192,8 @@
     ii = 1; // iterating through desired frequency points
     jj = 1; // iterating through measurement points w.r.t. reachable frequency
     scaleG = 0.0;
+    scaleH = 2.0;
+    wk = 0.0;
     cr = 0.0;
     ci = 0.0;
     for(int i = 0; i < 3; i++) {
@@ -240,12 +242,14 @@
             sY[i] = 0.0;
         }
     }
+    // update hann window
+    calcHann();
     // filter step for signal su
-    sU[0] = scaleG*inp + 2.0*cr*sU[1] - sU[2];
+    sU[0] = wk*scaleG*inp + 2.0*cr*sU[1] - sU[2];
     sU[2] = sU[1];
     sU[1] = sU[0];
     // filter step for signal sy
-    sY[0] = scaleG*out + 2.0*cr*sY[1] - sY[2];
+    sY[0] = wk*scaleG*out + 2.0*cr*sY[1] - sY[2];
     sY[2] = sY[1];
     sY[1] = sY[0];
     // measurement of frequencypoint is finished
@@ -254,10 +258,10 @@
         ii += 1;
         fexcPast = fexc;
         // calculate the one point dft
-        double Ureal = 2.0*scaleG*(cr*sU[1] - sU[2]);
-        double Uimag = 2.0*scaleG*ci*sU[1];
-        double Yreal = 2.0*scaleG*(cr*sY[1] - sY[2]);
-        double Yimag = 2.0*scaleG*ci*sY[1];
+        double Ureal = 2.0*scaleH*scaleG*(cr*sU[1] - sU[2]);
+        double Uimag = 2.0*scaleH*scaleG*ci*sU[1];
+        double Yreal = 2.0*scaleH*scaleG*(cr*sY[1] - sY[2]);
+        double Yimag = 2.0*scaleH*scaleG*ci*sY[1];
         // calculate magnitude and angle
         float Umag = (float)(sqrt(Ureal*Ureal + Uimag*Uimag));
         float Ymag = (float)(sqrt(Yreal*Yreal + Yimag*Yimag));
@@ -306,6 +310,11 @@
     fexc = (double)Nper/(double)Nmeas/Ts;
 }
 
+void GPA::calcHann()
+{
+    wk = 0.5 - 0.5*cos(2.0*pi*((double)jj-1.0)/(double)Nmeas);
+}
+
 void GPA::printLine()
 {
     printf("-----------------------------------------------------------------------------------------\r\n");