diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2017-09-16 10:05:26 +0200 |
---|---|---|
committer | Andreas Eversberg <jolly@eversberg.eu> | 2017-09-16 10:48:48 +0200 |
commit | 274cb7992b4b1498d1b55db322844ada0eab8cad (patch) | |
tree | 1dfe47e92cc5e06fa3a146708d39c56da7d7e118 /src/common | |
parent | 0b7b8f12c630203bd97710f33cba6f376c383aea (diff) |
SDR: Improvement of spectrum view, peaks are drawn correctly
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/display_spectrum.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/src/common/display_spectrum.c b/src/common/display_spectrum.c index ee7823c..8d48ad3 100644 --- a/src/common/display_spectrum.c +++ b/src/common/display_spectrum.c @@ -102,7 +102,7 @@ void display_spectrum(float *samples, int length) int color = 9; /* default color */ int i, j, k, o; double I, Q, v; - int s, e; + int s, e, l, n; if (!spectrum_on) return; @@ -178,11 +178,31 @@ void display_spectrum(float *samples, int length) *strchr(screen[0], '\0') = ')'; o = (width - fft_size) / 2; /* offset from left border */ for (j = 0; j < fft_size; j++) { - s = e = low[j]; - if (j > 0 && low[j - 1] > e) - e = low[j - 1] - 1; - if (j < fft_size - 1 && low[j + 1] > e) - e = low[j + 1] - 1; + s = l = n = low[j]; + /* get last and next value */ + if (j > 0) + l = (low[j - 1] + s) / 2; + if (j < fft_size - 1) + n = (low[j + 1] + s) / 2; + if (s > l && s > n) { + /* current value is a minimum */ + e = s; + s = (l < n) ? (l + 1) : (n + 1); + } else if (s < l && s < n) { + /* current value is a maximum */ + e = (l > n) ? l : n; + } else if (l < n) { + /* last value is higher, next value is lower */ + s = l + 1; + e = n; + } else if (l > n) { + /* last value is lower, next value is higher */ + s = n + 1; + e = l; + } else { + /* current, last and next values are equal */ + e = s; + } if (s == e) { if ((s & 1) == 0) screen[s >> 1][j + o] = '\''; @@ -205,8 +225,8 @@ void display_spectrum(float *samples, int length) screen_color[k][j + o] = 13; } } + e = s; s = heigh[j]; - e = low[j]; if ((s >> 1) < (e >> 1)) { if ((s & 1) == 0) screen[s >> 1][j + o] = '|'; @@ -238,7 +258,10 @@ void display_spectrum(float *samples, int length) screen_color[HEIGHT - 1][s] = 7; } } - sprintf(print_frequency, "%.4f", sender->empfangsfrequenz / 1e6); + if (fmod(sender->empfangsfrequenz, 1000.0)) + sprintf(print_frequency, "%.4f", sender->empfangsfrequenz / 1e6); + else + sprintf(print_frequency, "%.3f", sender->empfangsfrequenz / 1e6); for (o = 0; o < (int)strlen(print_frequency); o++) { s = j + o + 1; if (s >= 0 && s < width) { |