SDR: Display spectrum graph together with channel numbers and position

This commit is contained in:
Andreas Eversberg 2017-09-02 15:41:11 +02:00
parent 496aff5a79
commit 9205767f94
4 changed files with 40 additions and 5 deletions

View File

@ -49,7 +49,7 @@ void display_iq_on(int on);
void display_iq_limit_scroll(int on);
void display_iq(float *samples, int length);
void display_spectrum_init(int samplerate);
void display_spectrum_init(int samplerate, double center_frequency);
void display_spectrum_on(int on);
void display_spectrum_limit_scroll(int on);
void display_spectrum(float *samples, int length);

View File

@ -33,10 +33,11 @@ static char screen[HEIGHT][MAX_DISPLAY_WIDTH];
static uint8_t screen_color[HEIGHT][MAX_DISPLAY_WIDTH];
static int spectrum_on = 0;
static double db = 100;
static double center_frequency, frequency_range;
static dispspectrum_t disp;
void display_spectrum_init(int samplerate)
void display_spectrum_init(int samplerate, double _center_frequency)
{
memset(&disp, 0, sizeof(disp));
disp.interval_max = (double)samplerate * DISPLAY_INTERVAL + 0.5;
@ -44,6 +45,9 @@ void display_spectrum_init(int samplerate)
if (disp.interval_max < MAX_DISPLAY_SPECTRUM - 1)
disp.interval_max = MAX_DISPLAY_SPECTRUM - 1;
memset(buffer_max, 0, sizeof(buffer_max));
center_frequency = _center_frequency;
frequency_range = (double)samplerate;
}
void display_spectrum_on(int on)
@ -90,6 +94,8 @@ void display_spectrum_limit_scroll(int on)
*/
void display_spectrum(float *samples, int length)
{
sender_t *sender;
char print_channel[32], print_frequency[32];
int width, h;
int pos, max;
double *buffer_I, *buffer_Q;
@ -213,6 +219,34 @@ void display_spectrum(float *samples, int length)
}
}
}
for (sender = sender_head; sender; sender = sender->next) {
j = (int)((sender->empfangsfrequenz - center_frequency) / frequency_range * (double) fft_size + width / 2 + 0.5);
if (j < 0 || j >= width) /* check out-of-range, should not happen */
continue;
for (k = 0; k < HEIGHT; k++) {
/* skip yellow graph */
if (screen_color[k][j] == 13)
continue;
screen[k][j] = ':';
screen_color[k][j] = 12;
}
sprintf(print_channel, "Ch%d", sender->kanal);
for (o = 0; o < (int)strlen(print_channel); o++) {
s = j - strlen(print_channel) + o;
if (s >= 0 && s < width) {
screen[HEIGHT - 1][s] = print_channel[o];
screen_color[HEIGHT - 1][s] = 7;
}
}
sprintf(print_frequency, "%.4f", sender->empfangsfrequenz / 1e6);
for (o = 0; o < (int)strlen(print_frequency); o++) {
s = j + o + 1;
if (s >= 0 && s < width) {
screen[HEIGHT - 1][s] = print_frequency[o];
screen_color[HEIGHT - 1][s] = 7;
}
}
}
printf("\0337\033[H");
for (j = 0; j < HEIGHT; j++) {
for (k = 0; k < width; k++) {

View File

@ -114,9 +114,6 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq
threads = 1;
}
display_iq_init(samplerate);
display_spectrum_init(samplerate);
bandwidth = 2.0 * (max_deviation + max_modulation);
PDEBUG(DSDR, DEBUG_INFO, "Require bandwidth of 2 * (%.1f + %.1f) = %.1f\n", max_deviation / 1000, max_modulation / 1000, bandwidth / 1000);
@ -340,6 +337,9 @@ void *sdr_open(const char __attribute__((__unused__)) *audiodev, double *tx_freq
tx_center_frequency = temp;
}
display_iq_init(samplerate);
display_spectrum_init(samplerate, rx_center_frequency);
#ifdef HAVE_UHD
if (sdr_config->uhd) {
rc = uhd_open(sdr_config->channel, sdr_config->device_args, sdr_config->stream_args, sdr_config->tune_args, sdr_config->tx_antenna, sdr_config->rx_antenna, tx_center_frequency, rx_center_frequency, sdr_config->samplerate, sdr_config->tx_gain, sdr_config->rx_gain, sdr_config->bandwidth, sdr_config->uhd_tx_timestamps);

View File

@ -41,6 +41,7 @@ enum paging_signal;
#include "tv_modulate.h"
#include "channels.h"
void *sender_head = NULL;
int use_sdr = 0;
int num_kanal = 1; /* only one channel used for debugging */