From 0106011ce3c7251ad25523fb5f86de6fae807289 Mon Sep 17 00:00:00 2001 From: OSQZSS Date: Tue, 29 Dec 2015 11:40:46 +0900 Subject: [PATCH] Add 1-bit I/Q data format to reduce output file size --- gpssim.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/gpssim.c b/gpssim.c index 858460c..4473be2 100644 --- a/gpssim.c +++ b/gpssim.c @@ -76,6 +76,7 @@ typedef int bool; #define CARR_TO_CODE (1.0/1540.0) // Sampling data format +#define SC01 (1) #define SC08 (8) #define SC16 (16) @@ -1536,8 +1537,8 @@ void usage(void) " -d Duration [sec] (max: %.0f)\n" " -o I/Q sampling data file (default: gpssim.bin)\n" " -s Sampling frequency [Hz] (default: 2600000)\n" - " -b I/Q data format [8/16] (default: 16)\n" - " -v Show details about simulated channels\n", + " -b I/Q data format [1/8/16] (default: 16)\n" + " -v Show details about simulated channels\n", ((double)USER_MOTION_SIZE)/10.0); return; @@ -1658,7 +1659,7 @@ int main(int argc, char *argv[]) break; case 'b': data_format = atoi(optarg); - if (data_format!=SC08 && data_format!=SC16) + if (data_format!=SC01 && data_format!=SC08 && data_format!=SC16) { printf("ERROR: Invalid I/Q data format.\n"); exit(1); @@ -1856,7 +1857,7 @@ int main(int argc, char *argv[]) if (iq_buff==NULL) { - printf("ERROR: Faild to allocate IQ buffer.\n"); + printf("ERROR: Faild to allocate 16-bit I/Q buffer.\n"); exit(1); } @@ -1865,7 +1866,16 @@ int main(int argc, char *argv[]) iq8_buff = calloc(2*iq_buff_size, 1); if (iq8_buff==NULL) { - printf("ERROR: Faild to allocate IQ buffer.\n"); + printf("ERROR: Faild to allocate 8-bit I/Q buffer.\n"); + exit(1); + } + } + else if (data_format==SC01) + { + iq8_buff = calloc(iq_buff_size/4, 1); // byte = {I0, Q0, I1, Q1, I2, Q2, I3, Q3} + if (iq8_buff==NULL) + { + printf("ERROR: Faild to allocate compressed 1-bit I/Q buffer.\n"); exit(1); } } @@ -2009,15 +2019,32 @@ int main(int argc, char *argv[]) } // End of omp parallel for - if (data_format==SC08) + if (data_format==SC01) + { + for (isamp=0; isamp<2*iq_buff_size; isamp++) + { + if (isamp%8==0) + iq8_buff[isamp/8] = 0x00; + + iq8_buff[isamp/8] |= (iq_buff[isamp]>0?0x01:0x00)<<(7-isamp%8); + } + + fwrite(iq8_buff, 1, iq_buff_size/4, fp); + } + else if (data_format==SC08) { for (isamp=0; isamp<2*iq_buff_size; isamp++) iq8_buff[isamp] = iq_buff[isamp]>>4; // 12-bit bladeRF -> 8-bit HackRF fwrite(iq8_buff, 1, 2*iq_buff_size, fp); } - else + else // data_format==SC16 + { + for (isamp=0; isamp<2*iq_buff_size; isamp++) + iq_buff[isamp] = iq_buff[isamp]>0?1000:-1000; // Emulated 1-bit I/Q + fwrite(iq_buff, 2, 2*iq_buff_size, fp); + } // // Update navigation message and channel allocation every 30 seconds