Skip to content

Commit

Permalink
енхансед респонсе калибратион
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-tenma-white committed Sep 15, 2020
1 parent aa337d4 commit a7327e6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
9 changes: 9 additions & 0 deletions calibration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ inline complexf SOL_compute_reflection(complexf sc, complexf oc, complexf load,
return -(a - d)*(b - c)/(a*(b - c) + 2.f*c*(a - b) + d*(-2.f*a + b + c));
}


// given the measured raw values for S,O,L and a DUT calibrated value, compute the outgoing power
// gain caused by the SFG loop between the DUT and port 1.
inline complexf SOL_compute_thru_gain(complexf sc, complexf oc, complexf load, complexf dut) {
complexf e11 = -(sc+oc-2.f*load) / (sc-oc);
complexf loopGain = e11 * dut;
return 1.f / (1.f - loopGain);
}

1 change: 1 addition & 0 deletions common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static constexpr uint32_t FREQUENCY_CHANGE_OVER = 140000000;
#define CALSTAT_EX CALSTAT_ISOLN
#define CALSTAT_APPLY (1<<8)
#define CALSTAT_INTERPOLATED (1<<9)
#define CALSTAT_ENHANCED_RESPONSE (1<<10)

#define ETERM_ED 0 /* error term directivity */
#define ETERM_ES 1 /* error term source match */
Expand Down
23 changes: 17 additions & 6 deletions main2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,13 @@ static bool processDataPoint() {
auto cal_thru_leak = y2-cal_thru_leak_r*x2;
thru = thru - (cal_thru_leak + refl*cal_thru_leak_r);

// calculate reflection
auto newRefl = SOL_compute_reflection(
current_props._cal_data[CAL_SHORT][freqIndex],
current_props._cal_data[CAL_OPEN][freqIndex],
current_props._cal_data[CAL_LOAD][freqIndex],
refl);

// apply thru response correction
if(current_props._cal_status & CALSTAT_THRU) {
auto refThru = current_props._cal_data[CAL_THRU][freqIndex];
Expand All @@ -1170,15 +1177,19 @@ static bool processDataPoint() {
// this causes ~0.05dB of S21 error but it will be a problem if attempting
// to use this code with low-spec hardware with lots of leakage.
refThru = refThru - (cal_thru_leak + refl*cal_thru_leak_r);
thru = thru / refThru;
}

// apply reflection correction
refl = SOL_compute_reflection(
auto thruGain = SOL_compute_thru_gain(
current_props._cal_data[CAL_SHORT][freqIndex],
current_props._cal_data[CAL_OPEN][freqIndex],
current_props._cal_data[CAL_LOAD][freqIndex],
refl);
newRefl);

if(cal_status & CALSTAT_ENHANCED_RESPONSE)
refThru *= thruGain;

thru = thru / refThru;
}

refl = newRefl;
}
apply_edelay(usbDP.freqIndex, refl, thru);
measuredFreqDomain[0][usbDP.freqIndex] = refl;
Expand Down
5 changes: 5 additions & 0 deletions ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_cal2_acb)
(void)data;
if (b){
if (item == 3) b->icon = (cal_status&CALSTAT_APPLY) ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK;
if (item == 4) b->icon = (cal_status&CALSTAT_ENHANCED_RESPONSE) ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK;
return;
}
switch (item) {
Expand All @@ -465,6 +466,9 @@ static UI_FUNCTION_ADV_CALLBACK(menu_cal2_acb)
if (cal_status)
cal_status ^= CALSTAT_APPLY;
break;
case 4: // ENHANCED RESPONSE
cal_status ^= CALSTAT_ENHANCED_RESPONSE;
break;
}
draw_menu();
draw_cal_status();
Expand Down Expand Up @@ -934,6 +938,7 @@ const menuitem_t menu_cal[] = {
{ MT_SUBMENU, 0, "SAVE", (const void *)menu_save },
{ MT_ADV_CALLBACK, 0, "RESET", (const void *)menu_cal2_acb },
{ MT_ADV_CALLBACK, 0, "APPLY", (const void *)menu_cal2_acb },
{ MT_ADV_CALLBACK, 0, "ENHANCED\nRESPONSE", (const void *)menu_cal2_acb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
Expand Down

0 comments on commit a7327e6

Please sign in to comment.