# HG changeset patch # User Daniele Nicolodi # Date 1390398322 -3600 # Node ID e04123ab79ef6652aca3f8b83c22d7054f1cf374 # Parent 02044ad2749a0e69d7006d3f1d90dcaf237ea908 Fix recenter diff -r 02044ad2749a -r e04123ab79ef FXAnalyse.c --- a/FXAnalyse.c Wed Jan 22 14:45:07 2014 +0100 +++ b/FXAnalyse.c Wed Jan 22 14:45:22 2014 +0100 @@ -1352,10 +1352,6 @@ // recenter if (recenter.enabled) { - if (recenter.t0 == 0.0) { - - } - rollmean_accumulate(&rollmean_ch2, Ch2); rollmean_accumulate(&rollmean_ch3, Ch3); rollmean_accumulate(&rollmean_ch4, Ch4); @@ -1365,31 +1361,37 @@ if (recenter.Lo) { // adjust DDS2 frequency to keep Ch4 reading at 275 kHz double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); - freq = freq + 275000.0 - rollmean_ch4.mean; + double adj = 275000.0 - rollmean_ch4.mean; + freq = freq + adj; SetCtrlVal(MainPanel, PANEL_DDS2, freq); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, freq); + logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%5e", adj); } if (recenter.Hg) { // adjust DDS3 frequency to keep Ch2 reading at 10 kHz double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); - freq = freq + 10000 - rollmean_ch2.mean; + double adj = 10000 - rollmean_ch2.mean; + freq = freq + adj; SetCtrlVal(MainPanel, PANEL_DDS3, freq); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); + logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%5e", adj); } if (recenter.Sr) { // adjust DDS3 frequency to keep Ch3 reading at 10 kHz double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); - freq = freq + 10000 - rollmean_ch3.mean; + double adj = 10000 - rollmean_ch3.mean; + freq = freq + adj; SetCtrlVal(MainPanel, PANEL_DDS3, freq); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); + logmsg("recenter Hg beatnote (ch3) to 10 kHz: DDS3 adjustment=%5e", adj); } recenter.t0 = utc; - rollmean_zero(&rollmean_ch2, ROLLMEAN_N_OBS); - rollmean_zero(&rollmean_ch3, ROLLMEAN_N_OBS); - rollmean_zero(&rollmean_ch4, ROLLMEAN_N_OBS); + rollmean_zero(&rollmean_ch2); + rollmean_zero(&rollmean_ch3); + rollmean_zero(&rollmean_ch4); } } @@ -2014,7 +2016,7 @@ -int CVICALLBACK CB_OnReCentering (int panel, int control, int event, +int CVICALLBACK CB_RecenterEnable (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) @@ -2022,9 +2024,9 @@ case EVENT_COMMIT: GetCtrlVal(panel, control, &recenter.enabled); recenter.t0 = utc; - rollmean_zero(&rollmean_ch2, ROLLMEAN_N_OBS); - rollmean_zero(&rollmean_ch3, ROLLMEAN_N_OBS); - rollmean_zero(&rollmean_ch4, ROLLMEAN_N_OBS); + rollmean_zero(&rollmean_ch2); + rollmean_zero(&rollmean_ch3); + rollmean_zero(&rollmean_ch4); break; } return 0; @@ -2234,6 +2236,40 @@ return 0; } +int CVICALLBACK CB_RecenterInterval (int panel, int control, int event, + void *callbackData, int eventData1, int eventData2) +{ + switch (event) + { + case EVENT_COMMIT: + GetCtrlVal(panel, control, &recenter.interval); + break; + } + return 0; +} + +int CVICALLBACK CB_RecenterChannel (int panel, int control, int event, + void *callbackData, int eventData1, int eventData2) +{ + switch (event) + { + case EVENT_COMMIT: + switch (control) + { + case PANEL_RECENTER_LO: + GetCtrlVal(panel, control, &recenter.Lo); + break; + case PANEL_RECENTER_HG: + GetCtrlVal(panel, control, &recenter.Hg); + break; + case PANEL_RECENTER_SR: + GetCtrlVal(panel, control, &recenter.Sr); + break; + } + break; + } + return 0; +} int CVICALLBACK CB_DedriftDDSFreq (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { diff -r 02044ad2749a -r e04123ab79ef FXAnalyse.h --- a/FXAnalyse.h Wed Jan 22 14:45:07 2014 +0100 +++ b/FXAnalyse.h Wed Jan 22 14:45:22 2014 +0100 @@ -57,7 +57,7 @@ #define PANEL_DDS2 20 /* control type: numeric, callback function: CB_ChangeDDSOut */ #define PANEL_TEXTMSG 21 /* control type: textMsg, callback function: (none) */ #define PANEL_TEXTMSG_2 22 /* control type: textMsg, callback function: (none) */ -#define PANEL_RECENTER_INTERVAL 23 /* control type: numeric, callback function: CB_ChangeSlopeTime */ +#define PANEL_RECENTER_INTERVAL 23 /* control type: numeric, callback function: CB_RecenterInterval */ #define PANEL_SLOPETIME 24 /* control type: numeric, callback function: CB_ChangeSlopeTime */ #define PANEL_DEDRIFT_DDS_FREQ 25 /* control type: numeric, callback function: CB_DedriftDDSFreq */ #define PANEL_DDS1 26 /* control type: numeric, callback function: CB_ChangeDDSOut */ @@ -121,7 +121,7 @@ #define PANEL_SLOPE_REFERENCE 84 /* control type: ring, callback function: CB_OnSlopeReference */ #define PANEL_ESTIMATE_N3 85 /* control type: command, callback function: CB_OnEstimateN */ #define PANEL_INVERT_SLOPE_SIGN 86 /* control type: radioButton, callback function: CB_InvertSlopeSign */ -#define PANEL_RECENTER 87 /* control type: LED, callback function: CB_OnReCentering */ +#define PANEL_RECENTER 87 /* control type: LED, callback function: CB_RecenterEnable */ #define PANEL_MEASURE_SLOPE 88 /* control type: LED, callback function: CB_MeasureSlope */ #define PANEL_SLOPE_MEASURED 89 /* control type: numeric, callback function: (none) */ #define PANEL_RESET_DEDRIFT_DDS 90 /* control type: command, callback function: CB_ResetDedriftDDS */ @@ -148,9 +148,9 @@ #define PANEL_MATH3 111 /* control type: string, callback function: (none) */ #define PANEL_MATH2 112 /* control type: string, callback function: (none) */ #define PANEL_MATH1 113 /* control type: string, callback function: (none) */ -#define PANEL_CHECKBOX_3 114 /* control type: radioButton, callback function: (none) */ -#define PANEL_CHECKBOX_2 115 /* control type: radioButton, callback function: (none) */ -#define PANEL_CHECKBOX 116 /* control type: radioButton, callback function: (none) */ +#define PANEL_RECENTER_SR 114 /* control type: radioButton, callback function: CB_RecenterChannel */ +#define PANEL_RECENTER_HG 115 /* control type: radioButton, callback function: CB_RecenterChannel */ +#define PANEL_RECENTER_LO 116 /* control type: radioButton, callback function: CB_RecenterChannel */ /* Control Arrays: */ @@ -190,13 +190,15 @@ int CVICALLBACK CB_OnNEstimateSet(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnNStop(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnPlus10k(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); -int CVICALLBACK CB_OnReCentering(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnResetSlope(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnSlopeReference(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnStart(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnStartNCalculus(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnStop(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); +int CVICALLBACK CB_RecenterChannel(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); +int CVICALLBACK CB_RecenterEnable(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); +int CVICALLBACK CB_RecenterInterval(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_ResetDedriftDDS(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_SetSlope(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_ShowLog(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); diff -r 02044ad2749a -r e04123ab79ef FXAnalyse.uir Binary file FXAnalyse.uir has changed diff -r 02044ad2749a -r e04123ab79ef stat.c --- a/stat.c Wed Jan 22 14:45:07 2014 +0100 +++ b/stat.c Wed Jan 22 14:45:22 2014 +0100 @@ -1,3 +1,4 @@ +#include #include "stat.h" void stat_zero(struct stat *s) @@ -22,22 +23,22 @@ } -void rollmean_zero(struct rollmean *s, int wlen) +void rollmean_zero(struct rollmean *s) { - s->wlen = wlen; s->nobs = 0; s->mean = 0.0; s->acc = 0.0; - s->prev = 0.0; + memset(s->prev, 0, sizeof(s->prev)); } void rollmean_accumulate(struct rollmean *s, double value) { - s->acc = s->acc - s->prev + value; - if (s->nobs < s->wlen) - s->nobs++; + s->acc = s->acc + value - s->prev[s->nobs % _ROLLMEAN_WLEN]; + s->prev[s->nobs % _ROLLMEAN_WLEN] = value; + s->nobs++; + if (s->nobs < _ROLLMEAN_WLEN) + s->mean = s->acc / s->nobs; else - s->prev = s->acc; - s->mean = s->acc / s->nobs; + s->mean = s->acc / _ROLLMEAN_WLEN; } diff -r 02044ad2749a -r e04123ab79ef stat.h --- a/stat.h Wed Jan 22 14:45:07 2014 +0100 +++ b/stat.h Wed Jan 22 14:45:22 2014 +0100 @@ -11,17 +11,17 @@ void stat_zero(struct stat *s); void stat_accumulate(struct stat *s, double value); -#define ROLLMEAN_N_OBS 10 +/* must be a power of two */ +#define _ROLLMEAN_WLEN 16 struct rollmean { - int wlen; - int nobs; + unsigned int nobs; double mean; double acc; - double prev; + double prev[_ROLLMEAN_WLEN]; }; -void rollmean_zero(struct rollmean *s, int wlen); +void rollmean_zero(struct rollmean *s); void rollmean_accumulate(struct rollmean *s, double value); #endif