diff FXAnalyse.c @ 66:aa125ad6e842

Clarify variables names in dedrifting code
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 29 Oct 2012 14:48:01 +0100
parents da82b4815c2f
children 0159abc1a9d8
line wrap: on
line diff
--- a/FXAnalyse.c	Mon Oct 29 14:46:33 2012 +0100
+++ b/FXAnalyse.c	Mon Oct 29 14:48:01 2012 +0100
@@ -104,12 +104,14 @@
 
 int SlopeMeasuring = FALSE;
 int StopSlopeCancellingOnUnlocked = TRUE;
-double SlopeMath2 = 0.0; // currently applied frequency dedrifiting slope
 double TimetoSlope = 60.0;
 double SlopeMeasuringTimeBegin = 0.0;
 
-double Slope_Math2slope=0.0,Moy_Math2slope=0.0;
-int N_Math2slope=0.0;
+int Nsamples = 0;				// number of samples in current measurement
+double previousFreq = 0.0;		// previous frequency value
+double meanFreq = 0.0;			// mean value
+double measuredSlope = 0.0;		// measured slope
+double appliedSlope = 0.0;		// currently applied frequency dedrifiting slope
 
 double LimitToDelock=5.0;
 double limitotakoff=70.0;
@@ -126,7 +128,6 @@
 	SLOPE_REFERENCE_HG_CAVITY = 1,
 };
 
-double previousFreq = 0.0;
 int invertSlopeSign = 0;
 int slopeReference = SLOPE_REFERENCE_MICROWAVE;
 
@@ -1243,38 +1244,38 @@
 							frequency = DDSFox_ReadFreq(&DDS1xAD9956);
 						
 						if (! KeepSlope)
-							SlopeMath2 = 0.0;
+							appliedSlope = 0.0;
 						
-						SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, SlopeMath2);
-						DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2);
+						SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope);
+						DDSFox_Set(&DDS1xAD9956, frequency, appliedSlope);
 						
-						Slope_Math2slope = 0.0;
+						measuredSlope = 0.0;
 						SlopeMeasuring = FALSE;
 						SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0);
 					}
 					
 					// update slope measurement
-					N_Math2slope = N_Math2slope + 1;
+					Nsamples = Nsamples + 1;
+					meanFreq = ((Nsamples - 1) * meanFreq + currentFreq) / Nsamples;
+					measuredSlope = (measuredSlope * (Nsamples - 2) + 6 * (currentFreq - meanFreq) / Nsamples) / (Nsamples + 1);
 					previousFreq = currentFreq;
-					Moy_Math2slope = ((N_Math2slope-1)*Moy_Math2slope + currentFreq)/N_Math2slope;
-					Slope_Math2slope = (Slope_Math2slope*(N_Math2slope-2) + 6*(currentFreq-Moy_Math2slope)/N_Math2slope)/(N_Math2slope+1);
 					// update indicator
-					SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, Slope_Math2slope);
+					SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, measuredSlope);
 					
 					// update applied slope
 					if ((utc - SlopeMeasuringTimeBegin) > TimetoSlope) {
 						
 						if (invertSlopeSign)
-							SlopeMath2 = SlopeMath2 - Slope_Math2slope;
+							appliedSlope = appliedSlope - measuredSlope;
 						else
-							SlopeMath2 = SlopeMath2 + Slope_Math2slope;
+							appliedSlope = appliedSlope + measuredSlope;
 						
 						if (FrequCorrec) {
 							// proportional correction
 							
 							Nratio += 1;
 							if (Nratio >= 1) {
-								MoyMath2 = MoyMath2 + Moy_Math2slope;
+								MoyMath2 = MoyMath2 + meanFreq;
 							}
 							if (Nratio == 1 && CenterFrequencyCh2ToDetermine == TRUE) {
 								CenterFrequencyCh2 = MoyMath2;
@@ -1282,18 +1283,18 @@
 							}
 							if (Nratio == ratio) {
 								double correction = (MoyMath2/ratio-CenterFrequencyCh2)/TimetoSlope;
-								SlopeMath2 = SlopeMath2 + correction;
+								appliedSlope = appliedSlope + correction;
 								Nratio = 0;
 								MoyMath2 = 0.0;
 							}
 						}
 						
-						SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, SlopeMath2);
-						DDSFox_SetSweepRate(&DDS1xAD9956, SlopeMath2);
+						SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope);
+						DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope);
 						
-						N_Math2slope = 0.0;
-						Moy_Math2slope = 0.0;
-						Slope_Math2slope = 0.0;
+						Nsamples = 0.0;
+						meanFreq = 0.0;
+						measuredSlope = 0.0;
 						SlopeMeasuringTimeBegin = utc;
 					}
 				}
@@ -2239,17 +2240,16 @@
 					frequency = DDSFox_ReadFreq(&DDS1xAD9956);
 				
 				if (! KeepSlope)
-					SlopeMath2 = 0.0;
+					appliedSlope = 0.0;
 				
-				SetCtrlVal(panel, PANEL_SLOPE_APPLIED, SlopeMath2);
-				DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2);
+				SetCtrlVal(panel, PANEL_SLOPE_APPLIED, appliedSlope);
+				DDSFox_Set(&DDS1xAD9956, frequency, appliedSlope);
 				
 				SlopeMeasuring = FALSE; 
-				N_Math2slope = 0.0;
-				Moy_Math2slope = 0.0;
-				Slope_Math2slope = 0.0;
+				Nsamples = 0.0;
+				meanFreq = 0.0;
+				measuredSlope = 0.0;
 				MoyMath2 = 0.0; 
-				Slope_Math2slope = 0.0;
 				CenterFrequencyCh2 = 0.0;
 				Nratio = -1;
 			}
@@ -2269,9 +2269,9 @@
 			MoyMath2 = 0.0;
 			Nratio = -1;
 			CenterFrequencyCh2ToDetermine = TRUE ;
-			SlopeMath2 = 0.0; 
-			SetCtrlVal(panel, PANEL_SLOPE_APPLIED, SlopeMath2);
-			DDSFox_Set(&DDS1xAD9956, DEDRIFT_DDS_FREQUENCY, SlopeMath2);
+			appliedSlope = 0.0; 
+			SetCtrlVal(panel, PANEL_SLOPE_APPLIED, appliedSlope);
+			DDSFox_Set(&DDS1xAD9956, DEDRIFT_DDS_FREQUENCY, appliedSlope);
 			break;
 	}
 	return 0;
@@ -2460,8 +2460,8 @@
 	switch (event)
 	{
 		case EVENT_COMMIT:
-			GetCtrlVal(panel, control, &SlopeMath2);
-			DDSFox_SetSweepRate(&DDS1xAD9956, SlopeMath2);
+			GetCtrlVal(panel, control, &appliedSlope);
+			DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope);
 			break;
 	}
 	return 0;