# HG changeset patch # User Daniele Nicolodi # Date 1390389017 -3600 # Node ID 7540703b8473458222b5f82c8dd1fe0b3f764304 # Parent fbd72d87b4dcf8a5e4bed8fedb9c21faf45e93ea Major code cleanup. Implement beatnote recentering. diff -r fbd72d87b4dc -r 7540703b8473 FXAnalyse.c --- a/FXAnalyse.c Tue Dec 17 17:21:17 2013 +0100 +++ b/FXAnalyse.c Wed Jan 22 12:10:17 2014 +0100 @@ -14,6 +14,7 @@ #include "DDS4xAD9912.h" #include "DDS_Fox.h" #include "muParserDLL.h" +#include "stat.h" #define SR_LOGGER_IP "145.238.204.91" #define DATAFOLDER "Z:\\Measures-2013" @@ -118,38 +119,64 @@ volatile bool Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE; double Sign1=1.0, Sign2=1.0, Sign3=0.0; -// slope cancelling + +struct stat stat_math1, stat_ch2, stat_ch3, stat_ch4, freq; +struct rollmean rollmean_ch1, rollmean_ch2, rollmean_ch3, rollmean_ch4; + -double dedrift_DDS_freq = 70e6; -int SlopeMeasuring = FALSE; -int StopSlopeCancellingOnUnlocked = TRUE; -double TimetoSlope = 60.0; -double SlopeMeasuringTimeBegin = 0.0; -double appliedSlope = 0.0; // currently applied frequency dedrifiting slope -int slopeX2 = FALSE; - -double limitotakoff=70.0; - -int ratio=10; //Recentre la frequence tous les ratios - -int FrequCorrec = FALSE, KeepFrequ = TRUE, KeepSlope = TRUE; -int Nratio = -1; -double MoyMath2 = 0.0, CenterFrequencyCh2 = 0.0; -int CenterFrequencyCh2ToDetermine = FALSE; +// dedrift +struct dedrift { + int enabled; // dedrift enabled + int reference; // reference frequency + int invert; // invert applied slope sign + int doubleslope; // double applied slope + int keep_freq; // keep current frequency value when dedrift is disabled + int keep_slope; // keep current slope value when dedrift is disabled + double freq0; // DDS center frequency + double threshold; // maximum allowed frequency change + double applied; // currently applied slope + double interval; // measurement duration + double t0; // beginning of currrent measurement interval +}; enum { - SLOPE_REFERENCE_MICROWAVE = 0, - SLOPE_REFERENCE_HG_CAVITY = 1, + DEDRIFT_REFERENCE_MICROWAVE = 0, + DEDRIFT_REFERENCE_HG = 1, +}; + +struct dedrift dedrift = { + .enabled = FALSE, + .reference = DEDRIFT_REFERENCE_MICROWAVE, + .invert = FALSE, + .doubleslope = FALSE, + .keep_freq = TRUE, + .keep_slope = TRUE, + .freq0 = 70e6, + .threshold = 100.0, + .applied = 0.0, + .interval = 40.0, + .t0 = 0.0 }; -int invertSlopeSign = 0; -int slopeReference = SLOPE_REFERENCE_MICROWAVE; -int KeepCentering = FALSE; -double Timetorecenter275K = 3600.0 * 10; -double Timetorecenter10K = 3600.0 * 3; -double CenteringTimeBegin275K = 0.0; -double CenteringTimeBegin10K = 0.0; +// recenter +struct recenter { + int enabled; // recenter enabled + int Lo; // recenter microwave beatnote + int Sr; // recenter Sr beatnote + int Hg; // recenter Hg beatnote + double interval; // interval + double t0; // beginning of current interval +}; + +struct recenter recenter = { + .enabled = FALSE, + .Lo = FALSE, + .Sr = FALSE, + .Hg = FALSE, + .interval = 1800.0, + .t0 = 0.0 +}; // panels @@ -184,35 +211,6 @@ } -struct stat { - int samples; - double mean; - double slope; - double previous; -}; - -void stat_zero(struct stat *s) -{ - s->samples = 0; - s->mean = 0.0; - s->slope = 0.0; - s->previous = 0.0; -} - -void stat_accumulate(struct stat *s, double value) -{ - s->samples += 1; - - if (s->samples > 1) - s->slope = (s->slope * (s->samples - 2) + 6 * (value - s->mean) / s->samples) / (s->samples + 1); - - s->mean = ((s->samples - 1) * s->mean + value) / s->samples; - - s->previous = value; -} - -struct stat stat_math1, stat_ch2, stat_ch4, stat_ch3, freq; - #define MIN(x, y) (x) < (y) ? (x) : (y) // MJD functiom used by the Sr programs @@ -377,7 +375,7 @@ DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, frequency); // initialyze 1x AD9956 DDS box - DDSFox_Initialize(&DDS1xAD9956, "145.238.205.58", 6665, dedrift_DDS_freq); + DDSFox_Initialize(&DDS1xAD9956, "145.238.205.58", 6665, dedrift.freq0); Ch1 = Ch2 = Ch3 = Ch4 = 0.0; @@ -661,8 +659,6 @@ SetCtrlVal(MainPanel, PANEL_CH2, Ch2); SetCtrlVal(MainPanel, PANEL_CH3, Ch3); SetCtrlVal(MainPanel, PANEL_CH4, Ch4); - - SetCtrlVal(MainPanel, PANEL_CENTERFREQUENCY, CenterFrequencyCh2); // compute Math1 = mupEval(MathParser1); @@ -1297,105 +1293,112 @@ } // select reference - double current = 0.0; - switch (slopeReference) { - case SLOPE_REFERENCE_MICROWAVE: - current = Math2; + double f = 0.0; + switch (dedrift.reference) { + case DEDRIFT_REFERENCE_MICROWAVE: + f = Math2; break; - case SLOPE_REFERENCE_HG_CAVITY: - current = Ch2 * 1062.5 / 1542.2; + case DEDRIFT_REFERENCE_HG: + f = Ch2 * 1062.5 / 1542.2; break; } - // stop slope cancelling if the comb is not locked - if (SlopeMeasuring & StopSlopeCancellingOnUnlocked + // stop dedrift if the comb is not locked + if ((dedrift.enabled) + & (dedrift.threshold != 0.0) & (freq.previous != 0.0) - & (fabs(current - freq.previous) > limitotakoff)) { + & (fabs(f - freq.previous) > dedrift.threshold)) { - if (! KeepSlope) { - appliedSlope = 0.0; - DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); - SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); + if (! dedrift.keep_slope) { + dedrift.applied = 0.0; + DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); + SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); } - if (! KeepFrequ) { - DDSFox_Set(&DDS1xAD9956, dedrift_DDS_freq, appliedSlope); + if (! dedrift.keep_freq) { + DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); } stat_zero(&freq); SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, freq.slope); - SlopeMeasuring = FALSE; + dedrift.enabled = FALSE; SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0); } - // slope measurement - if (SlopeMeasuring) + // dedrifting + if (dedrift.enabled) { // update slope measurement - stat_accumulate(&freq, current); + stat_accumulate(&freq, f); // update indicator SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, freq.slope); // update applied slope - if ((utc - SlopeMeasuringTimeBegin) > TimetoSlope) { + if ((utc - dedrift.t0) > dedrift.interval) { - if (invertSlopeSign) - appliedSlope = appliedSlope - freq.slope; + if (dedrift.invert) + dedrift.applied -= freq.slope; else - appliedSlope = appliedSlope + freq.slope; + dedrift.applied += freq.slope; - if (FrequCorrec) { - // proportional correction - - Nratio += 1; - if (Nratio >= 1) { - MoyMath2 = MoyMath2 + freq.mean; - } - if (Nratio == 1 && CenterFrequencyCh2ToDetermine == TRUE) { - CenterFrequencyCh2 = MoyMath2; - CenterFrequencyCh2ToDetermine = FALSE; - } - if (Nratio == ratio) { - double correction = (MoyMath2/ratio-CenterFrequencyCh2)/TimetoSlope; - appliedSlope = appliedSlope + correction; - Nratio = 0; - MoyMath2 = 0.0; - } - } + SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); - SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); - if (slopeX2) - DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope * 2.0); + if (dedrift.doubleslope) + DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied * 2.0); else - DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); + DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); - logmsg("Slope correction update (%+6g) %6g", freq.slope, appliedSlope); + logmsg("dedrift update (%+6g) %6g", freq.slope, dedrift.applied); stat_zero(&freq); - SlopeMeasuringTimeBegin = utc; + dedrift.t0 = utc; } } - // re-centering - if (KeepCentering) { - if ((utc - CenteringTimeBegin275K) > Timetorecenter275K && CenteringTimeBegin275K > 10) { - double frequency; - GetCtrlVal(MainPanel, PANEL_DDS2, &frequency); - // adjust DDS2 frequency to keep Ch4 reading around 275000 - frequency = frequency + 275000 - Ch4; - SetCtrlVal(MainPanel, PANEL_DDS2, frequency); - DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, frequency); - CenteringTimeBegin275K = utc; + // recenter + if (recenter.enabled) + { + if (recenter.t0 == 0.0) { + recenter.t0 = utc; + rollmean_zero(&rollmean_ch2, ROLLMEAN_N_OBS); + rollmean_zero(&rollmean_ch3, ROLLMEAN_N_OBS); + rollmean_zero(&rollmean_ch4, ROLLMEAN_N_OBS); } - if ((utc - CenteringTimeBegin10K) > Timetorecenter10K && CenteringTimeBegin10K > 10) { - double frequency; - GetCtrlVal(MainPanel, PANEL_DDS3, &frequency); - // adjust DDS3 frequency to keep Ch2 reading around 10000 - frequency = frequency + 10000 - Ch2; - SetCtrlVal(MainPanel, PANEL_DDS3, frequency); - DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, frequency); - CenteringTimeBegin10K = utc; + rollmean_accumulate(&rollmean_ch2, Ch2); + rollmean_accumulate(&rollmean_ch3, Ch3); + rollmean_accumulate(&rollmean_ch4, Ch4); + + if ((utc - recenter.t0) > recenter.interval) { + + 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; + SetCtrlVal(MainPanel, PANEL_DDS2, freq); + DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, freq); + } + + 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; + SetCtrlVal(MainPanel, PANEL_DDS3, freq); + DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); + } + + 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; + SetCtrlVal(MainPanel, PANEL_DDS3, freq); + DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); + } + + recenter.t0 = utc; + rollmean_zero(&rollmean_ch2, ROLLMEAN_N_OBS); + rollmean_zero(&rollmean_ch3, ROLLMEAN_N_OBS); + rollmean_zero(&rollmean_ch4, ROLLMEAN_N_OBS); } } @@ -1955,7 +1958,8 @@ void *callbackData, int eventData1, int eventData2) { - switch (event) { + switch (event) + { case EVENT_COMMIT: switch (control) { @@ -2024,7 +2028,8 @@ int CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { - switch (event) { + switch (event) + { case EVENT_COMMIT: GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &Ndiv); FrequDDS1 = 880000000.0 / Ndiv; @@ -2039,36 +2044,26 @@ int CVICALLBACK CB_MeasureSlope (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { - switch (event) { + switch (event) + { case EVENT_COMMIT: - - GetCtrlVal(panel, control, &SlopeMeasuring); - if (SlopeMeasuring) { - - SlopeMeasuringTimeBegin = utc; - + GetCtrlVal(panel, control, &dedrift.enabled); + if (dedrift.enabled) { + dedrift.t0 = utc; stat_zero(&freq); - - Nratio = -1; - MoyMath2 = 0.0; - CenterFrequencyCh2ToDetermine = TRUE ; - CenterFrequencyCh2 = 0.0; - - logmsg("Start slope measurement"); - + logmsg("dedrift start"); } else { - if (! KeepSlope) { - appliedSlope = 0.0; - DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); - SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); + if (! dedrift.keep_slope) { + dedrift.applied = 0.0; + DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); + SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); } - if (! KeepFrequ) { - DDSFox_Set(&DDS1xAD9956, dedrift_DDS_freq, appliedSlope); + if (! dedrift.keep_freq) { + DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); } stat_zero(&freq); SetCtrlVal(panel, PANEL_SLOPE_MEASURED, freq.slope); - - logmsg("Stop slope measurement"); + logmsg("dedrift stop"); } break; } @@ -2080,16 +2075,13 @@ void *callbackData, int eventData1, int eventData2) { - switch (event) { + switch (event) + { case EVENT_COMMIT: - CenterFrequencyCh2 = 0.0; - MoyMath2 = 0.0; - Nratio = -1; - CenterFrequencyCh2ToDetermine = TRUE ; - appliedSlope = 0.0; - SetCtrlVal(panel, PANEL_SLOPE_APPLIED, appliedSlope); - DDSFox_Set(&DDS1xAD9956, dedrift_DDS_freq, appliedSlope); - logmsg("Reset slope measurement"); + dedrift.applied = 0.0; + SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); + DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); + logmsg("dedrift reset"); break; } return 0; @@ -2100,9 +2092,10 @@ void *callbackData, int eventData1, int eventData2) { - switch (event) { + switch (event) + { case EVENT_COMMIT: - GetCtrlVal(MainPanel, PANEL_SLOPETIME, &TimetoSlope); + GetCtrlVal(MainPanel, PANEL_SLOPETIME, &dedrift.interval); break; } return 0; @@ -2112,23 +2105,24 @@ int CVICALLBACK CB_OnCROX (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { - switch (event) { + switch (event) + { case EVENT_COMMIT: switch (control) { case PANEL_CHECKBOX_CORRFREQU: // enable frequency correction - GetCtrlVal(MainPanel, PANEL_CHECKBOX_CORRFREQU, &FrequCorrec); + // GetCtrlVal(MainPanel, PANEL_CHECKBOX_CORRFREQU, &FrequCorrec); break; case PANEL_CHECKBOX_KEEP: // keep current dedrifting frequency when dedrifting is disabled - GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEP, &KeepFrequ); + GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEP, &dedrift.keep_freq); break; case PANEL_CHECKBOX_KEEPSLOPE: // keep current dedrifting slope when dedrifting is disabled - GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEPSLOPE, &KeepSlope); + GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEPSLOPE, &dedrift.keep_slope); break; } break; @@ -2141,28 +2135,13 @@ int CVICALLBACK CB_OnReCentering (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { - bool BoxChecked = FALSE; - switch (event) - { + { case EVENT_COMMIT: - - if (control== PANEL_CHECKBOX_RECENTER) - { - GetCtrlVal(MainPanel, PANEL_CHECKBOX_RECENTER, &BoxChecked) ; - if (BoxChecked) { - KeepCentering=TRUE ; - CenteringTimeBegin275K=utc; - CenteringTimeBegin10K=utc; - } - else {KeepCentering=FALSE ;} - - } - - + GetCtrlVal(panel, control, &recenter.enabled); + recenter.t0 = 0.0; break; - - } + } return 0; } @@ -2170,10 +2149,12 @@ int CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { + int value; switch (event) { case EVENT_COMMIT: - GetCtrlVal(MainPanel, PANEL_CHECKBOX_STOPIFAUTODE, &StopSlopeCancellingOnUnlocked); + GetCtrlVal(MainPanel, PANEL_CHECKBOX_STOPIFAUTODE, &value); + dedrift.threshold = value ? 100.0 : 0.0; break; } return 0; @@ -2185,7 +2166,7 @@ switch (event) { case EVENT_COMMIT: - GetCtrlVal(MainPanel, PANEL_SLOPE_REFERENCE, &slopeReference); + GetCtrlVal(MainPanel, PANEL_SLOPE_REFERENCE, &dedrift.reference); break; } return 0; @@ -2278,8 +2259,8 @@ switch (event) { case EVENT_COMMIT: - GetCtrlVal(panel, control, &appliedSlope); - DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); + GetCtrlVal(panel, control, &dedrift.applied); + DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); break; } return 0; @@ -2291,7 +2272,7 @@ switch (event) { case EVENT_COMMIT: - GetCtrlVal(panel, control, &invertSlopeSign); + GetCtrlVal(panel, control, &dedrift.invert); break; } return 0; @@ -2304,19 +2285,15 @@ { case EVENT_COMMIT: // stop slope measurement and reset slope - SlopeMeasuring = 0; - SetCtrlVal(panel, PANEL_MEASURE_SLOPE, SlopeMeasuring); - CenterFrequencyCh2 = 0.0; - MoyMath2 = 0.0; - Nratio = -1; - CenterFrequencyCh2ToDetermine = TRUE ; - appliedSlope = 0.0; - SetCtrlVal(panel, PANEL_SLOPE_APPLIED, appliedSlope); + dedrift.enabled = FALSE; + SetCtrlVal(panel, PANEL_MEASURE_SLOPE, 0); + dedrift.applied = 0.0; + SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); // reset DDS DDSFox_Reset(&DDS1xAD9956); DDSFox_SetProfile(&DDS1xAD9956); DDSFox_SetDiv(&DDS1xAD9956, 1); - DDSFox_Set(&DDS1xAD9956, dedrift_DDS_freq, appliedSlope); + DDSFox_Set(&DDS1xAD9956, dedrift.freq0, 0.0); break; } return 0; @@ -2367,7 +2344,7 @@ switch (event) { case EVENT_COMMIT: - GetCtrlVal(panel, control, &slopeX2); + GetCtrlVal(panel, control, &dedrift.doubleslope); break; } return 0; @@ -2379,8 +2356,8 @@ switch (event) { case EVENT_COMMIT: - GetCtrlVal(panel, control, &dedrift_DDS_freq); - DDSFox_Set(&DDS1xAD9956, dedrift_DDS_freq, appliedSlope); + GetCtrlVal(panel, control, &dedrift.freq0); + DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); break; } return 0; diff -r fbd72d87b4dc -r 7540703b8473 FXAnalyse.h --- a/FXAnalyse.h Tue Dec 17 17:21:17 2013 +0100 +++ b/FXAnalyse.h Wed Jan 22 12:10:17 2014 +0100 @@ -1,6 +1,6 @@ /**************************************************************************/ /* LabWindows/CVI User Interface Resource (UIR) Include File */ -/* Copyright (c) National Instruments 2013. All Rights Reserved. */ +/* Copyright (c) National Instruments 2014. All Rights Reserved. */ /* */ /* WARNING: Do not add to, delete from, or otherwise modify the contents */ /* of this include file. */ @@ -57,94 +57,100 @@ #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_SLOPETIME 23 /* control type: numeric, callback function: CB_ChangeSlopeTime */ -#define PANEL_DEDRIFT_DDS_FREQ 24 /* control type: numeric, callback function: CB_DedriftDDSFreq */ -#define PANEL_DDS1 25 /* control type: numeric, callback function: CB_ChangeDDSOut */ -#define PANEL_CHANGENDIV 26 /* control type: numeric, callback function: CB_OnChangeNdiv */ -#define PANEL_N3CHOICE 27 /* control type: numeric, callback function: CB_ChangeN */ -#define PANEL_N3CALCULUS 28 /* control type: command, callback function: CB_OnNCalculus */ -#define PANEL_N1CHOICE 29 /* control type: numeric, callback function: CB_ChangeN */ -#define PANEL_N2CHOICE 30 /* control type: numeric, callback function: CB_ChangeN */ -#define PANEL_N2CALCULUS 31 /* control type: command, callback function: CB_OnNCalculus */ -#define PANEL_DDS4STEP 32 /* control type: ring, callback function: CB_ChangeDDSStep */ -#define PANEL_DDS3STEP 33 /* control type: ring, callback function: CB_ChangeDDSStep */ -#define PANEL_DDS2STEP 34 /* control type: ring, callback function: CB_ChangeDDSStep */ -#define PANEL_CENTERFREQUENCY 35 /* control type: numeric, callback function: (none) */ -#define PANEL_SLOPE_APPLIED 36 /* control type: numeric, callback function: CB_SetSlope */ -#define PANEL_CHECKBOX_MATH5PLOT 37 /* control type: radioButton, callback function: CB_OnFreqPlot */ -#define PANEL_CHECKBOX_MATH4PLOT 38 /* control type: radioButton, callback function: CB_OnFreqPlot */ -#define PANEL_CHECKBOX_MATH4ALLAN 39 /* control type: radioButton, callback function: CB_OnAllanPlot */ -#define PANEL_DDS1STEP 40 /* control type: ring, callback function: CB_ChangeDDSStep */ -#define PANEL_TEXTMSG_15 41 /* control type: textMsg, callback function: (none) */ -#define PANEL_CHECKBOX_MATH5ALLAN 42 /* control type: radioButton, callback function: CB_OnAllanPlot */ -#define PANEL_CHECKBOX_MATH3PLOT 43 /* control type: radioButton, callback function: CB_OnFreqPlot */ -#define PANEL_CHECKBOX_MATH5SAVE 44 /* control type: radioButton, callback function: (none) */ -#define PANEL_SR_LOGGER 45 /* control type: radioButton, callback function: (none) */ -#define PANEL_CHECKBOX_MATH4SAVE 46 /* control type: radioButton, callback function: (none) */ -#define PANEL_CHECKBOX_MATH3ALLAN 47 /* control type: radioButton, callback function: CB_OnAllanPlot */ -#define PANEL_MATHSTRING4 48 /* control type: string, callback function: CB_ChangeMath */ -#define PANEL_CHECKBOX_MATH2PLOT 49 /* control type: radioButton, callback function: CB_OnFreqPlot */ -#define PANEL_CHECKBOX_MATH3SAVE 50 /* control type: radioButton, callback function: (none) */ -#define PANEL_CHECKBOX_MATH2SAVE 51 /* control type: radioButton, callback function: (none) */ -#define PANEL_CHECKBOX_MATH2ALLAN 52 /* control type: radioButton, callback function: CB_OnAllanPlot */ -#define PANEL_MATHSTRING3 53 /* control type: string, callback function: CB_ChangeMath */ -#define PANEL_MATHSTRING1 54 /* control type: string, callback function: CB_ChangeMath */ -#define PANEL_MATHSTRING2 55 /* control type: string, callback function: CB_ChangeMath */ -#define PANEL_TEXTMSG_16 56 /* control type: textMsg, callback function: (none) */ -#define PANEL_MINUS10KDDS1 57 /* control type: command, callback function: CB_OnMinus10k */ -#define PANEL_MINUS10KDDS4 58 /* control type: command, callback function: CB_OnMinus10k */ -#define PANEL_MINUS10KDDS3 59 /* control type: command, callback function: CB_OnMinus10k */ -#define PANEL_MINUS10KDDS2 60 /* control type: command, callback function: CB_OnMinus10k */ -#define PANEL_PLUS10KDDS4 61 /* control type: command, callback function: CB_OnPlus10k */ -#define PANEL_PLUS10KDDS3 62 /* control type: command, callback function: CB_OnPlus10k */ -#define PANEL_PLUS10KDDS1 63 /* control type: command, callback function: CB_OnPlus10k */ -#define PANEL_PLUS10KDDS2 64 /* control type: command, callback function: CB_OnPlus10k */ -#define PANEL_MATHSTRING5 65 /* control type: textBox, callback function: CB_ChangeMath */ -#define PANEL_UTC 66 /* control type: numeric, callback function: (none) */ -#define PANEL_TIME 67 /* control type: string, callback function: (none) */ -#define PANEL_DDS4 68 /* control type: numeric, callback function: CB_ChangeDDSOut */ -#define PANEL_DDS3 69 /* control type: numeric, callback function: CB_ChangeDDSOut */ -#define PANEL_N1CALCULUS 70 /* control type: command, callback function: CB_OnNCalculus */ -#define PANEL_FINDSIGN3 71 /* control type: command, callback function: CB_OnFindSign */ -#define PANEL_SIGN3 72 /* control type: numeric, callback function: CB_Sign3 */ -#define PANEL_FINDSIGN2 73 /* control type: command, callback function: CB_OnFindSign */ -#define PANEL_SIGN2 74 /* control type: numeric, callback function: (none) */ -#define PANEL_FINDSIGN1 75 /* control type: command, callback function: CB_OnFindSign */ -#define PANEL_SIGN1 76 /* control type: numeric, callback function: (none) */ -#define PANEL_FIND10K3 77 /* control type: command, callback function: CB_OnFind275K */ -#define PANEL_FIND275K2 78 /* control type: command, callback function: CB_OnFind275K */ -#define PANEL_RESETSLOPE 79 /* control type: command, callback function: CB_OnResetSlope */ -#define PANEL_CHECKBOX_STOPIFAUTODE 80 /* control type: radioButton, callback function: CB_OnStopSlopeCancellingOnUnlocked */ -#define PANEL_CHECKBOX_RECENTER 81 /* control type: radioButton, callback function: CB_OnReCentering */ +#define PANEL_RECENTER_INTERVAL 23 /* control type: numeric, callback function: CB_ChangeSlopeTime */ +#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 */ +#define PANEL_CHANGENDIV 27 /* control type: numeric, callback function: CB_OnChangeNdiv */ +#define PANEL_N3CHOICE 28 /* control type: numeric, callback function: CB_ChangeN */ +#define PANEL_N3CALCULUS 29 /* control type: command, callback function: CB_OnNCalculus */ +#define PANEL_N1CHOICE 30 /* control type: numeric, callback function: CB_ChangeN */ +#define PANEL_N2CHOICE 31 /* control type: numeric, callback function: CB_ChangeN */ +#define PANEL_N2CALCULUS 32 /* control type: command, callback function: CB_OnNCalculus */ +#define PANEL_DDS4STEP 33 /* control type: ring, callback function: CB_ChangeDDSStep */ +#define PANEL_DDS3STEP 34 /* control type: ring, callback function: CB_ChangeDDSStep */ +#define PANEL_DDS2STEP 35 /* control type: ring, callback function: CB_ChangeDDSStep */ +#define PANEL_CENTERFREQUENCY 36 /* control type: numeric, callback function: (none) */ +#define PANEL_SLOPE_APPLIED 37 /* control type: numeric, callback function: CB_SetSlope */ +#define PANEL_CHECKBOX_MATH5PLOT 38 /* control type: radioButton, callback function: CB_OnFreqPlot */ +#define PANEL_CHECKBOX_MATH4PLOT 39 /* control type: radioButton, callback function: CB_OnFreqPlot */ +#define PANEL_CHECKBOX_MATH4ALLAN 40 /* control type: radioButton, callback function: CB_OnAllanPlot */ +#define PANEL_DDS1STEP 41 /* control type: ring, callback function: CB_ChangeDDSStep */ +#define PANEL_TEXTMSG_15 42 /* control type: textMsg, callback function: (none) */ +#define PANEL_CHECKBOX_MATH5ALLAN 43 /* control type: radioButton, callback function: CB_OnAllanPlot */ +#define PANEL_CHECKBOX_MATH3PLOT 44 /* control type: radioButton, callback function: CB_OnFreqPlot */ +#define PANEL_CHECKBOX_MATH5SAVE 45 /* control type: radioButton, callback function: (none) */ +#define PANEL_SR_LOGGER 46 /* control type: radioButton, callback function: (none) */ +#define PANEL_CHECKBOX_MATH4SAVE 47 /* control type: radioButton, callback function: (none) */ +#define PANEL_CHECKBOX_MATH3ALLAN 48 /* control type: radioButton, callback function: CB_OnAllanPlot */ +#define PANEL_MATHSTRING4 49 /* control type: string, callback function: CB_ChangeMath */ +#define PANEL_CHECKBOX_MATH2PLOT 50 /* control type: radioButton, callback function: CB_OnFreqPlot */ +#define PANEL_CHECKBOX_MATH3SAVE 51 /* control type: radioButton, callback function: (none) */ +#define PANEL_CHECKBOX_MATH2SAVE 52 /* control type: radioButton, callback function: (none) */ +#define PANEL_CHECKBOX_MATH2ALLAN 53 /* control type: radioButton, callback function: CB_OnAllanPlot */ +#define PANEL_MATHSTRING3 54 /* control type: string, callback function: CB_ChangeMath */ +#define PANEL_MATHSTRING1 55 /* control type: string, callback function: CB_ChangeMath */ +#define PANEL_MATHSTRING2 56 /* control type: string, callback function: CB_ChangeMath */ +#define PANEL_TEXTMSG_16 57 /* control type: textMsg, callback function: (none) */ +#define PANEL_MINUS10KDDS1 58 /* control type: command, callback function: CB_OnMinus10k */ +#define PANEL_MINUS10KDDS4 59 /* control type: command, callback function: CB_OnMinus10k */ +#define PANEL_MINUS10KDDS3 60 /* control type: command, callback function: CB_OnMinus10k */ +#define PANEL_MINUS10KDDS2 61 /* control type: command, callback function: CB_OnMinus10k */ +#define PANEL_PLUS10KDDS4 62 /* control type: command, callback function: CB_OnPlus10k */ +#define PANEL_PLUS10KDDS3 63 /* control type: command, callback function: CB_OnPlus10k */ +#define PANEL_PLUS10KDDS1 64 /* control type: command, callback function: CB_OnPlus10k */ +#define PANEL_PLUS10KDDS2 65 /* control type: command, callback function: CB_OnPlus10k */ +#define PANEL_MATHSTRING5 66 /* control type: textBox, callback function: CB_ChangeMath */ +#define PANEL_UTC 67 /* control type: numeric, callback function: (none) */ +#define PANEL_TIME 68 /* control type: string, callback function: (none) */ +#define PANEL_DDS4 69 /* control type: numeric, callback function: CB_ChangeDDSOut */ +#define PANEL_DDS3 70 /* control type: numeric, callback function: CB_ChangeDDSOut */ +#define PANEL_N1CALCULUS 71 /* control type: command, callback function: CB_OnNCalculus */ +#define PANEL_FINDSIGN3 72 /* control type: command, callback function: CB_OnFindSign */ +#define PANEL_SIGN3 73 /* control type: numeric, callback function: CB_Sign3 */ +#define PANEL_FINDSIGN2 74 /* control type: command, callback function: CB_OnFindSign */ +#define PANEL_SIGN2 75 /* control type: numeric, callback function: (none) */ +#define PANEL_FINDSIGN1 76 /* control type: command, callback function: CB_OnFindSign */ +#define PANEL_SIGN1 77 /* control type: numeric, callback function: (none) */ +#define PANEL_FIND10K3 78 /* control type: command, callback function: CB_OnFind275K */ +#define PANEL_FIND275K2 79 /* control type: command, callback function: CB_OnFind275K */ +#define PANEL_RESETSLOPE 80 /* control type: command, callback function: CB_OnResetSlope */ +#define PANEL_CHECKBOX_STOPIFAUTODE 81 /* control type: radioButton, callback function: CB_OnStopSlopeCancellingOnUnlocked */ #define PANEL_CHECKBOX_KEEPSLOPE 82 /* control type: radioButton, callback function: CB_OnCROX */ #define PANEL_CHECKBOX_KEEP 83 /* control type: radioButton, callback function: CB_OnCROX */ #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_MEASURE_SLOPE 87 /* control type: LED, callback function: CB_MeasureSlope */ -#define PANEL_SLOPE_MEASURED 88 /* control type: numeric, callback function: (none) */ -#define PANEL_RESET_DEDRIFT_DDS 89 /* control type: command, callback function: CB_ResetDedriftDDS */ -#define PANEL_SAVE_RAW_DATA 90 /* control type: radioButton, callback function: (none) */ -#define PANEL_SHOWLOG 91 /* control type: radioButton, callback function: CB_ShowLog */ -#define PANEL_SLOPEX2 92 /* control type: radioButton, callback function: CB_SlopeX2 */ -#define PANEL_SAVE_DDS_FREQS 93 /* control type: radioButton, callback function: (none) */ -#define PANEL_DECORATION_2 94 /* control type: deco, callback function: (none) */ -#define PANEL_DECORATION 95 /* control type: deco, callback function: (none) */ -#define PANEL_DECORATION_3 96 /* control type: deco, callback function: (none) */ -#define PANEL_TEXTMSG_6 97 /* control type: textMsg, callback function: (none) */ -#define PANEL_TEXTMSG_21 98 /* control type: textMsg, callback function: (none) */ -#define PANEL_TEXTMSG_7 99 /* control type: textMsg, callback function: (none) */ -#define PANEL_DECORATION_4 100 /* control type: deco, callback function: (none) */ -#define PANEL_DECORATION_7 101 /* control type: deco, callback function: (none) */ -#define PANEL_DECORATION_6 102 /* control type: deco, callback function: (none) */ -#define PANEL_DECORATION_5 103 /* control type: deco, callback function: (none) */ -#define PANEL_TEXTMSG_20 104 /* control type: textMsg, callback function: (none) */ -#define PANEL_TEXTMSG_19 105 /* control type: textMsg, callback function: (none) */ -#define PANEL_MATH4 106 /* control type: string, callback function: (none) */ -#define PANEL_MATH5 107 /* control type: string, callback function: (none) */ -#define PANEL_MATH3 108 /* control type: string, callback function: (none) */ -#define PANEL_MATH2 109 /* control type: string, callback function: (none) */ -#define PANEL_MATH1 110 /* control type: string, callback function: (none) */ +#define PANEL_RECENTER 87 /* control type: LED, callback function: CB_OnReCentering */ +#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 */ +#define PANEL_SAVE_RAW_DATA 91 /* control type: radioButton, callback function: (none) */ +#define PANEL_SHOWLOG 92 /* control type: radioButton, callback function: CB_ShowLog */ +#define PANEL_SLOPEX2 93 /* control type: radioButton, callback function: CB_SlopeX2 */ +#define PANEL_SAVE_DDS_FREQS 94 /* control type: radioButton, callback function: (none) */ +#define PANEL_DECORATION_2 95 /* control type: deco, callback function: (none) */ +#define PANEL_DECORATION_8 96 /* control type: deco, callback function: (none) */ +#define PANEL_DECORATION 97 /* control type: deco, callback function: (none) */ +#define PANEL_DECORATION_3 98 /* control type: deco, callback function: (none) */ +#define PANEL_TEXTMSG_6 99 /* control type: textMsg, callback function: (none) */ +#define PANEL_TEXTMSG_22 100 /* control type: textMsg, callback function: (none) */ +#define PANEL_TEXTMSG_21 101 /* control type: textMsg, callback function: (none) */ +#define PANEL_TEXTMSG_7 102 /* control type: textMsg, callback function: (none) */ +#define PANEL_DECORATION_4 103 /* control type: deco, callback function: (none) */ +#define PANEL_DECORATION_7 104 /* control type: deco, callback function: (none) */ +#define PANEL_DECORATION_6 105 /* control type: deco, callback function: (none) */ +#define PANEL_DECORATION_5 106 /* control type: deco, callback function: (none) */ +#define PANEL_TEXTMSG_20 107 /* control type: textMsg, callback function: (none) */ +#define PANEL_TEXTMSG_19 108 /* control type: textMsg, callback function: (none) */ +#define PANEL_MATH4 109 /* control type: string, callback function: (none) */ +#define PANEL_MATH5 110 /* control type: string, callback function: (none) */ +#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) */ /* Control Arrays: */ diff -r fbd72d87b4dc -r 7540703b8473 FXAnalyse.uir Binary file FXAnalyse.uir has changed diff -r fbd72d87b4dc -r 7540703b8473 stat.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stat.c Wed Jan 22 12:10:17 2014 +0100 @@ -0,0 +1,43 @@ +#include "stat.h" + +void stat_zero(struct stat *s) +{ + s->samples = 0; + s->mean = 0.0; + s->slope = 0.0; + s->previous = 0.0; +} + + +void stat_accumulate(struct stat *s, double value) +{ + s->samples += 1; + + if (s->samples > 1) + s->slope = (s->slope * (s->samples - 2) + 6 * (value - s->mean) / s->samples) / (s->samples + 1); + + s->mean = ((s->samples - 1) * s->mean + value) / s->samples; + + s->previous = value; +} + + +void rollmean_zero(struct rollmean *s, int wlen) +{ + s->wlen = wlen; + s->nobs = 0; + s->mean = 0.0; + s->acc = 0.0; + s->prev = 0.0; +} + + +void rollmean_accumulate(struct rollmean *s, double value) +{ + s->acc = s->acc - s->prev + value; + if (s->nobs < s->wlen) + s->nobs++; + else + s->prev = s->acc; + s->mean = s->acc / s->nobs; +} diff -r fbd72d87b4dc -r 7540703b8473 stat.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stat.h Wed Jan 22 12:10:17 2014 +0100 @@ -0,0 +1,27 @@ +#ifndef __STAT_H__ +#define __STAT_H__ + +struct stat { + int samples; + double mean; + double slope; + double previous; +}; + +void stat_zero(struct stat *s); +void stat_accumulate(struct stat *s, double value); + +#define ROLLMEAN_N_OBS 10 + +struct rollmean { + int wlen; + int nobs; + double mean; + double acc; + double prev; +}; + +void rollmean_zero(struct rollmean *s, int wlen); +void rollmean_accumulate(struct rollmean *s, double value); + +#endif