Fixed sync test

master
ismagom 9 years ago
parent 0e8421e76c
commit 7956e04dcc

@ -40,23 +40,26 @@
uint32_t nof_prb = 25; uint32_t nof_prb = 25;
uint32_t nof_frames = 20; uint32_t nof_frames = 20;
float tone_offset_hz = 0;
float uhd_rx_gain=40, uhd_tx_gain=40, uhd_freq=2.4e9; float uhd_rx_gain=40, uhd_tx_gain=40, uhd_freq=2.4e9;
char *uhd_args=""; char *uhd_args="";
char *output_filename = NULL; char *output_filename = NULL;
char *input_filename = NULL; char *input_filename = NULL;
void usage(char *prog) { void usage(char *prog) {
printf("Usage: %s -i [tx_signal_file] -o [rx_signal_file]\n", prog); printf("Usage: %s -o [rx_signal_file]\n", prog);
printf("\t-a UHD args [Default %s]\n", uhd_args); printf("\t-a UHD args [Default %s]\n", uhd_args);
printf("\t-f UHD TX/RX frequency [Default %.2f MHz]\n", uhd_freq/1e6); printf("\t-f UHD TX/RX frequency [Default %.2f MHz]\n", uhd_freq/1e6);
printf("\t-g UHD RX gain [Default %.1f dB]\n", uhd_rx_gain); printf("\t-g UHD RX gain [Default %.1f dB]\n", uhd_rx_gain);
printf("\t-G UHD TX gain [Default %.1f dB]\n", uhd_tx_gain); printf("\t-G UHD TX gain [Default %.1f dB]\n", uhd_tx_gain);
printf("\t-t Single tone offset (Hz) [Default %f]\n", tone_offset_hz);
printf("\t-i File name to read signal from [Default single tone]\n");
printf("\t-p Number of UL RB [Default %d]\n", nof_prb); printf("\t-p Number of UL RB [Default %d]\n", nof_prb);
} }
void parse_args(int argc, char **argv) { void parse_args(int argc, char **argv) {
int opt; int opt;
while ((opt = getopt(argc, argv, "ioafgp")) != -1) { while ((opt = getopt(argc, argv, "ioafgpt")) != -1) {
switch (opt) { switch (opt) {
case 'a': case 'a':
uhd_args = argv[optind]; uhd_args = argv[optind];
@ -67,6 +70,9 @@ void parse_args(int argc, char **argv) {
case 'i': case 'i':
input_filename = argv[optind]; input_filename = argv[optind];
break; break;
case 't':
tone_offset_hz = atof(argv[optind]);
break;
case 'f': case 'f':
uhd_freq = atof(argv[optind]); uhd_freq = atof(argv[optind]);
break; break;
@ -88,7 +94,7 @@ void parse_args(int argc, char **argv) {
exit(-1); exit(-1);
} }
} }
if (!input_filename || !output_filename) { if (!output_filename) {
usage(argv[0]); usage(argv[0]);
exit(-1); exit(-1);
} }
@ -127,17 +133,33 @@ int main(int argc, char **argv) {
exit(-1); exit(-1);
} }
cuhd_set_master_clock_rate(uhd, 30.72e6); cuhd_set_master_clock_rate(uhd, 30.72e6);
int srate = srslte_sampling_freq_hz(nof_prb);
if (srate < 10e6) {
cuhd_set_master_clock_rate(uhd, 4*srate);
} else {
cuhd_set_master_clock_rate(uhd, srate);
}
cuhd_set_rx_srate(uhd, (double) srate);
cuhd_set_tx_srate(uhd, (double) srate);
printf("Subframe len: %d samples\n", flen); printf("Subframe len: %d samples\n", flen);
printf("Set TX/RX rate: %.2f MHz\n", cuhd_set_rx_srate(uhd, srslte_sampling_freq_hz(nof_prb)) / 1000000); printf("Set TX/RX rate: %.2f MHz\n", (float) srate / 1000000);
printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_rx_gain)); printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_rx_gain));
printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_tx_gain)); printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_tx_gain));
printf("Set TX/RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); printf("Set TX/RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000);
cuhd_set_tx_srate(uhd, srslte_sampling_freq_hz(nof_prb));
cuhd_set_tx_freq_offset(uhd, uhd_freq, 8e6); cuhd_set_tx_freq_offset(uhd, uhd_freq, 8e6);
sleep(1); sleep(1);
srslte_vec_load_file(input_filename, &tx_buffer[nsamples_adv], flen*sizeof(cf_t)); if (input_filename) {
srslte_vec_load_file(input_filename, &tx_buffer[nsamples_adv], flen*sizeof(cf_t));
} else {
for (int i=0;i<flen-nsamples_adv;i++) {
tx_buffer[i+nsamples_adv] = cexpf(_Complex_I*2*M_PI*tone_offset_hz*(float) i/(float) srate);
}
srslte_vec_save_file("uhd_txrx_tone", tx_buffer, flen*sizeof(cf_t));
}
srslte_timestamp_t tstamp; srslte_timestamp_t tstamp;

