RT2_Cuboid_demo / Mbed 2 deprecated nucf446-test_GPA

Dependencies:   mbed

Fork of nucf446-cuboid-balance1_strong by RT2_Cuboid_demo

Revision:
24:33ded7d7bcbd
Parent:
23:26a1ccd0a856
Child:
25:e46687840dd6
--- a/GPA.cpp	Mon Apr 09 15:09:54 2018 +0000
+++ b/GPA.cpp	Mon Apr 09 18:13:58 2018 +0000
@@ -10,14 +10,15 @@
                                |                    P: plant
                                v
      exc(1) --> o   ->| C |--->o------->| P |----------> out
-                ^                  |             |
+                ^ -                |             |
                 |                   --> inp      |  exc: excitation signal (E)
                 |                                |  inp: input plant (U)
                  --------------------------------   out: output plant (Y)
 
     instantiate option 1:
+    
     GPA(float fMin, float fMax, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1)
-
+    
         fMin:     minimal desired frequency that should be measured in Hz
         fMax:     maximal desired frequency that should be measured in Hz
         NfexcDes: number of logarithmic equaly spaced frequency points
@@ -26,11 +27,18 @@
         Ts:       sampling time
         Aexc0:    excitation amplitude at fMin
         Aexc1:    excitation amplitude at fMax
+           
+    instantiate option 2: (for a second, refined frequency grid measurement)
+    
+    GPA(float f0, float f1, float *fexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1)
+    
+        f0:       frequency point for the calculation of Aexc0 in Hz (should be chosen like in the first measurement)
+        f1:       frequency point for the calculation of Aexc1 in Hz (should be chosen like in the first measurement)
+        *fexcDes: sorted frequency point array in Hz
 
-        hints:    the amplitude drops with 1/fexc, if you're using
-                  Axc1 = Aexc0/fMax then d/dt exc = const., this is recommended
-                  if your controller does not have a rolloff.
-                  if a desired frequency point is not measured try to increase Nmeas.
+    hints:    the amplitude drops with 1/fexc, if you're using Axc1 = Aexc0/fMax then d/dt exc = const.,
+              this is recommended if your controller does not have a rolloff. if a desired frequency point
+              is not measured try to increase Nmeas.
 
     pseudo code for a closed loop measurement with a controller C:
 
@@ -111,6 +119,32 @@
     reset();
 }
 
+GPA::GPA(float f0, float f1, float *fexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1)
+{
+    // convert fexcDes from float to double, it is assumed that it is sorted
+    NfexcDes = sizeof(fexcDes)/sizeof(fexcDes[0]);
+    this->fexcDes = (double*)malloc(NfexcDes*sizeof(double));
+    for(int i = 0; i < NfexcDes; i++) {
+        this->fexcDes[i] = (double)fexcDes[i];
+    }
+    this->NperMin = NperMin;
+    this->NmeasMin = NmeasMin;
+    this->Ts = (double)Ts;
+
+    // calculate coefficients for decreasing amplitude (1/fexc)
+    this->aAexcDes = ((double)Aexc1 - (double)Aexc0)/(1.0/(double)f1 - 1.0/(double)f0);
+    this->bAexcDes = (double)Aexc0 - aAexcDes/fexcDes[0];
+
+    fnyq = 1.0/2.0/(double)Ts;
+    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();
+}
+
 GPA::~GPA() {}
 
 void GPA::reset()