From 889d675836f0b6aeb22ed3abcf99b182a68c624c Mon Sep 17 00:00:00 2001 From: cho45 Date: Tue, 10 Sep 2019 22:39:20 +0900 Subject: [PATCH 1/8] TDR feature --- fft.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.c | 34 ++++++++++++++++++++++++ nanovna.h | 12 +++++++++ plot.c | 11 ++++++-- ui.c | 35 +++++++++++++++++++++++++ 5 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 fft.h diff --git a/fft.h b/fft.h new file mode 100644 index 0000000..bf5cb11 --- /dev/null +++ b/fft.h @@ -0,0 +1,78 @@ +/* + * fft.h is Based on + * Free FFT and convolution (C) + * + * Copyright (c) 2019 Project Nayuki. (MIT License) + * https://www.nayuki.io/page/free-small-fft-in-multiple-languages + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * - The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * - The Software is provided "as is", without warranty of any kind, express or + * implied, including but not limited to the warranties of merchantability, + * fitness for a particular purpose and noninfringement. In no event shall the + * authors or copyright holders be liable for any claim, damages or other + * liability, whether in an action of contract, tort or otherwise, arising from, + * out of or in connection with the Software or the use or other dealings in the + * Software. + */ + + +#include +#include + +static uint8_t reverse_bits(uint8_t x, int n) { + uint8_t result = 0; + for (int i = 0; i < n; i++, x >>= 1) + result = (result << 1) | (x & 1U); + return result; +} + +/*** + * dir = forward: 0, inverse: 1 + */ +void fft(float array[][2], uint8_t n, uint8_t dir) { + int levels = 0; // Compute levels = floor(log2(n)) + for (uint8_t temp = n; temp > 1U; temp >>= 1) + levels++; + + uint8_t real = dir & 1; + uint8_t imag = ~real & 1; + + for (uint8_t i = 0; i < n; i++) { + uint8_t j = reverse_bits(i, levels); + if (j > i) { + float temp = array[i][real]; + array[i][real] = array[j][real]; + array[j][real] = temp; + temp = array[i][imag]; + array[i][imag] = array[j][imag]; + array[j][imag] = temp; + } + } + + // Cooley-Tukey decimation-in-time radix-2 FFT + for (uint8_t size = 2; size <= n; size *= 2) { + uint8_t halfsize = size / 2; + uint8_t tablestep = n / size; + for (uint8_t i = 0; i < n; i += size) { + for (uint8_t j = i, k = 0; j < i + halfsize; j++, k += tablestep) { + uint8_t l = j + halfsize; + float tpre = array[l][real] * cos(2 * M_PI * k / n) + array[l][imag] * sin(2 * M_PI * k / n); + float tpim = -array[l][real] * sin(2 * M_PI * k / n) + array[l][imag] * cos(2 * M_PI * k / n); + array[l][real] = array[j][real] - tpre; + array[l][imag] = array[j][imag] - tpim; + array[j][real] += tpre; + array[j][imag] += tpim; + } + } + if (size == n) // Prevent overflow in 'size *= 2' + break; + } +} + diff --git a/main.c b/main.c index 4bafd45..23feb52 100644 --- a/main.c +++ b/main.c @@ -23,6 +23,7 @@ #include "usbcfg.h" #include "si5351.h" #include "nanovna.h" +#include "fft.h" #include #include @@ -36,6 +37,7 @@ static void apply_error_term(void); static void apply_error_term_at(int i); static void cal_interpolate(int s); +static void transform_domain(void); void sweep(void); @@ -54,6 +56,8 @@ int8_t redraw_requested = FALSE; int8_t stop_the_world = FALSE; int16_t vbat = 0; +uint8_t domain = DOMAIN_TIME; +uint8_t tdrfunc = TDR_IMPULSE; static THD_WORKING_AREA(waThread1, 640); static THD_FUNCTION(Thread1, arg) { @@ -82,6 +86,7 @@ static THD_FUNCTION(Thread1, arg) draw_battery_status(); } + transform_domain(); /* calculate trace coordinates */ plot_into_index(measured); /* plot trace as raster */ @@ -107,6 +112,35 @@ toggle_sweep(void) sweep_enabled = !sweep_enabled; } +static +void +transform_domain(void) +{ + if (domain != DOMAIN_TIME) return; // nothing to do for freq domain + // use spi_buffer as temporary buffer + // and calculate ifft for time domain + float* tmp = (float*)spi_buffer; + for (int ch = 0; ch < 2; ch++) { + for (int i = 0; i < 128; i++) { + tmp[i*2+0] = 0.0; + tmp[i*2+1] = 0.0; + } + memcpy(spi_buffer, measured[ch], sizeof(measured[0])); + fft((float(*)[2])tmp, 128, 1); + memcpy(measured[ch], spi_buffer, sizeof(measured[0])); + for (int i = 0; i < 101; i++) { + measured[ch][i][0] /= 128.0; + measured[ch][i][1] /= 128.0; + } + if (tdrfunc == TDR_STEP) { + for (int i = 1; i < 101; i++) { + measured[ch][i][0] += measured[ch][i-1][0]; + measured[ch][i][1] += measured[ch][i-1][1]; + } + } + } +} + static void cmd_pause(BaseSequentialStream *chp, int argc, char *argv[]) { (void)chp; diff --git a/nanovna.h b/nanovna.h index 655e78e..a33cf5e 100644 --- a/nanovna.h +++ b/nanovna.h @@ -22,8 +22,20 @@ /* * main.c */ + extern float measured[2][101][2]; +enum { + DOMAIN_FREQ, DOMAIN_TIME +}; + +enum { + TDR_IMPULSE, TDR_STEP +}; + +extern uint8_t domain; +extern uint8_t tdrfunc; + #define CAL_LOAD 0 #define CAL_OPEN 1 #define CAL_SHORT 2 diff --git a/plot.c b/plot.c index 2367372..91ef03a 100644 --- a/plot.c +++ b/plot.c @@ -1367,8 +1367,15 @@ cell_draw_marker_info(int m, int n, int w, int h) chsnprintf(buf, sizeof buf, "%d:", active_marker + 1); cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); xpos += 16; - frequency_string(buf, sizeof buf, frequencies[idx]); - cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); + if (domain == DOMAIN_FREQ) { + frequency_string(buf, sizeof buf, frequencies[idx]); + cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); + } else { +#define SPEED_OF_LIGHT 299792458 + float distance = ((float)idx * (float)SPEED_OF_LIGHT) / ( (float)(frequencies[1] - frequencies[0]) * 128.0 * 2.0); + chsnprintf(buf, sizeof buf, "%f m", distance); + cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); + } // draw marker delta if (previous_marker >= 0 && active_marker != previous_marker && markers[previous_marker].enabled) { diff --git a/ui.c b/ui.c index 0012db5..59f2255 100644 --- a/ui.c +++ b/ui.c @@ -664,6 +664,24 @@ menu_channel_cb(int item) ui_mode_normal(); } +static void +menu_tdr_cb(int item) +{ + switch (item) { + case 0: + domain = (domain == DOMAIN_FREQ) ? DOMAIN_TIME : DOMAIN_FREQ; + break; + case 1: + tdrfunc = TDR_IMPULSE; + break; + case 2: + tdrfunc = TDR_STEP; + break; + } + + ui_mode_normal(); +} + static void choose_active_marker(void) { @@ -874,11 +892,20 @@ const menuitem_t menu_channel[] = { { MT_NONE, NULL, NULL } // sentinel }; +const menuitem_t menu_tdr[] = { + { MT_CALLBACK, "TDR MODE", menu_tdr_cb }, + { MT_CALLBACK, "IMPULSE", menu_tdr_cb }, + { MT_CALLBACK, "STEP", menu_tdr_cb }, + { MT_CANCEL, S_LARROW" BACK", NULL }, + { MT_NONE, NULL, NULL } // sentinel +}; + const menuitem_t menu_display[] = { { MT_SUBMENU, "TRACE", menu_trace }, { MT_SUBMENU, "FORMAT", menu_format }, { MT_SUBMENU, "SCALE", menu_scale }, { MT_SUBMENU, "CHANNEL", menu_channel }, + { MT_SUBMENU, "TDR", menu_tdr }, { MT_CANCEL, S_LARROW" BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; @@ -1235,6 +1262,14 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, *bg = 0x0000; *fg = 0xffff; } + } else if (menu == menu_tdr) { + if ((item == 0 && domain == DOMAIN_TIME) + || (item == 1 && tdrfunc == TDR_IMPULSE) + || (item == 2 && tdrfunc == TDR_STEP) + ) { + *bg = 0x0000; + *fg = 0xffff; + } } } From 95ab3995679123a5e4783a3d5cc48aaccd6ebfe8 Mon Sep 17 00:00:00 2001 From: cho45 Date: Tue, 10 Sep 2019 23:49:08 +0900 Subject: [PATCH 2/8] save domain mode --- main.c | 6 ++---- nanovna.h | 12 +++++++++--- plot.c | 2 +- ui.c | 17 +++++++++++------ 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/main.c b/main.c index 23feb52..ea63e40 100644 --- a/main.c +++ b/main.c @@ -56,8 +56,6 @@ int8_t redraw_requested = FALSE; int8_t stop_the_world = FALSE; int16_t vbat = 0; -uint8_t domain = DOMAIN_TIME; -uint8_t tdrfunc = TDR_IMPULSE; static THD_WORKING_AREA(waThread1, 640); static THD_FUNCTION(Thread1, arg) { @@ -116,7 +114,7 @@ static void transform_domain(void) { - if (domain != DOMAIN_TIME) return; // nothing to do for freq domain + if ((domain_mode & DOMAIN_MODE) != DOMAIN_TIME) return; // nothing to do for freq domain // use spi_buffer as temporary buffer // and calculate ifft for time domain float* tmp = (float*)spi_buffer; @@ -132,7 +130,7 @@ transform_domain(void) measured[ch][i][0] /= 128.0; measured[ch][i][1] /= 128.0; } - if (tdrfunc == TDR_STEP) { + if ( (domain_mode & TDR_FUNC_STEP) == TDR_FUNC_STEP ) { for (int i = 1; i < 101; i++) { measured[ch][i][0] += measured[ch][i-1][0]; measured[ch][i][1] += measured[ch][i-1][1]; diff --git a/nanovna.h b/nanovna.h index a33cf5e..e253113 100644 --- a/nanovna.h +++ b/nanovna.h @@ -33,9 +33,6 @@ enum { TDR_IMPULSE, TDR_STEP }; -extern uint8_t domain; -extern uint8_t tdrfunc; - #define CAL_LOAD 0 #define CAL_OPEN 1 #define CAL_SHORT 2 @@ -61,6 +58,13 @@ extern uint8_t tdrfunc; #define ETERM_ET 3 /* error term transmission tracking */ #define ETERM_EX 4 /* error term isolation */ +#define DOMAIN_MODE (1<<0) +#define DOMAIN_FREQ (0<<0) +#define DOMAIN_TIME (1<<0) +#define TDR_FUNC (1<<1) +#define TDR_FUNC_IMPULSE (0<<1) +#define TDR_FUNC_STEP (1<<1) + void cal_collect(int type); void cal_done(void); @@ -294,6 +298,7 @@ typedef struct { trace_t _trace[TRACES_MAX]; marker_t _markers[4]; int _active_marker; + uint8_t _domain_mode; int32_t checksum; } properties_t; @@ -317,6 +322,7 @@ extern int8_t previous_marker; #define trace current_props._trace #define markers current_props._markers #define active_marker current_props._active_marker +#define domain_mode current_props._domain_mode int caldata_save(int id); int caldata_recall(int id); diff --git a/plot.c b/plot.c index 91ef03a..ae44bf0 100644 --- a/plot.c +++ b/plot.c @@ -1367,7 +1367,7 @@ cell_draw_marker_info(int m, int n, int w, int h) chsnprintf(buf, sizeof buf, "%d:", active_marker + 1); cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); xpos += 16; - if (domain == DOMAIN_FREQ) { + if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { frequency_string(buf, sizeof buf, frequencies[idx]); cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); } else { diff --git a/ui.c b/ui.c index 59f2255..149bbd5 100644 --- a/ui.c +++ b/ui.c @@ -669,13 +669,17 @@ menu_tdr_cb(int item) { switch (item) { case 0: - domain = (domain == DOMAIN_FREQ) ? DOMAIN_TIME : DOMAIN_FREQ; + if ((domain_mode & DOMAIN_MODE) == DOMAIN_TIME) { + domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_FREQ; + } else { + domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_TIME; + } break; case 1: - tdrfunc = TDR_IMPULSE; + domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_IMPULSE; break; case 2: - tdrfunc = TDR_STEP; + domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_STEP; break; } @@ -1249,6 +1253,7 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, || (item == 2 && (cal_status & CALSTAT_LOAD)) || (item == 3 && (cal_status & CALSTAT_ISOLN)) || (item == 4 && (cal_status & CALSTAT_THRU))) { + domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_FREQ; *bg = 0x0000; *fg = 0xffff; } @@ -1263,9 +1268,9 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, *fg = 0xffff; } } else if (menu == menu_tdr) { - if ((item == 0 && domain == DOMAIN_TIME) - || (item == 1 && tdrfunc == TDR_IMPULSE) - || (item == 2 && tdrfunc == TDR_STEP) + if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME) + || (item == 1 && (domain_mode & TDR_FUNC) == TDR_FUNC_IMPULSE) + || (item == 2 && (domain_mode & TDR_FUNC) == TDR_FUNC_STEP) ) { *bg = 0x0000; *fg = 0xffff; From 8f0bfacf3d31cd55164af0a1bd72b0f890294d8c Mon Sep 17 00:00:00 2001 From: cho45 Date: Wed, 11 Sep 2019 00:24:06 +0900 Subject: [PATCH 3/8] setting velocity factor --- main.c | 2 ++ nanovna.h | 2 ++ plot.c | 2 +- ui.c | 43 +++++++++++++++++++++++++++++++++---------- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/main.c b/main.c index ea63e40..b6c052b 100644 --- a/main.c +++ b/main.c @@ -547,6 +547,8 @@ properties_t current_props = { { 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 } }, /* active_marker */ 0, + /* domain_mode */ 0, + /* velocity_factor */ 70, /* checksum */ 0 }; properties_t *active_props = ¤t_props; diff --git a/nanovna.h b/nanovna.h index e253113..d9e008f 100644 --- a/nanovna.h +++ b/nanovna.h @@ -299,6 +299,7 @@ typedef struct { marker_t _markers[4]; int _active_marker; uint8_t _domain_mode; + uint8_t _velocity_factor; // % int32_t checksum; } properties_t; @@ -323,6 +324,7 @@ extern int8_t previous_marker; #define markers current_props._markers #define active_marker current_props._active_marker #define domain_mode current_props._domain_mode +#define velocity_factor current_props._velocity_factor int caldata_save(int id); int caldata_recall(int id); diff --git a/plot.c b/plot.c index ae44bf0..5fc7064 100644 --- a/plot.c +++ b/plot.c @@ -1373,7 +1373,7 @@ cell_draw_marker_info(int m, int n, int w, int h) } else { #define SPEED_OF_LIGHT 299792458 float distance = ((float)idx * (float)SPEED_OF_LIGHT) / ( (float)(frequencies[1] - frequencies[0]) * 128.0 * 2.0); - chsnprintf(buf, sizeof buf, "%f m", distance); + chsnprintf(buf, sizeof buf, "%.1f m (%d%%)", distance * (velocity_factor / 100.0), velocity_factor); cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); } diff --git a/ui.c b/ui.c index 149bbd5..d62a54e 100644 --- a/ui.c +++ b/ui.c @@ -68,7 +68,7 @@ enum { }; enum { - KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY + KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY, KM_VELOCITY_FACTOR }; uint8_t ui_mode = UI_NORMAL; @@ -667,23 +667,35 @@ menu_channel_cb(int item) static void menu_tdr_cb(int item) { + int status; switch (item) { case 0: - if ((domain_mode & DOMAIN_MODE) == DOMAIN_TIME) { - domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_FREQ; - } else { - domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_TIME; - } + if ((domain_mode & DOMAIN_MODE) == DOMAIN_TIME) { + domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_FREQ; + } else { + domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_TIME; + } + ui_mode_normal(); break; case 1: domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_IMPULSE; + ui_mode_normal(); break; case 2: domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_STEP; + ui_mode_normal(); + break; + case 3: + status = btn_wait_release(); + if (status & EVT_BUTTON_DOWN_LONG) { + ui_mode_numeric(KM_VELOCITY_FACTOR); + ui_process_numeric(); + } else { + ui_mode_keypad(KM_VELOCITY_FACTOR); + ui_process_keypad(); + } break; } - - ui_mode_normal(); } static void @@ -900,6 +912,7 @@ const menuitem_t menu_tdr[] = { { MT_CALLBACK, "TDR MODE", menu_tdr_cb }, { MT_CALLBACK, "IMPULSE", menu_tdr_cb }, { MT_CALLBACK, "STEP", menu_tdr_cb }, + { MT_CALLBACK, "\2VELOCITY\0FACTOR", menu_tdr_cb }, { MT_CANCEL, S_LARROW" BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; @@ -1150,11 +1163,12 @@ const keypads_t * const keypads_mode_tbl[] = { keypads_freq, // cw freq keypads_scale, // scale keypads_scale, // respos - keypads_time // electrical delay + keypads_time, // electrical delay + keypads_scale // velocity factor }; const char * const keypad_mode_label[] = { - "START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY" + "START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY" }; void @@ -1402,6 +1416,9 @@ fetch_numeric_target(void) case KM_EDELAY: uistat.value = get_electrical_delay(); break; + case KM_VELOCITY_FACTOR: + uistat.value = velocity_factor; + break; } { @@ -1441,6 +1458,9 @@ void set_numeric_value(void) case KM_EDELAY: set_electrical_delay(uistat.value); break; + case KM_VELOCITY_FACTOR: + velocity_factor = uistat.value; + break; } } @@ -1615,6 +1635,9 @@ keypad_click(int key) case KM_EDELAY: set_electrical_delay(value); // pico seconds break; + case KM_VELOCITY_FACTOR: + velocity_factor = value; + break; } return KP_DONE; From b17ecfa533de3957fe19f4c4b2149882c8028ef7 Mon Sep 17 00:00:00 2001 From: cho45 Date: Wed, 11 Sep 2019 08:17:40 +0900 Subject: [PATCH 4/8] minor fixes --- main.c | 12 ++++++------ plot.c | 10 +++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index b6c052b..0cd5832 100644 --- a/main.c +++ b/main.c @@ -37,7 +37,6 @@ static void apply_error_term(void); static void apply_error_term_at(int i); static void cal_interpolate(int s); -static void transform_domain(void); void sweep(void); @@ -84,7 +83,6 @@ static THD_FUNCTION(Thread1, arg) draw_battery_status(); } - transform_domain(); /* calculate trace coordinates */ plot_into_index(measured); /* plot trace as raster */ @@ -119,13 +117,13 @@ transform_domain(void) // and calculate ifft for time domain float* tmp = (float*)spi_buffer; for (int ch = 0; ch < 2; ch++) { - for (int i = 0; i < 128; i++) { + memcpy(tmp, measured[ch], sizeof(measured[0])); + for (int i = 101+1; i < 128; i++) { tmp[i*2+0] = 0.0; tmp[i*2+1] = 0.0; } - memcpy(spi_buffer, measured[ch], sizeof(measured[0])); fft((float(*)[2])tmp, 128, 1); - memcpy(measured[ch], spi_buffer, sizeof(measured[0])); + memcpy(measured[ch], tmp, sizeof(measured[0])); for (int i = 0; i < 101; i++) { measured[ch][i][0] /= 128.0; measured[ch][i][1] /= 128.0; @@ -633,11 +631,13 @@ void sweep(void) redraw_requested = FALSE; ui_process(); if (redraw_requested) - return; // return to redraw screen asap. + break; // return to redraw screen asap. if (frequency_updated) goto rewind; } + + transform_domain(); } static void diff --git a/plot.c b/plot.c index 5fc7064..e3f569f 100644 --- a/plot.c +++ b/plot.c @@ -701,6 +701,12 @@ trace_get_info(int t, char *buf, int len) } } +static float distance_of_index(int idx) { +#define SPEED_OF_LIGHT 299792458 + float distance = ((float)idx * (float)SPEED_OF_LIGHT) / ( (float)(frequencies[1] - frequencies[0]) * 128.0 * 2.0); + return distance * (velocity_factor / 100.0); +} + static inline void mark_map(int x, int y) { @@ -1371,9 +1377,7 @@ cell_draw_marker_info(int m, int n, int w, int h) frequency_string(buf, sizeof buf, frequencies[idx]); cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); } else { -#define SPEED_OF_LIGHT 299792458 - float distance = ((float)idx * (float)SPEED_OF_LIGHT) / ( (float)(frequencies[1] - frequencies[0]) * 128.0 * 2.0); - chsnprintf(buf, sizeof buf, "%.1f m (%d%%)", distance * (velocity_factor / 100.0), velocity_factor); + chsnprintf(buf, sizeof buf, "%.1f m (VF=%d%%)", distance_of_index(idx), velocity_factor); cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); } From 6bad9de6068828e97b5ca3b73f6f69a35a369f44 Mon Sep 17 00:00:00 2001 From: cho45 Date: Wed, 11 Sep 2019 20:47:17 +0900 Subject: [PATCH 5/8] change menu name to 'TRANSFORM' --- fft.h | 45 +++++++++++++++++++++++++++++------- main.c | 4 ++-- nanovna.h | 13 +++++++---- ui.c | 69 ++++++++++++++++++++++++++++++++++++++++++++----------- 4 files changed, 104 insertions(+), 27 deletions(-) diff --git a/fft.h b/fft.h index bf5cb11..1a46515 100644 --- a/fft.h +++ b/fft.h @@ -33,16 +33,38 @@ static uint8_t reverse_bits(uint8_t x, int n) { return result; } +static const float sin_table[] = { + /* + * float has about 7.2 digits of precision + for (uint8_t i = 0; i < 96; i++) { + printf("% .8f,%c", sin(2 * M_PI * i / n), i % 8 == 7 ? '\n' : ' '); + } + */ + 0.00000000, 0.04906767, 0.09801714, 0.14673047, 0.19509032, 0.24298018, 0.29028468, 0.33688985, + 0.38268343, 0.42755509, 0.47139674, 0.51410274, 0.55557023, 0.59569930, 0.63439328, 0.67155895, + 0.70710678, 0.74095113, 0.77301045, 0.80320753, 0.83146961, 0.85772861, 0.88192126, 0.90398929, + 0.92387953, 0.94154407, 0.95694034, 0.97003125, 0.98078528, 0.98917651, 0.99518473, 0.99879546, + 1.00000000, 0.99879546, 0.99518473, 0.98917651, 0.98078528, 0.97003125, 0.95694034, 0.94154407, + 0.92387953, 0.90398929, 0.88192126, 0.85772861, 0.83146961, 0.80320753, 0.77301045, 0.74095113, + 0.70710678, 0.67155895, 0.63439328, 0.59569930, 0.55557023, 0.51410274, 0.47139674, 0.42755509, + 0.38268343, 0.33688985, 0.29028468, 0.24298018, 0.19509032, 0.14673047, 0.09801714, 0.04906767, + 0.00000000, -0.04906767, -0.09801714, -0.14673047, -0.19509032, -0.24298018, -0.29028468, -0.33688985, + -0.38268343, -0.42755509, -0.47139674, -0.51410274, -0.55557023, -0.59569930, -0.63439328, -0.67155895, + -0.70710678, -0.74095113, -0.77301045, -0.80320753, -0.83146961, -0.85772861, -0.88192126, -0.90398929, + -0.92387953, -0.94154407, -0.95694034, -0.97003125, -0.98078528, -0.98917651, -0.99518473, -0.99879546, +}; + /*** * dir = forward: 0, inverse: 1 + * https://www.nayuki.io/res/free-small-fft-in-multiple-languages/fft.c */ -void fft(float array[][2], uint8_t n, uint8_t dir) { - int levels = 0; // Compute levels = floor(log2(n)) - for (uint8_t temp = n; temp > 1U; temp >>= 1) - levels++; +static void fft128(float array[][2], const uint8_t dir) { + const uint8_t n = 128; + const uint8_t levels = 7; // log2(n) + const float* const cos_table = &sin_table[32]; - uint8_t real = dir & 1; - uint8_t imag = ~real & 1; + const uint8_t real = dir & 1; + const uint8_t imag = ~real & 1; for (uint8_t i = 0; i < n; i++) { uint8_t j = reverse_bits(i, levels); @@ -63,8 +85,8 @@ void fft(float array[][2], uint8_t n, uint8_t dir) { for (uint8_t i = 0; i < n; i += size) { for (uint8_t j = i, k = 0; j < i + halfsize; j++, k += tablestep) { uint8_t l = j + halfsize; - float tpre = array[l][real] * cos(2 * M_PI * k / n) + array[l][imag] * sin(2 * M_PI * k / n); - float tpim = -array[l][real] * sin(2 * M_PI * k / n) + array[l][imag] * cos(2 * M_PI * k / n); + float tpre = array[l][real] * cos_table[k] + array[l][imag] * sin_table[k]; + float tpim = -array[l][real] * sin_table[k] + array[l][imag] * cos_table[k] ; array[l][real] = array[j][real] - tpre; array[l][imag] = array[j][imag] - tpim; array[j][real] += tpre; @@ -76,3 +98,10 @@ void fft(float array[][2], uint8_t n, uint8_t dir) { } } +static inline void fft128_forward(float array[][2]) { + fft128(array, 0); +} + +static inline void fft128_inverse(float array[][2]) { + fft128(array, 1); +} diff --git a/main.c b/main.c index 0cd5832..5d0a327 100644 --- a/main.c +++ b/main.c @@ -122,13 +122,13 @@ transform_domain(void) tmp[i*2+0] = 0.0; tmp[i*2+1] = 0.0; } - fft((float(*)[2])tmp, 128, 1); + fft128_inverse((float(*)[2])tmp); memcpy(measured[ch], tmp, sizeof(measured[0])); for (int i = 0; i < 101; i++) { measured[ch][i][0] /= 128.0; measured[ch][i][1] /= 128.0; } - if ( (domain_mode & TDR_FUNC_STEP) == TDR_FUNC_STEP ) { + if ( (domain_mode & TDR_FUNC) == TDR_FUNC_LOWPASS_STEP ) { for (int i = 1; i < 101; i++) { measured[ch][i][0] += measured[ch][i-1][0]; measured[ch][i][1] += measured[ch][i-1][1]; diff --git a/nanovna.h b/nanovna.h index d9e008f..7465d44 100644 --- a/nanovna.h +++ b/nanovna.h @@ -61,9 +61,14 @@ enum { #define DOMAIN_MODE (1<<0) #define DOMAIN_FREQ (0<<0) #define DOMAIN_TIME (1<<0) -#define TDR_FUNC (1<<1) -#define TDR_FUNC_IMPULSE (0<<1) -#define TDR_FUNC_STEP (1<<1) +#define TDR_FUNC (0b11<<1) +#define TDR_FUNC_BANDPASS (0b00<<1) +#define TDR_FUNC_LOWPASS_IMPULSE (0b01<<1) +#define TDR_FUNC_LOWPASS_STEP (0b10<<1) +#define TDR_WINDOW (0b11<<3) +#define TDR_WINDOW_NORMAL (0b00<<3) +#define TDR_WINDOW_MINIMUM (0b01<<3) +#define TDR_WINDOW_MAXIMUM (0b10<<3) void cal_collect(int type); void cal_done(void); @@ -298,7 +303,7 @@ typedef struct { trace_t _trace[TRACES_MAX]; marker_t _markers[4]; int _active_marker; - uint8_t _domain_mode; + uint8_t _domain_mode; /* 0bxxxxxffm : where ff: TDR_FUNC m: DOMAIN_MODE */ uint8_t _velocity_factor; // % int32_t checksum; diff --git a/ui.c b/ui.c index d62a54e..3541156 100644 --- a/ui.c +++ b/ui.c @@ -665,7 +665,27 @@ menu_channel_cb(int item) } static void -menu_tdr_cb(int item) +menu_transform_window_cb(int item) +{ + // TODO + switch (item) { + case 0: + domain_mode = (domain_mode & ~TDR_WINDOW) | TDR_WINDOW_MINIMUM; + ui_mode_normal(); + break; + case 1: + domain_mode = (domain_mode & ~TDR_WINDOW) | TDR_WINDOW_NORMAL; + ui_mode_normal(); + break; + case 2: + domain_mode = (domain_mode & ~TDR_WINDOW) | TDR_WINDOW_MAXIMUM; + ui_mode_normal(); + break; + } +} + +static void +menu_transform_cb(int item) { int status; switch (item) { @@ -678,14 +698,18 @@ menu_tdr_cb(int item) ui_mode_normal(); break; case 1: - domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_IMPULSE; + domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_LOWPASS_IMPULSE; ui_mode_normal(); break; case 2: - domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_STEP; + domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_LOWPASS_STEP; ui_mode_normal(); break; case 3: + domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_BANDPASS; + ui_mode_normal(); + break; + case 5: status = btn_wait_release(); if (status & EVT_BUTTON_DOWN_LONG) { ui_mode_numeric(KM_VELOCITY_FACTOR); @@ -908,11 +932,21 @@ const menuitem_t menu_channel[] = { { MT_NONE, NULL, NULL } // sentinel }; -const menuitem_t menu_tdr[] = { - { MT_CALLBACK, "TDR MODE", menu_tdr_cb }, - { MT_CALLBACK, "IMPULSE", menu_tdr_cb }, - { MT_CALLBACK, "STEP", menu_tdr_cb }, - { MT_CALLBACK, "\2VELOCITY\0FACTOR", menu_tdr_cb }, +const menuitem_t menu_transform_window[] = { + { MT_CALLBACK, "MINIMUM", menu_transform_window_cb }, + { MT_CALLBACK, "NORMAL", menu_transform_window_cb }, + { MT_CALLBACK, "MAXIMUM", menu_transform_window_cb }, + { MT_CANCEL, S_LARROW" BACK", NULL }, + { MT_NONE, NULL, NULL } // sentinel +}; + +const menuitem_t menu_transform[] = { + { MT_CALLBACK, "\2TRANSFORM\0ON", menu_transform_cb }, + { MT_CALLBACK, "\2LOW PASS\0IMPULSE", menu_transform_cb }, + { MT_CALLBACK, "\2LOW PASS\0STEP", menu_transform_cb }, + { MT_CALLBACK, "BANDPASS", menu_transform_cb }, + { MT_SUBMENU, "WINDOW", menu_transform_window }, + { MT_CALLBACK, "\2VELOCITY\0FACTOR", menu_transform_cb }, { MT_CANCEL, S_LARROW" BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; @@ -922,7 +956,7 @@ const menuitem_t menu_display[] = { { MT_SUBMENU, "FORMAT", menu_format }, { MT_SUBMENU, "SCALE", menu_scale }, { MT_SUBMENU, "CHANNEL", menu_channel }, - { MT_SUBMENU, "TDR", menu_tdr }, + { MT_SUBMENU, "TRANSFORM", menu_transform }, { MT_CANCEL, S_LARROW" BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; @@ -1168,7 +1202,7 @@ const keypads_t * const keypads_mode_tbl[] = { }; const char * const keypad_mode_label[] = { - "START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY" + "START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY%" }; void @@ -1281,10 +1315,19 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, *bg = 0x0000; *fg = 0xffff; } - } else if (menu == menu_tdr) { + } else if (menu == menu_transform) { if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME) - || (item == 1 && (domain_mode & TDR_FUNC) == TDR_FUNC_IMPULSE) - || (item == 2 && (domain_mode & TDR_FUNC) == TDR_FUNC_STEP) + || (item == 1 && (domain_mode & TDR_FUNC) == TDR_FUNC_LOWPASS_IMPULSE) + || (item == 2 && (domain_mode & TDR_FUNC) == TDR_FUNC_LOWPASS_STEP) + || (item == 3 && (domain_mode & TDR_FUNC) == TDR_FUNC_BANDPASS) + ) { + *bg = 0x0000; + *fg = 0xffff; + } + } else if (menu == menu_transform_window) { + if ((item == 0 && (domain_mode & TDR_WINDOW) == TDR_WINDOW_MINIMUM) + || (item == 1 && (domain_mode & TDR_WINDOW) == TDR_WINDOW_NORMAL) + || (item == 2 && (domain_mode & TDR_WINDOW) == TDR_WINDOW_MAXIMUM) ) { *bg = 0x0000; *fg = 0xffff; From a3b511f468a23f6e20072c0643f0284bb7d02954 Mon Sep 17 00:00:00 2001 From: cho45 Date: Wed, 11 Sep 2019 21:22:42 +0900 Subject: [PATCH 6/8] show time domain range --- plot.c | 77 +++++++++++++++++++++++++++++++++++----------------------- ui.c | 1 + 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/plot.c b/plot.c index e3f569f..83ed0fb 100644 --- a/plot.c +++ b/plot.c @@ -701,12 +701,17 @@ trace_get_info(int t, char *buf, int len) } } +static float time_of_index(int idx) { + return 1.0 / (float)(frequencies[1] - frequencies[0]) / 128.0 * idx; +} + static float distance_of_index(int idx) { #define SPEED_OF_LIGHT 299792458 float distance = ((float)idx * (float)SPEED_OF_LIGHT) / ( (float)(frequencies[1] - frequencies[0]) * 128.0 * 2.0); return distance * (velocity_factor / 100.0); } + static inline void mark_map(int x, int y) { @@ -1377,7 +1382,7 @@ cell_draw_marker_info(int m, int n, int w, int h) frequency_string(buf, sizeof buf, frequencies[idx]); cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); } else { - chsnprintf(buf, sizeof buf, "%.1f m (VF=%d%%)", distance_of_index(idx), velocity_factor); + chsnprintf(buf, sizeof buf, "%d ns %.1f m", (uint16_t)(time_of_index(idx) * 1e9), distance_of_index(idx)); cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); } @@ -1421,37 +1426,47 @@ void draw_frequencies(void) { char buf[24]; - if (frequency1 > 0) { - int start = frequency0; - int stop = frequency1; - strcpy(buf, "START "); - frequency_string(buf+6, 24-6, start); - strcat(buf, " "); - ili9341_drawstring_5x7(buf, OFFSETX, 233, 0xffff, 0x0000); - strcpy(buf, "STOP "); - frequency_string(buf+5, 24-5, stop); - strcat(buf, " "); - ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); - } else if (frequency1 < 0) { - int fcenter = frequency0; - int fspan = -frequency1; - strcpy(buf, "CENTER "); - frequency_string(buf+7, 24-7, fcenter); - strcat(buf, " "); - ili9341_drawstring_5x7(buf, OFFSETX, 233, 0xffff, 0x0000); - strcpy(buf, "SPAN "); - frequency_string(buf+5, 24-5, fspan); - strcat(buf, " "); - ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); + if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { + if (frequency1 > 0) { + int start = frequency0; + int stop = frequency1; + strcpy(buf, "START "); + frequency_string(buf+6, 24-6, start); + strcat(buf, " "); + ili9341_drawstring_5x7(buf, OFFSETX, 233, 0xffff, 0x0000); + strcpy(buf, "STOP "); + frequency_string(buf+5, 24-5, stop); + strcat(buf, " "); + ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); + } else if (frequency1 < 0) { + int fcenter = frequency0; + int fspan = -frequency1; + strcpy(buf, "CENTER "); + frequency_string(buf+7, 24-7, fcenter); + strcat(buf, " "); + ili9341_drawstring_5x7(buf, OFFSETX, 233, 0xffff, 0x0000); + strcpy(buf, "SPAN "); + frequency_string(buf+5, 24-5, fspan); + strcat(buf, " "); + ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); + } else { + int fcenter = frequency0; + chsnprintf(buf, 24, "CW %d.%03d %03d MHz ", + (int)(fcenter / 1000000), + (int)((fcenter / 1000) % 1000), + (int)(fcenter % 1000)); + ili9341_drawstring_5x7(buf, OFFSETX, 233, 0xffff, 0x0000); + chsnprintf(buf, 24, " "); + ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); + } } else { - int fcenter = frequency0; - chsnprintf(buf, 24, "CW %d.%03d %03d MHz ", - (int)(fcenter / 1000000), - (int)((fcenter / 1000) % 1000), - (int)(fcenter % 1000)); - ili9341_drawstring_5x7(buf, OFFSETX, 233, 0xffff, 0x0000); - chsnprintf(buf, 24, " "); - ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); + strcpy(buf, "START 0s "); + ili9341_drawstring_5x7(buf, OFFSETX, 233, 0xffff, 0x0000); + + strcpy(buf, "STOP "); + chsnprintf(buf+5, 24-5, "%d ns", (uint16_t)(time_of_index(101) * 1e9)); + strcat(buf, " "); + ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); } } diff --git a/ui.c b/ui.c index 3541156..7023c6f 100644 --- a/ui.c +++ b/ui.c @@ -695,6 +695,7 @@ menu_transform_cb(int item) } else { domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_TIME; } + draw_frequencies(); ui_mode_normal(); break; case 1: From 472b895d5b23ab8440c351326471355bbf8927ae Mon Sep 17 00:00:00 2001 From: cho45 Date: Wed, 11 Sep 2019 22:35:44 +0900 Subject: [PATCH 7/8] windowing --- main.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 5d0a327..8f88c27 100644 --- a/main.c +++ b/main.c @@ -108,6 +108,28 @@ toggle_sweep(void) sweep_enabled = !sweep_enabled; } +float bessel0(float x) { + const float eps = 0.0001; + + float ret = 0; + float term = 1; + float m = 0; + + while (term > eps * ret) { + ret += term; + ++m; + term *= (x*x) / (4*m*m); + } + + return ret; +} + +float kaiser_window(float k, float n, float beta) { + if (beta == 0.0) return 1.0; + float r = (2 * k) / (n - 1) - 1; + return bessel0(beta * sqrt(1 - r * r)) / bessel0(beta); +} + static void transform_domain(void) @@ -116,9 +138,43 @@ transform_domain(void) // use spi_buffer as temporary buffer // and calculate ifft for time domain float* tmp = (float*)spi_buffer; + + uint8_t window_size, offset; + switch (domain_mode & TDR_FUNC) { + case TDR_FUNC_BANDPASS: + offset = 0; + window_size = 101; + break; + case TDR_FUNC_LOWPASS_IMPULSE: + case TDR_FUNC_LOWPASS_STEP: + offset = 101; + window_size = 202; + break; + } + + float beta = 0.0; + switch (domain_mode & TDR_WINDOW) { + case TDR_WINDOW_MINIMUM: + beta = 0.0; // this is rectangular + break; + case TDR_WINDOW_NORMAL: + beta = 6.0; + break; + case TDR_WINDOW_MAXIMUM: + beta = 13; + break; + } + for (int ch = 0; ch < 2; ch++) { memcpy(tmp, measured[ch], sizeof(measured[0])); - for (int i = 101+1; i < 128; i++) { + if (beta != 0.0) { + for (int i = 0; i < 101; i++) { + float w = kaiser_window(i+offset, window_size, beta); + tmp[i*2+0] *= w; + tmp[i*2+1] *= w; + } + } + for (int i = 101; i < 128; i++) { tmp[i*2+0] = 0.0; tmp[i*2+1] = 0.0; } From aa4faa5a6e7419f95251ff481dfe0b2d5a5c89cc Mon Sep 17 00:00:00 2001 From: cho45 Date: Wed, 11 Sep 2019 23:05:01 +0900 Subject: [PATCH 8/8] rename TDR -> TD --- main.c | 18 +++++++++--------- nanovna.h | 26 +++++++++----------------- ui.c | 24 ++++++++++++------------ 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/main.c b/main.c index 8f88c27..40a9b1b 100644 --- a/main.c +++ b/main.c @@ -140,27 +140,27 @@ transform_domain(void) float* tmp = (float*)spi_buffer; uint8_t window_size, offset; - switch (domain_mode & TDR_FUNC) { - case TDR_FUNC_BANDPASS: + switch (domain_mode & TD_FUNC) { + case TD_FUNC_BANDPASS: offset = 0; window_size = 101; break; - case TDR_FUNC_LOWPASS_IMPULSE: - case TDR_FUNC_LOWPASS_STEP: + case TD_FUNC_LOWPASS_IMPULSE: + case TD_FUNC_LOWPASS_STEP: offset = 101; window_size = 202; break; } float beta = 0.0; - switch (domain_mode & TDR_WINDOW) { - case TDR_WINDOW_MINIMUM: + switch (domain_mode & TD_WINDOW) { + case TD_WINDOW_MINIMUM: beta = 0.0; // this is rectangular break; - case TDR_WINDOW_NORMAL: + case TD_WINDOW_NORMAL: beta = 6.0; break; - case TDR_WINDOW_MAXIMUM: + case TD_WINDOW_MAXIMUM: beta = 13; break; } @@ -184,7 +184,7 @@ transform_domain(void) measured[ch][i][0] /= 128.0; measured[ch][i][1] /= 128.0; } - if ( (domain_mode & TDR_FUNC) == TDR_FUNC_LOWPASS_STEP ) { + if ( (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP ) { for (int i = 1; i < 101; i++) { measured[ch][i][0] += measured[ch][i-1][0]; measured[ch][i][1] += measured[ch][i-1][1]; diff --git a/nanovna.h b/nanovna.h index 7465d44..e60924d 100644 --- a/nanovna.h +++ b/nanovna.h @@ -25,14 +25,6 @@ extern float measured[2][101][2]; -enum { - DOMAIN_FREQ, DOMAIN_TIME -}; - -enum { - TDR_IMPULSE, TDR_STEP -}; - #define CAL_LOAD 0 #define CAL_OPEN 1 #define CAL_SHORT 2 @@ -61,14 +53,14 @@ enum { #define DOMAIN_MODE (1<<0) #define DOMAIN_FREQ (0<<0) #define DOMAIN_TIME (1<<0) -#define TDR_FUNC (0b11<<1) -#define TDR_FUNC_BANDPASS (0b00<<1) -#define TDR_FUNC_LOWPASS_IMPULSE (0b01<<1) -#define TDR_FUNC_LOWPASS_STEP (0b10<<1) -#define TDR_WINDOW (0b11<<3) -#define TDR_WINDOW_NORMAL (0b00<<3) -#define TDR_WINDOW_MINIMUM (0b01<<3) -#define TDR_WINDOW_MAXIMUM (0b10<<3) +#define TD_FUNC (0b11<<1) +#define TD_FUNC_BANDPASS (0b00<<1) +#define TD_FUNC_LOWPASS_IMPULSE (0b01<<1) +#define TD_FUNC_LOWPASS_STEP (0b10<<1) +#define TD_WINDOW (0b11<<3) +#define TD_WINDOW_NORMAL (0b00<<3) +#define TD_WINDOW_MINIMUM (0b01<<3) +#define TD_WINDOW_MAXIMUM (0b10<<3) void cal_collect(int type); void cal_done(void); @@ -303,7 +295,7 @@ typedef struct { trace_t _trace[TRACES_MAX]; marker_t _markers[4]; int _active_marker; - uint8_t _domain_mode; /* 0bxxxxxffm : where ff: TDR_FUNC m: DOMAIN_MODE */ + uint8_t _domain_mode; /* 0bxxxxxffm : where ff: TD_FUNC m: DOMAIN_MODE */ uint8_t _velocity_factor; // % int32_t checksum; diff --git a/ui.c b/ui.c index 7023c6f..686e032 100644 --- a/ui.c +++ b/ui.c @@ -670,15 +670,15 @@ menu_transform_window_cb(int item) // TODO switch (item) { case 0: - domain_mode = (domain_mode & ~TDR_WINDOW) | TDR_WINDOW_MINIMUM; + domain_mode = (domain_mode & ~TD_WINDOW) | TD_WINDOW_MINIMUM; ui_mode_normal(); break; case 1: - domain_mode = (domain_mode & ~TDR_WINDOW) | TDR_WINDOW_NORMAL; + domain_mode = (domain_mode & ~TD_WINDOW) | TD_WINDOW_NORMAL; ui_mode_normal(); break; case 2: - domain_mode = (domain_mode & ~TDR_WINDOW) | TDR_WINDOW_MAXIMUM; + domain_mode = (domain_mode & ~TD_WINDOW) | TD_WINDOW_MAXIMUM; ui_mode_normal(); break; } @@ -699,15 +699,15 @@ menu_transform_cb(int item) ui_mode_normal(); break; case 1: - domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_LOWPASS_IMPULSE; + domain_mode = (domain_mode & ~TD_FUNC) | TD_FUNC_LOWPASS_IMPULSE; ui_mode_normal(); break; case 2: - domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_LOWPASS_STEP; + domain_mode = (domain_mode & ~TD_FUNC) | TD_FUNC_LOWPASS_STEP; ui_mode_normal(); break; case 3: - domain_mode = (domain_mode & ~TDR_FUNC) | TDR_FUNC_BANDPASS; + domain_mode = (domain_mode & ~TD_FUNC) | TD_FUNC_BANDPASS; ui_mode_normal(); break; case 5: @@ -1318,17 +1318,17 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, } } else if (menu == menu_transform) { if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME) - || (item == 1 && (domain_mode & TDR_FUNC) == TDR_FUNC_LOWPASS_IMPULSE) - || (item == 2 && (domain_mode & TDR_FUNC) == TDR_FUNC_LOWPASS_STEP) - || (item == 3 && (domain_mode & TDR_FUNC) == TDR_FUNC_BANDPASS) + || (item == 1 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_IMPULSE) + || (item == 2 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP) + || (item == 3 && (domain_mode & TD_FUNC) == TD_FUNC_BANDPASS) ) { *bg = 0x0000; *fg = 0xffff; } } else if (menu == menu_transform_window) { - if ((item == 0 && (domain_mode & TDR_WINDOW) == TDR_WINDOW_MINIMUM) - || (item == 1 && (domain_mode & TDR_WINDOW) == TDR_WINDOW_NORMAL) - || (item == 2 && (domain_mode & TDR_WINDOW) == TDR_WINDOW_MAXIMUM) + if ((item == 0 && (domain_mode & TD_WINDOW) == TD_WINDOW_MINIMUM) + || (item == 1 && (domain_mode & TD_WINDOW) == TD_WINDOW_NORMAL) + || (item == 2 && (domain_mode & TD_WINDOW) == TD_WINDOW_MAXIMUM) ) { *bg = 0x0000; *fg = 0xffff;