Mercurial > hg > fxanalyse
comparison FXAnalyse.c @ 220:28a4ff70fe48
Rework beatnote sign determination. Fix Sign3 measurement
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Thu, 18 Sep 2014 18:01:38 +0200 |
parents | fefe921a9784 |
children | c14f5a95850d |
comparison
equal
deleted
inserted
replaced
219:ddc8c47db3df | 220:28a4ff70fe48 |
---|---|
258 double f_rep_slope, f_beat_slope; | 258 double f_rep_slope, f_beat_slope; |
259 double f_rep_plus, f_rep_minus; | 259 double f_rep_plus, f_rep_minus; |
260 double f_beat_plus, f_beat_minus; | 260 double f_beat_plus, f_beat_minus; |
261 double N_measured; | 261 double N_measured; |
262 | 262 |
263 double Frequencystep1=10000.0, tbegin1=0.0, Frepbefore1=0.0, Frequency1=0.0; | 263 // Beatnote sign determination is done stepping the repetition rate by |
264 double Frequencystep2=10.0, tbegin2=0.0, Frepbefore2=0.0, Ch2before=0.0, Frequency2=0.0; | 264 // stepping the comb phase-lock offset frequency f_lock generated by |
265 double Frequencystep3=100000.0, tbegin3=0.0, Frepbefore3=0.0, Frequency3=0.0; | 265 // DDS1. A lock frequency step delta_f_lock determines a change in the |
266 | 266 // repetition rate given by: |
267 int Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE; | 267 // |
268 // abs(delta_f_rep) = Ndiv * delta_f_lock / N1 | |
269 // | |
270 // where Ndiv = 8 and N1 ~= 8 x 10^5 obtaining that | |
271 // | |
272 // abs(delta_f_rep) ~= delta_f_lock / 10^5 | |
273 // | |
274 // For the determination of the comb locking beatnote sign we detect | |
275 // the sign of delta_f_rep caused by a positive delta_f_lock. f_rep is | |
276 // measured should be small enough to do not exceed the 200x PLL | |
277 // bandwidth but still be clearly identified. | |
278 // | |
279 // For the optical beatnotes we detect the sign of delta_f_beat caused | |
280 // by a positive delta_f_lock thus we need to take into account the | |
281 // sign of the comb locking beatnote. The optical beatnote frequency | |
282 // change is given by | |
283 // | |
284 // abs(delta_f_beat) = abs(delta_f_rep) * Nx | |
285 // | |
286 // where Nx ~= 10^6 obtaining that | |
287 // | |
288 // abs(delta_f_beat) ~= delta_f_lock * 10 | |
289 // | |
290 // this need to do not exceed the beatnote filters bandwidth. Given | |
291 // those contraints the following f_lock steps are chosen: | |
292 | |
293 double f_lock_step_1 = 10000.0; | |
294 double f_lock_step_2 = 10.0; | |
295 double f_lock_step_3 = 10.0; | |
296 | |
297 struct beatsign { | |
298 int measure; // which beatnote sign is being measured | |
299 double f0_DDS1; // DDS1 frequency before stepping | |
300 double t0; // measurement start time | |
301 double f_rep_zero; // repetition rate before stepping | |
302 double f_beat_zero; // beatnote frequwncy before stepping | |
303 }; | |
304 | |
305 struct beatsign beatsign = { | |
306 .measure = 0, | |
307 }; | |
308 | |
268 | 309 |
269 struct stat stat_math1, stat_ch2, stat_ch3, freq; | 310 struct stat stat_math1, stat_ch2, stat_ch3, freq; |
270 struct rollmean rollmean_ch1, rollmean_ch2, rollmean_ch3, rollmean_ch4; | 311 struct rollmean rollmean_ch1, rollmean_ch2, rollmean_ch3, rollmean_ch4; |
271 | 312 |
272 | 313 |
1204 Measuring_3 = N_MEASUREMENT_NONE; | 1245 Measuring_3 = N_MEASUREMENT_NONE; |
1205 } | 1246 } |
1206 break; | 1247 break; |
1207 } | 1248 } |
1208 | 1249 |
1209 // beatnote sign determination | 1250 // beatnote sign determination |
1210 | 1251 if ((beatsign.measure) && |
1211 if (Getsign1 == TRUE) { | 1252 (utc > beatsign.t0 + 2.0)) { |
1212 if (utc > tbegin1+2) { | 1253 |
1213 if (Math1 > Frepbefore1) | 1254 int f_beat_sign, f_rep_sign = 0; |
1214 Sign1 = -1.0; | 1255 |
1215 else | 1256 switch (beatsign.measure) { |
1216 Sign1 = +1.0; | 1257 case LO: |
1217 ad9912_set_frequency_w(&ad9912, 0, Frequency1); | 1258 f_rep_sign = (Math1 > beatsign.f_rep_zero) ? -1 : 1; |
1218 Getsign1 = FALSE; | 1259 Sign1 = f_rep_sign; |
1219 SetCtrlVal(MainPanel, PANEL_SIGN1, Sign1); | 1260 SetCtrlVal(MainPanel, PANEL_SIGN1, Sign1); |
1261 break; | |
1262 case HG: | |
1263 f_rep_sign = (Math1 > beatsign.f_rep_zero) ? -1 : 1; | |
1264 f_beat_sign = (Ch2 > beatsign.f_beat_zero) ? -1 : 1; | |
1265 Sign2 = f_rep_sign * f_beat_sign; | |
1266 SetCtrlVal(MainPanel, PANEL_SIGN2, Sign2); | |
1267 break; | |
1268 case SR: | |
1269 f_rep_sign = (Math1 > beatsign.f_rep_zero) ? -1 : 1; | |
1270 f_beat_sign = (Ch3 > beatsign.f_beat_zero) ? -1 : 1; | |
1271 Sign3 = f_rep_sign * f_beat_sign; | |
1272 SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3); | |
1273 break; | |
1220 } | 1274 } |
1221 } | 1275 |
1222 if (Getsign2 == TRUE) { | 1276 // back to original repetition rate |
1223 if (utc > tbegin2+2){ | 1277 ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS1); |
1224 if (Math1 > Frepbefore2) { | 1278 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1225 if (Ch2 > Ch2before) | 1279 |
1226 Sign2 = +1.0; | 1280 // measurement done |
1227 else | 1281 beatsign.measure = 0; |
1228 Sign2 = -1.0; | 1282 |
1229 } else { | 1283 // in the case of the optical beatnotes sign measurement |
1230 if (Ch2 > Ch2before) | 1284 // we induce fairly small steps in f_rep therefore it is |
1231 Sign2 = -1.0; | 1285 // good to check that we get the sign of the comb locking |
1232 else | 1286 // beatnote right in those cases |
1233 Sign2 = +1.0; | 1287 if (f_rep_sign != Sign1) |
1234 } | 1288 logmessage(ERROR, "merasured f_rep_sign does not agree with previous determination!"); |
1235 ad9912_set_frequency_w(&ad9912, 0, Frequency2); | |
1236 Getsign2 = FALSE; | |
1237 SetCtrlVal(MainPanel, PANEL_SIGN2, Sign2); | |
1238 } | |
1239 } | |
1240 if (Getsign3 == TRUE) { | |
1241 if (utc > tbegin3+2){ | |
1242 if (Ch3 > Frepbefore3) | |
1243 Sign3 = -1.0; | |
1244 else | |
1245 Sign3 = +1.0; | |
1246 ad9912_set_frequency_w(&ad9912, 0, Frequency3); | |
1247 Getsign3 = FALSE; | |
1248 SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3); | |
1249 } | |
1250 } | 1289 } |
1251 | 1290 |
1252 // select reference | 1291 // select reference |
1253 double f = 0.0; | 1292 double f = 0.0; |
1254 switch (dedrift.reference) { | 1293 switch (dedrift.reference) { |
1691 } | 1730 } |
1692 | 1731 |
1693 int CVICALLBACK CB_OnFindSign (int panel, int control, int event, | 1732 int CVICALLBACK CB_OnFindSign (int panel, int control, int event, |
1694 void *callbackData, int eventData1, int eventData2) | 1733 void *callbackData, int eventData1, int eventData2) |
1695 { | 1734 { |
1696 switch (event) | 1735 double step = 0.0; |
1697 { | 1736 switch (event) |
1698 case EVENT_COMMIT: | 1737 { |
1699 switch (control) | 1738 case EVENT_COMMIT: |
1700 { | 1739 switch (control) { |
1701 case PANEL_FINDSIGN1: | 1740 case PANEL_FINDSIGN1: |
1702 tbegin1 = utc; | 1741 beatsign.measure = LO; |
1703 Frepbefore1 = Math1; | 1742 beatsign.f_beat_zero = 0.0; |
1704 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency1) ; | 1743 step = f_lock_step_1; |
1705 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1+Frequencystep1) ; | |
1706 ad9912_set_frequency_w(&ad9912, 0, Frequency1+Frequencystep1); | |
1707 Getsign1 = TRUE; | |
1708 break; | 1744 break; |
1709 case PANEL_FINDSIGN2: | 1745 case PANEL_FINDSIGN2: |
1710 tbegin2 = utc; | 1746 beatsign.measure = HG; |
1711 Frepbefore2 = Math1; | 1747 beatsign.f_beat_zero = Ch2; |
1712 Ch2before = Ch2; | 1748 step = f_lock_step_2; |
1713 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency2) ; | |
1714 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2+Frequencystep2) ; | |
1715 ad9912_set_frequency_w(&ad9912, 0, Frequency2+Frequencystep2); | |
1716 Getsign2 = TRUE; | |
1717 break; | 1749 break; |
1718 case PANEL_FINDSIGN3: | 1750 case PANEL_FINDSIGN3: |
1719 tbegin3 = utc; | 1751 beatsign.measure = SR; |
1720 Frepbefore3 = Math1; | 1752 beatsign.f_beat_zero = Ch3; |
1721 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency3) ; | 1753 step = f_lock_step_3; |
1722 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency3+Frequencystep3) ; | |
1723 ad9912_set_frequency_w(&ad9912, 0, Frequency3+Frequencystep3); | |
1724 Getsign3 = TRUE; | |
1725 break; | 1754 break; |
1726 } | 1755 } |
1756 | |
1757 beatsign.t0 = utc; | |
1758 beatsign.f_rep_zero = Math1; | |
1759 | |
1760 // step the repetition rate | |
1761 beatsign.f0_DDS1 = ad9912.frequency[0]; | |
1762 ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS1 + step); | |
1763 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | |
1764 | |
1727 break; | 1765 break; |
1728 } | 1766 } |
1729 return 0; | 1767 return 0; |
1730 } | 1768 } |
1731 | 1769 |