Mercurial > hg > fxanalyse
comparison Allan.c @ 136:7b9cf3d4346e
Code cleanup
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Wed, 22 Jan 2014 12:29:58 +0100 |
parents | 77539f2597b1 |
children | 792ac7151f0f |
comparison
equal
deleted
inserted
replaced
135:77539f2597b1 | 136:7b9cf3d4346e |
---|---|
44 { | 44 { |
45 /* total number of points used. used to calculate the drift rate */ | 45 /* total number of points used. used to calculate the drift rate */ |
46 int N = 1 + Instance->BlocksNumber[0]; | 46 int N = 1 + Instance->BlocksNumber[0]; |
47 double Mean = Instance->Mean; | 47 double Mean = Instance->Mean; |
48 double Drift = Instance->Drift; | 48 double Drift = Instance->Drift; |
49 double Normalizer = Instance->normalization; | |
50 | 49 |
51 /* compute drift rate */ | 50 /* compute drift rate */ |
52 if (N > 1) { | 51 if (N > 1) |
53 Instance->Drift = (Drift * (N - 2) + 6 * (Freq - Mean) / N) / (N + 1); | 52 Instance->Drift = (Drift * (N - 2) + 6 * (Freq - Mean) / N) / (N + 1); |
54 SetCtrlVal(Instance->AllanPanel, ALLANPANEL_DRIFT, Instance->Drift/Normalizer); | |
55 } | |
56 Instance->Mean = (Mean * (N - 1) + Freq) / N; | 53 Instance->Mean = (Mean * (N - 1) + Freq) / N; |
57 | 54 |
58 /* compute allan deviation */ | 55 /* compute allan deviation */ |
59 for (int i = 0; i < ALLAN_MAXPOINTSNUMBER; i++) { | 56 for (int i = 0; i < ALLAN_NUM_DATAPOINTS; i++) { |
60 Instance->CurrentAverage[i] = (Instance->CurrentAverage[i]*Instance->NbCurrentAverage[i] + Freq) | 57 Instance->CurrentAverage[i] = (Instance->CurrentAverage[i]*Instance->NbCurrentAverage[i] + Freq) |
61 /(Instance->NbCurrentAverage[i]+1); | 58 /(Instance->NbCurrentAverage[i]+1); |
62 Instance->NbCurrentAverage[i] +=1; | 59 Instance->NbCurrentAverage[i] +=1; |
63 | 60 |
64 if (Instance->NbCurrentAverage[i] >= pow(2,i) ) { | 61 if (Instance->NbCurrentAverage[i] >= pow(2,i) ) { |
99 | 96 |
100 | 97 |
101 static void Allan_Display(Allan_Data *Instance) | 98 static void Allan_Display(Allan_Data *Instance) |
102 { | 99 { |
103 int i, N; | 100 int i, N; |
104 double X[ALLAN_MAXPOINTSNUMBER]; | 101 double X[ALLAN_NUM_DATAPOINTS]; |
105 double Y[ALLAN_MAXPOINTSNUMBER]; | 102 double Y[ALLAN_NUM_DATAPOINTS]; |
106 double Normalizer = Instance->normalization; | 103 double Normalizer = Instance->normalization; |
107 double DriftTau, FirstFreq, LastFreq, Error; | 104 double DriftTau, FirstFreq, LastFreq, Error; |
108 int dedrift; | 105 int dedrift; |
109 | 106 |
110 GetCtrlVal(Instance->AllanPanel, ALLANPANEL_DEDRIFT, &dedrift); | 107 GetCtrlVal(Instance->AllanPanel, ALLANPANEL_DEDRIFT, &dedrift); |
111 | 108 SetCtrlVal(Instance->AllanPanel, ALLANPANEL_DRIFT, Instance->Drift); |
112 for (i = 0; i < ALLAN_MAXPOINTSNUMBER; i++) { | 109 |
110 for (i = 0; i < ALLAN_NUM_DATAPOINTS; i++) { | |
113 X[i] = pow(2, i); | 111 X[i] = pow(2, i); |
114 if (dedrift) { | 112 if (dedrift) { |
115 DriftTau = Instance->Drift * X[i]; | 113 DriftTau = Instance->Drift * X[i]; |
116 N = Instance->BlocksNumber[i]; | 114 N = Instance->BlocksNumber[i]; |
117 if (N>=2) { // if enough data to calculate AVAR for tau = 2^i*tau0, and therefore, AllanVar[i] is meaningful | 115 if (N > 1) { // if enough data to calculate AVAR for tau = 2^i*tau0, and therefore, AllanVar[i] is meaningful |
118 FirstFreq = Instance->FirstMean[i]; | 116 FirstFreq = Instance->FirstMean[i]; |
119 LastFreq = Instance->LastMean[i]; | 117 LastFreq = Instance->LastMean[i]; |
120 Y[i] = sqrt(Instance->AllanVar[i]+DriftTau*(DriftTau/2-(LastFreq-FirstFreq)/(N-1)))/Normalizer; | 118 Y[i] = sqrt(Instance->AllanVar[i]+DriftTau*(DriftTau/2-(LastFreq-FirstFreq)/(N-1)))/Normalizer; |
121 // Not totaly sure it works... to be checked thoroughly | 119 // Not totaly sure it works... to be checked thoroughly |
122 } | 120 } |
127 Y[i] = sqrt(Instance->AllanVar[i])/Normalizer; | 125 Y[i] = sqrt(Instance->AllanVar[i])/Normalizer; |
128 } | 126 } |
129 } | 127 } |
130 | 128 |
131 DeleteGraphPlot(Instance->AllanPanel, ALLANPANEL_ALLANPLOT, -1, VAL_IMMEDIATE_DRAW); | 129 DeleteGraphPlot(Instance->AllanPanel, ALLANPANEL_ALLANPLOT, -1, VAL_IMMEDIATE_DRAW); |
132 PlotXY(Instance->AllanPanel, ALLANPANEL_ALLANPLOT, X, Y, ALLAN_MAXPOINTSNUMBER, | 130 PlotXY(Instance->AllanPanel, ALLANPANEL_ALLANPLOT, X, Y, ALLAN_NUM_DATAPOINTS, |
133 VAL_DOUBLE, VAL_DOUBLE, VAL_SCATTER, VAL_SOLID_SQUARE, VAL_SOLID, 1, DATAPOINT_COLOR); | 131 VAL_DOUBLE, VAL_DOUBLE, VAL_SCATTER, VAL_SOLID_SQUARE, VAL_SOLID, 1, DATAPOINT_COLOR); |
134 | 132 |
135 for (i = 0; i < ALLAN_MAXPOINTSNUMBER; i++) { | 133 for (i = 0; i < ALLAN_NUM_DATAPOINTS; i++) { |
136 Error = 1/sqrt(Instance->BlocksNumber[i]); | 134 Error = 1/sqrt(Instance->BlocksNumber[i]); |
137 PlotLine(Instance->AllanPanel, ALLANPANEL_ALLANPLOT, X[i], Y[i]*(1-Error), X[i], Y[i]*(1+Error), ERRORBAR_COLOR); | 135 PlotLine(Instance->AllanPanel, ALLANPANEL_ALLANPLOT, X[i], Y[i]*(1-Error), X[i], Y[i]*(1+Error), ERRORBAR_COLOR); |
138 } | 136 } |
139 } | 137 } |
140 | 138 |
160 void *callbackData, int eventData1, int eventData2) | 158 void *callbackData, int eventData1, int eventData2) |
161 { | 159 { |
162 switch (event) | 160 switch (event) |
163 { | 161 { |
164 case EVENT_COMMIT: | 162 case EVENT_COMMIT: |
165 int YMin, YMax; | 163 int pmin, pmax; |
166 GetCtrlVal(panel, ALLANPANEL_MIN, &YMin); | 164 GetCtrlVal(panel, ALLANPANEL_MIN, &pmin); |
167 GetCtrlVal(panel, ALLANPANEL_MAX, &YMax); | 165 GetCtrlVal(panel, ALLANPANEL_MAX, &pmax); |
168 if (YMin < YMax) { | 166 if (pmin < pmax) { |
169 SetAxisScalingMode(panel, ALLANPANEL_ALLANPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, pow(10,(double)YMin), pow(10,(double)YMax) ); | 167 SetAxisScalingMode(panel, ALLANPANEL_ALLANPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, pow(10, pmin), pow(10, pmax)); |
170 SetCtrlVal(panel, ALLANPANEL_CHECKBOX_AUTOSCALE, FALSE); | 168 SetCtrlVal(panel, ALLANPANEL_CHECKBOX_AUTOSCALE, FALSE); |
171 } | 169 } |
172 break; | 170 break; |
173 } | 171 } |
174 return 0; | 172 return 0; |
175 } | 173 } |
181 switch (event) | 179 switch (event) |
182 { | 180 { |
183 case EVENT_COMMIT: | 181 case EVENT_COMMIT: |
184 Allan_Data *data; | 182 Allan_Data *data; |
185 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &data); | 183 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &data); |
184 GetCtrlVal(panel, control, &(data->autoscale)); | |
185 Allan_Display(data); | |
186 break; | |
187 } | |
188 return 0; | |
189 } | |
190 | |
191 | |
192 int CVICALLBACK Allan_CB_ChangeNormalization (int panel, int control, int event, | |
193 void *callbackData, int eventData1, int eventData2) | |
194 { | |
195 switch (event) | |
196 { | |
197 case EVENT_COMMIT: | |
198 Allan_Data *data; | |
199 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &data); | |
186 GetCtrlVal(panel, control, &(data->normalization)); | 200 GetCtrlVal(panel, control, &(data->normalization)); |
187 Allan_Display(data); | 201 Allan_Display(data); |
188 break; | 202 break; |
189 } | 203 } |
190 return 0; | 204 return 0; |
191 } | 205 } |
192 | 206 |
193 | 207 |
194 int CVICALLBACK Allan_CB_ChangeNormalization (int panel, int control, int event, | |
195 void *callbackData, int eventData1, int eventData2) | |
196 { | |
197 switch (event) | |
198 { | |
199 case EVENT_COMMIT: | |
200 Allan_Data *data; | |
201 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &data); | |
202 GetCtrlVal(panel, control, &(data->normalization)); | |
203 Allan_Display(data); | |
204 break; | |
205 } | |
206 return 0; | |
207 } | |
208 | |
209 | |
210 int CVICALLBACK CB_GeneralAllanPanel (int panel, int event, void *callbackData, | 208 int CVICALLBACK CB_GeneralAllanPanel (int panel, int event, void *callbackData, |
211 int eventData1, int eventData2) | 209 int eventData1, int eventData2) |
212 { | 210 { |
213 switch (event) | 211 switch (event) |
214 { | 212 { |