@ -79,7 +79,7 @@ void parse_args(int argc, char **argv) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
int N_id_2, ns, find_ns; int N_id_2, sf_idx, find_sf;
cf_t *buffer, *fft_buffer; cf_t *buffer, *fft_buffer;
cf_t pss_signal[SRSLTE_PSS_LEN]; cf_t pss_signal[SRSLTE_PSS_LEN];
float sss_signal0[SRSLTE_SSS_LEN]; // for subframe 0 float sss_signal0[SRSLTE_SSS_LEN]; // for subframe 0
@ -104,7 +104,7 @@ int main(int argc, char **argv) {
exit(-1); exit(-1);
} }
fft_buffer = malloc(sizeof(cf_t) * FLEN); fft_buffer = malloc(sizeof(cf_t) * FLEN * 2);
if (!fft_buffer) { if (!fft_buffer) {
perror("malloc"); perror("malloc");
exit(-1); exit(-1);
@ -142,28 +142,29 @@ int main(int argc, char **argv) {
srslte_sync_set_N_id_2(&sync, N_id_2); srslte_sync_set_N_id_2(&sync, N_id_2);
for (ns=0;ns<2;ns++) { // SF1 is SF5
for (sf_idx=0;sf_idx<2;sf_idx++) {
memset(buffer, 0, sizeof(cf_t) * FLEN); memset(buffer, 0, sizeof(cf_t) * FLEN);
srslte_pss_put_slot(pss_signal, buffer, nof_prb, cp); srslte_pss_put_slot(pss_signal, buffer, nof_prb, cp);
srslte_sss_put_slot(ns?sss_signal5:sss_signal0, buffer, nof_prb, cp); srslte_sss_put_slot(sf_idx?sss_signal5:sss_signal0, buffer, nof_prb, cp);
/* Transform to OFDM symbols */ /* Transform to OFDM symbols */
memset(fft_buffer, 0, sizeof(cf_t) * FLEN); memset(fft_buffer, 0, sizeof(cf_t) * FLEN);
srslte_ofdm_tx_slot(&ifft, buffer, &fft_buffer[offset]); srslte_ofdm_tx_sf(&ifft, buffer, &fft_buffer[offset]);
if (srslte_sync_find(&sync, fft_buffer, 0, &find_idx) < 0) { if (srslte_sync_find(&sync, fft_buffer, 0, &find_idx) < 0) {
fprintf(stderr, "Error running srslte_sync_find\n"); fprintf(stderr, "Error running srslte_sync_find\n");
exit(-1); exit(-1);
} }
find_ns = 2*srslte_sync_get_sf_idx(&sync); find_sf = srslte_sync_get_sf_idx(&sync);
printf("cell_id: %d find: %d, offset: %d, ns=%d find_ns=%d\n", cid, find_idx, offset, printf("cell_id: %d find: %d, offset: %d, ns=%d find_ns=%d\n", cid, find_idx, offset,
ns, find_ns); sf_idx, find_sf);
if (find_idx != offset + FLEN/2) { if (find_idx != offset + FLEN/2) {
printf("offset != find_offset: %d != %d\n", find_idx, offset + FLEN/2); printf("offset != find_offset: %d != %d\n", find_idx, offset + FLEN/2);
exit(-1); exit(-1);
} }
if (ns*10 != find_ns) { if (sf_idx*5 != find_sf) {
printf("ns != find_ns\n", 10 * ns, find_ns); printf("ns != find_ns\n");
exit(-1); exit(-1);
} }
if (srslte_sync_get_cp(&sync) != cp) { if (srslte_sync_get_cp(&sync) != cp) {

Loading…
Cancel
Save