Speed up the I/Q to magnitude calculation
Increase the speed of the I/Q to magnitude calculation lookup by expanding the table to 65536 entries (256*256*2 bytes). At runtime, this allows us to pick up raw I/Q bytes as a 16 bit value and index into the magnitude table to get a 16 bit result. This removes the need for subtracting 127, and then correcting for -ve numbers, so should be faster, at the expense of a larger data table. Change the maglut lookup table from 129*129 to 256*256 Initialise the maglut buffer accordingly Change the data->maglut lookup to use the new maglut buffer Change the I/Q data buffer pointet to a uint16_t *
This commit is contained in:
parent
3113223029
commit
ed80552ca1
23
dump1090.c
23
dump1090.c
|
@ -133,7 +133,7 @@ struct {
|
||||||
pthread_t reader_thread;
|
pthread_t reader_thread;
|
||||||
pthread_mutex_t data_mutex; /* Mutex to synchronize buffer access. */
|
pthread_mutex_t data_mutex; /* Mutex to synchronize buffer access. */
|
||||||
pthread_cond_t data_cond; /* Conditional variable associated. */
|
pthread_cond_t data_cond; /* Conditional variable associated. */
|
||||||
unsigned char *data; /* Raw IQ samples buffer */
|
uint16_t *data; /* Raw IQ samples buffer */
|
||||||
uint16_t *magnitude; /* Magnitude vector */
|
uint16_t *magnitude; /* Magnitude vector */
|
||||||
long long timestampBlk; /* Timestamp of the start of the current block */
|
long long timestampBlk; /* Timestamp of the start of the current block */
|
||||||
int fd; /* --ifile option file descriptor. */
|
int fd; /* --ifile option file descriptor. */
|
||||||
|
@ -328,10 +328,12 @@ void modesInit(void) {
|
||||||
* We scale to 0-255 range multiplying by 1.4 in order to ensure that
|
* We scale to 0-255 range multiplying by 1.4 in order to ensure that
|
||||||
* every different I/Q pair will result in a different magnitude value,
|
* every different I/Q pair will result in a different magnitude value,
|
||||||
* not losing any resolution. */
|
* not losing any resolution. */
|
||||||
Modes.maglut = malloc(129*129*2);
|
Modes.maglut = malloc(256*256*2);
|
||||||
for (i = 0; i <= 128; i++) {
|
for (i = 0; i <= 255; i++) {
|
||||||
for (q = 0; q <= 128; q++) {
|
int mag_i = i-127;
|
||||||
Modes.maglut[i*129+q] = round(sqrt(i*i+q*q)*360);
|
for (q = 0; q <= 255; q++) {
|
||||||
|
int mag_q = q - 127;
|
||||||
|
Modes.maglut[i*256+q] = round(sqrt((mag_i*mag_i)+(mag_q*mag_q))*360);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,7 +445,7 @@ void readDataFromFile(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
toread = MODES_ASYNC_BUF_SIZE;
|
toread = MODES_ASYNC_BUF_SIZE;
|
||||||
p = Modes.data;
|
p = (unsigned char *) Modes.data;
|
||||||
while(toread) {
|
while(toread) {
|
||||||
nread = read(Modes.fd, p, toread);
|
nread = read(Modes.fd, p, toread);
|
||||||
if (nread <= 0) {
|
if (nread <= 0) {
|
||||||
|
@ -1236,7 +1238,7 @@ void displayModesMessage(struct modesMessage *mm) {
|
||||||
* pointed by Modes.magnitude. */
|
* pointed by Modes.magnitude. */
|
||||||
void computeMagnitudeVector(void) {
|
void computeMagnitudeVector(void) {
|
||||||
uint16_t *m = &Modes.magnitude[MODES_PREAMBLE_SAMPLES+MODES_LONG_MSG_SAMPLES];
|
uint16_t *m = &Modes.magnitude[MODES_PREAMBLE_SAMPLES+MODES_LONG_MSG_SAMPLES];
|
||||||
unsigned char *p = Modes.data;
|
uint16_t *p = Modes.data;
|
||||||
uint32_t j;
|
uint32_t j;
|
||||||
|
|
||||||
memcpy(Modes.magnitude,&Modes.magnitude[MODES_ASYNC_BUF_SAMPLES], MODES_PREAMBLE_SIZE+MODES_LONG_MSG_SIZE);
|
memcpy(Modes.magnitude,&Modes.magnitude[MODES_ASYNC_BUF_SAMPLES], MODES_PREAMBLE_SIZE+MODES_LONG_MSG_SIZE);
|
||||||
|
@ -1244,12 +1246,7 @@ void computeMagnitudeVector(void) {
|
||||||
/* Compute the magnitudo vector. It's just SQRT(I^2 + Q^2), but
|
/* Compute the magnitudo vector. It's just SQRT(I^2 + Q^2), but
|
||||||
* we rescale to the 0-255 range to exploit the full resolution. */
|
* we rescale to the 0-255 range to exploit the full resolution. */
|
||||||
for (j = 0; j < MODES_ASYNC_BUF_SAMPLES; j ++) {
|
for (j = 0; j < MODES_ASYNC_BUF_SAMPLES; j ++) {
|
||||||
int i = (*p++)-127;
|
*m++ = Modes.maglut[*p++];
|
||||||
int q = (*p++)-127;
|
|
||||||
|
|
||||||
if (i < 0) i = -i;
|
|
||||||
if (q < 0) q = -q;
|
|
||||||
*m++ = Modes.maglut[i*129+q];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue