mirror of https://github.com/PentHertz/srsLTE.git
Added PRACH test for USRP
This commit is contained in:
parent
d005ec8f9b
commit
104efa35ff
|
@ -2,18 +2,18 @@ clear
|
|||
ueConfig=struct('NULRB',6,'DuplexMode','FDD','CyclicPrefix','Normal');
|
||||
prachConfig=struct('Format',0,'SeqIdx',0,'PreambleIdx',0,'CyclicShiftIdx',0,'HighSpeed',0,'TimingOffset',0,'FreqIdx',0,'FreqOffset',0);
|
||||
|
||||
addpath('../../debug/srslte/lib/phch/test')
|
||||
addpath('../../build/srslte/lib/phch/test')
|
||||
|
||||
NULRB=[6 15 25 50 100];
|
||||
|
||||
% FreqIdx, FreqOffset and TimeOffset need to be tested
|
||||
|
||||
for n_rb=3:length(NULRB)
|
||||
for n_rb=1:length(NULRB)
|
||||
for format=0;
|
||||
for seqIdx=7:17:237
|
||||
fprintf('RB: %d, format %d, seqIdx: %d\n',NULRB(n_rb),format,seqIdx);
|
||||
for preambleIdx=0:23:63
|
||||
for CyclicShift=1:3:15
|
||||
fprintf('RB: %d, format %d, seqIdx: %d, Cyc=%d Idx=%d\n',NULRB(n_rb),format,seqIdx, CyclicShift, preambleIdx);
|
||||
%for hs=0:1
|
||||
hs=0;
|
||||
ueConfig.NULRB=NULRB(n_rb);
|
||||
|
@ -24,12 +24,14 @@ for n_rb=3:length(NULRB)
|
|||
prachConfig.HighSpeed=hs;
|
||||
prachConfig.FreqIdx=0;
|
||||
prachConfig.FreqOffset=0;
|
||||
lib=srslte_prach(ueConfig,prachConfig)*2.4645;
|
||||
lib=srslte_prach(ueConfig,prachConfig);
|
||||
|
||||
[mat, info]=ltePRACH(ueConfig,prachConfig);
|
||||
err=mean(abs(mat-lib));
|
||||
if (err > 10^-3)
|
||||
disp(err)
|
||||
a=1:100;
|
||||
plot(a,real(lib(a)),a,real(mat(a)))
|
||||
error('Error!');
|
||||
end
|
||||
%end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
ueConfig=struct('NCellID',1,'NULRB',25,'NSubframe',8,'RNTI',65,'CyclicPrefixUL','Normal','NTxAnts',1,'Shortened',0);
|
||||
ueConfig=struct('NCellID',1,'NULRB',25,'NSubframe',8,'RNTI',71,'CyclicPrefixUL','Normal','NTxAnts',1,'Shortened',0);
|
||||
puschConfig=struct('NTurboDecIts',5,'NLayers',1,'OrthCover','Off','PRBSet',22,'Modulation','16QAM','RV',0);
|
||||
|
||||
TBS=336;
|
||||
cfo=2717.973389;
|
||||
t0=1;
|
||||
cfo=3400;
|
||||
t0=128;
|
||||
x=[rx(t0:end); zeros(t0-1,1)];
|
||||
|
||||
subframe_rx=lteSCFDMADemodulate(ueConfig,x.*exp(-1i*2*pi*cfo/15000*transpose(1:length(x))/512));
|
||||
|
@ -15,4 +15,4 @@ ce=hest(idx);
|
|||
[trblkout,blkcrc,stateout] = lteULSCHDecode(ueConfig,puschConfig,TBS,cws);
|
||||
disp(blkcrc)
|
||||
scatter(real(symbols),imag(symbols))
|
||||
plot(real(hest(:,1)))
|
||||
%plot(angle(hest(:,1)))
|
|
@ -201,8 +201,7 @@ void setup_mac_phy_sib2(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT *sib2, srslte::u
|
|||
void process_connsetup(LIBLTE_RRC_CONNECTION_SETUP_STRUCT *msg, srslte::ue::mac *mac, srslte::ue::phy *phy) {
|
||||
|
||||
// FIXME: There's an error parsing the connectionSetup message. This value is hard-coded:
|
||||
msg->rr_cnfg.phy_cnfg_ded.sched_request_cnfg.sr_cnfg_idx = 35;
|
||||
|
||||
|
||||
phy->set_param(srslte::ue::phy_params::SR_PUCCH_RESINDEX,
|
||||
msg->rr_cnfg.phy_cnfg_ded.sched_request_cnfg.sr_pucch_resource_idx);
|
||||
phy->set_param(srslte::ue::phy_params::SR_CONFIG_INDEX,
|
||||
|
@ -388,6 +387,7 @@ int main(int argc, char *argv[])
|
|||
if (n > 0) {
|
||||
printf("ConnSetup received %d bytes\n", n/8);
|
||||
bit_msg.N_bits = n;
|
||||
srslte_vec_fprint_hex(stdout, bit_msg.msg, n);
|
||||
liblte_rrc_unpack_dl_ccch_msg(&bit_msg, &dl_ccch_msg);
|
||||
printf("Response: %s\n", liblte_rrc_dl_ccch_msg_type_text[dl_ccch_msg.msg_type]);
|
||||
switch (dl_ccch_msg.msg_type) {
|
||||
|
|
|
@ -108,14 +108,15 @@ radio* phy::get_radio() {
|
|||
}
|
||||
|
||||
void phy::set_timeadv_rar(uint32_t ta_cmd) {
|
||||
ta_cmd=7;
|
||||
n_ta = srslte_N_ta_new_rar(ta_cmd);
|
||||
time_adv_sec = SRSLTE_TA_OFFSET+((float) n_ta)/(15000.0*2048);
|
||||
time_adv_sec = ((float) n_ta)/(15000.0*srslte_symbol_sz(cell.nof_prb));
|
||||
Info("Set TA RAR: ta_cmd: %d, n_ta: %d, ta_usec: %.1f\n", ta_cmd, n_ta, time_adv_sec*1e6);
|
||||
}
|
||||
|
||||
void phy::set_timeadv(uint32_t ta_cmd) {
|
||||
n_ta = srslte_N_ta_new(n_ta, ta_cmd);
|
||||
time_adv_sec = SRSLTE_TA_OFFSET+((float) n_ta)/(15000.0*2048);
|
||||
time_adv_sec = ((float) n_ta)/(15000.0*srslte_symbol_sz(cell.nof_prb));
|
||||
Info("Set TA: ta_cmd: %d, n_ta: %d, ta_usec: %.1f\n", ta_cmd, n_ta, time_adv_sec*1e6);
|
||||
}
|
||||
|
||||
|
|
|
@ -423,7 +423,7 @@ int srslte_prach_gen(srslte_prach_t *p,
|
|||
uint32_t N_rb_ul = prach_get_rb_ul(p->N_ifft_ul);
|
||||
uint32_t k_0 = freq_offset*N_RB_SC - N_rb_ul*N_RB_SC/2 + p->N_ifft_ul/2;
|
||||
uint32_t K = DELTA_F/DELTA_F_RA;
|
||||
uint32_t begin = PHI + (K*k_0) + (K/2) + 1;
|
||||
uint32_t begin = PHI + (K*k_0) + (K/2);
|
||||
|
||||
DEBUG("N_zc: %d, N_cp: %d, N_seq: %d, N_ifft_prach=%d begin: %d\n", p->N_zc, p->N_cp, p->N_seq, p->N_ifft_prach, begin);
|
||||
// Map dft-precoded sequence to ifft bins
|
||||
|
@ -440,7 +440,6 @@ int srslte_prach_gen(srslte_prach_t *p,
|
|||
for(int i=0;i<p->N_seq;i++){
|
||||
signal[p->N_cp+i] = p->ifft_out[i%p->N_ifft_prach];
|
||||
}
|
||||
srslte_vec_sc_prod_cfc(signal, PRACH_AMP, signal, p->N_cp + p->N_seq);
|
||||
|
||||
ret = SRSLTE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -192,5 +192,10 @@ ADD_TEST(prach_test_multi_n8 prach_test_multi -n 8)
|
|||
ADD_TEST(prach_test_multi_n4 prach_test_multi -n 4)
|
||||
|
||||
|
||||
BuildMex(MEXNAME prach SOURCES prach_test_mex.c LIBRARIES srslte srslte_mex)
|
||||
BuildMex(MEXNAME prach SOURCES prach_test_mex.c LIBRARIES srslte srslte_mex)
|
||||
|
||||
|
||||
IF(UHD_FOUND)
|
||||
ADD_EXECUTABLE(prach_test_usrp prach_test_usrp.c)
|
||||
TARGET_LINK_LIBRARIES(prach_test_usrp srslte srslte_uhd)
|
||||
ENDIF(UHD_FOUND)
|
||||
|
|
|
@ -1,3 +1,31 @@
|
|||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 The srsLTE Developers. See the
|
||||
* COPYRIGHT file at the top-level directory of this distribution.
|
||||
*
|
||||
* \section LICENSE
|
||||
*
|
||||
* This file is part of the srsLTE library.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
|
@ -0,0 +1,198 @@
|
|||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 The srsLTE Developers. See the
|
||||
* COPYRIGHT file at the top-level directory of this distribution.
|
||||
*
|
||||
* \section LICENSE
|
||||
*
|
||||
* This file is part of the srsLTE library.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include <complex.h>
|
||||
|
||||
#include "srslte/cuhd/cuhd.h"
|
||||
#include "srslte/srslte.h"
|
||||
|
||||
#define MAX_LEN 70176
|
||||
|
||||
|
||||
uint32_t nof_prb = 25;
|
||||
uint32_t preamble_format = 0;
|
||||
uint32_t root_seq_idx = 0;
|
||||
uint32_t seq_idx = 0;
|
||||
uint32_t frequency_offset = 0;
|
||||
uint32_t zero_corr_zone = 0;
|
||||
uint32_t nof_frames = 20;
|
||||
|
||||
float uhd_gain=40, uhd_freq=2.4e9;
|
||||
char *uhd_args="";
|
||||
char *output_filename = NULL;
|
||||
|
||||
void usage(char *prog) {
|
||||
printf("Usage: %s \n", prog);
|
||||
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-g UHD TX/RX gain [Default %.1f dB]\n", uhd_gain);
|
||||
printf("\t-p Number of UL RB [Default %d]\n", nof_prb);
|
||||
printf("\t-F Preamble format [Default %d]\n", preamble_format);
|
||||
printf("\t-s sequence index [Default %d]\n", seq_idx);
|
||||
printf("\t-r Root sequence index [Default %d]\n", root_seq_idx);
|
||||
printf("\t-z Zero correlation zone config [Default %d]\n", zero_corr_zone);
|
||||
printf("\t-o Save transmitted PRACH in file [Default no]\n");
|
||||
}
|
||||
|
||||
void parse_args(int argc, char **argv) {
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "apfFgrsoz")) != -1) {
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
uhd_args = argv[optind];
|
||||
break;
|
||||
case 'o':
|
||||
output_filename = argv[optind];
|
||||
break;
|
||||
case 'f':
|
||||
uhd_freq = atof(argv[optind]);
|
||||
break;
|
||||
case 'g':
|
||||
uhd_gain = atof(argv[optind]);
|
||||
break;
|
||||
case 'p':
|
||||
nof_prb = atoi(argv[optind]);
|
||||
if (!srslte_nofprb_isvalid(nof_prb)) {
|
||||
fprintf(stderr, "Invalid number of UL RB %d\n", nof_prb);
|
||||
exit(-1);
|
||||
}
|
||||
break;
|
||||
case 'F':
|
||||
preamble_format = atoi(argv[optind]);
|
||||
break;
|
||||
case 'r':
|
||||
root_seq_idx = atoi(argv[optind]);
|
||||
break;
|
||||
case 's':
|
||||
seq_idx = atoi(argv[optind]);
|
||||
break;
|
||||
case 'z':
|
||||
zero_corr_zone = atoi(argv[optind]);
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
parse_args(argc, argv);
|
||||
|
||||
srslte_prach_t *p = (srslte_prach_t*)malloc(sizeof(srslte_prach_t));
|
||||
|
||||
bool high_speed_flag = false;
|
||||
|
||||
cf_t preamble[MAX_LEN];
|
||||
memset(preamble, 0, sizeof(cf_t)*MAX_LEN);
|
||||
|
||||
srslte_prach_init(p,
|
||||
srslte_symbol_sz(nof_prb),
|
||||
preamble_format,
|
||||
root_seq_idx,
|
||||
high_speed_flag,
|
||||
zero_corr_zone);
|
||||
|
||||
uint32_t flen = srslte_sampling_freq_hz(nof_prb)/1000;
|
||||
|
||||
printf("Generating PRACH\n");
|
||||
bzero(preamble, flen*sizeof(cf_t));
|
||||
srslte_prach_gen(p,
|
||||
seq_idx,
|
||||
frequency_offset,
|
||||
preamble);
|
||||
|
||||
|
||||
uint32_t prach_len = p->N_seq;
|
||||
|
||||
srslte_vec_save_file("generated",preamble,prach_len*sizeof(cf_t));
|
||||
|
||||
cf_t *buffer = malloc(sizeof(cf_t)*flen*nof_frames);
|
||||
|
||||
// Send through UHD
|
||||
void *uhd;
|
||||
printf("Opening UHD device...\n");
|
||||
if (cuhd_open(uhd_args, &uhd)) {
|
||||
fprintf(stderr, "Error opening uhd\n");
|
||||
exit(-1);
|
||||
}
|
||||
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 gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain));
|
||||
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_gain(uhd, uhd_gain);
|
||||
cuhd_set_tx_freq(uhd, uhd_freq);
|
||||
cuhd_rx_wait_lo_locked(uhd);
|
||||
|
||||
cf_t *zeros = calloc(sizeof(cf_t),flen);
|
||||
|
||||
FILE *f = NULL;
|
||||
if (output_filename) {
|
||||
f = fopen(output_filename, "w");
|
||||
}
|
||||
|
||||
srslte_timestamp_t tstamp;
|
||||
|
||||
cuhd_start_rx_stream(uhd);
|
||||
uint32_t nframe=0;
|
||||
|
||||
while(nframe<nof_frames) {
|
||||
cuhd_recv_with_time(uhd, &buffer[flen*nframe], flen, true, &tstamp.full_secs, &tstamp.frac_secs);
|
||||
nframe++;
|
||||
if (nframe==9 || nframe==8) {
|
||||
srslte_timestamp_add(&tstamp, 0, 2e-3);
|
||||
if (nframe==8) {
|
||||
cuhd_send_timed2(uhd, zeros, flen, tstamp.full_secs, tstamp.frac_secs, true, false);
|
||||
printf("Transmitting zeros\n");
|
||||
} else {
|
||||
cuhd_send_timed2(uhd, preamble, flen, tstamp.full_secs, tstamp.frac_secs, false, true);
|
||||
printf("Transmitting PRACH\n");
|
||||
}
|
||||
}
|
||||
printf("Rx subframe %d\n", nframe);
|
||||
}
|
||||
if (f) {
|
||||
fwrite(&buffer[10*flen], flen*sizeof(cf_t), 1, f);
|
||||
}
|
||||
if (f) {
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
srslte_prach_free(p);
|
||||
free(p);
|
||||
|
||||
printf("Done\n");
|
||||
exit(0);
|
||||
}
|
Loading…
Reference in New Issue