Started with pusch processing

master
Ismael Gomez 9 years ago
parent d622d5d19d
commit 8de159dc29

@ -7,33 +7,8 @@
recordedSignal=[];
Npackets = 20;
SNR_values = linspace(2,6,10);
Lp=12;
N=256;
K=180;
rstart=(N-K)/2;
P=K/6;
Rhphp=zeros(P,P);
Rhhp=zeros(K,P);
Rhh=zeros(K,K);
t=0:Lp-1;
alfa=log(2*Lp)/Lp;
c_l=exp(-t*alfa);
c_l=c_l/sum(c_l);
C_l=diag(1./c_l);
prows=rstart+(1:6:K);
F=dftmtx(N);
F_p=F(prows,1:Lp);
F_l=F((rstart+1):(K+rstart),1:Lp);
Wi=(F_p'*F_p+C_l*0.01)^(-1);
W2=F_l*Wi*F_p';
w2=reshape(transpose(W2),1,[]);
Npackets = 1;
SNR_values = 10;%linspace(2,6,10);
%% Choose RMC
[waveform,rgrid,rmccFgOut] = lteRMCDLTool('R.0',[1;0;0;1]);
waveform = sum(waveform,2);

@ -78,7 +78,6 @@ void srslte_dft_precoding_free(srslte_dft_precoding_t *q)
{
for (uint32_t i=1;i<=q->max_prb;i++) {
if(srslte_dft_precoding_valid_prb(i)) {
DEBUG("Freeing DFT precoding plan for %d PRBs\n", i);
srslte_dft_plan_free(&q->dft_plan[i]);
srslte_dft_plan_free(&q->idft_plan[i]);
}
@ -121,7 +120,7 @@ int srslte_dft_predecoding(srslte_dft_precoding_t *q, cf_t *input, cf_t *output,
}
for (uint32_t i=0;i<nof_symbols;i++) {
srslte_dft_run_c(&q->dft_plan[nof_prb], &input[i*SRSLTE_NRE*nof_prb], &output[i*SRSLTE_NRE*nof_prb]);
srslte_dft_run_c(&q->idft_plan[nof_prb], &input[i*SRSLTE_NRE*nof_prb], &output[i*SRSLTE_NRE*nof_prb]);
}
return SRSLTE_SUCCESS;

@ -149,7 +149,7 @@ int pusch_cp(srslte_pusch_t *q, srslte_ra_ul_grant_t *grant, cf_t *input, cf_t *
if (q->shortened && slot == 1) {
N_srs = 1;
}
INFO("Allocating PUSCH %d PRB to index %d at slot %d\n",grant->L_prb, grant->n_prb_tilde[slot], slot);
INFO("%s PUSCH %d PRB to index %d at slot %d\n",advance_input?"Allocating":"Getting",grant->L_prb, grant->n_prb_tilde[slot], slot);
for (uint32_t l=0;l<SRSLTE_CP_NSYMB(q->cell.cp)-N_srs;l++) {
if (l != L_ref) {
uint32_t idx = SRSLTE_RE_IDX(q->cell.nof_prb, l+slot*SRSLTE_CP_NSYMB(q->cell.cp),
@ -168,7 +168,11 @@ int pusch_cp(srslte_pusch_t *q, srslte_ra_ul_grant_t *grant, cf_t *input, cf_t *
}
}
}
return SRSLTE_NRE*grant->L_prb;
if (advance_input) {
return in_ptr - input;
} else {
return out_ptr - output;
}
}
int pusch_put(srslte_pusch_t *q, srslte_ra_ul_grant_t *grant, cf_t *input, cf_t *output) {
@ -393,64 +397,6 @@ int srslte_pusch_set_rnti(srslte_pusch_t *q, uint16_t rnti) {
return SRSLTE_SUCCESS;
}
/** Decodes the PUSCH from the received symbols
*/
int srslte_pusch_decode(srslte_pusch_t *q,
srslte_pusch_cfg_t *cfg, srslte_softbuffer_rx_t *softbuffer,
cf_t *sf_symbols,
cf_t *ce, float noise_estimate,
uint8_t *data)
{
uint32_t n;
if (q != NULL &&
sf_symbols != NULL &&
data != NULL &&
cfg != NULL)
{
if (q->rnti_is_set) {
INFO("Decoding PUSCH SF: %d, Mod %s, NofBits: %d, NofRE: %d, NofSymbols=%d, NofBitsE: %d, rv_idx: %d\n",
cfg->sf_idx, srslte_mod_string(cfg->grant.mcs.mod), cfg->grant.mcs.tbs,
cfg->nbits.nof_re, cfg->nbits.nof_symb, cfg->nbits.nof_bits, cfg->rv);
/* extract symbols */
n = pusch_get(q, &cfg->grant, sf_symbols, q->d);
if (n != cfg->nbits.nof_re) {
fprintf(stderr, "Error expecting %d symbols but got %d\n", cfg->nbits.nof_re, n);
return SRSLTE_ERROR;
}
/* extract channel estimates */
n = pusch_get(q, &cfg->grant, ce, q->ce);
if (n != cfg->nbits.nof_re) {
fprintf(stderr, "Error expecting %d symbols but got %d\n", cfg->nbits.nof_re, n);
return SRSLTE_ERROR;
}
srslte_predecoding_single(q->d, q->ce, q->z, cfg->nbits.nof_re, noise_estimate);
srslte_dft_predecoding(&q->dft_precoding, q->z, q->d, cfg->grant.L_prb, cfg->nbits.nof_symb);
/* demodulate symbols
* The MAX-log-MAP algorithm used in turbo decoding is unsensitive to SNR estimation,
* thus we don't need tot set it in the LLRs normalization
*/
srslte_demod_soft_demodulate(cfg->grant.mcs.mod, q->d, q->q, cfg->nbits.nof_re);
/* descramble */
srslte_scrambling_f_offset(&q->seq[cfg->sf_idx], q->q, 0, cfg->nbits.nof_bits);
return srslte_ulsch_decode(&q->dl_sch, cfg, softbuffer, q->q, data);
} else {
fprintf(stderr, "Must call srslte_pusch_set_rnti() before calling srslte_pusch_decode()\n");
return SRSLTE_ERROR;
}
} else {
return SRSLTE_ERROR_INVALID_INPUTS;
}
}
int srslte_pusch_encode_rnti(srslte_pusch_t *q, srslte_pusch_cfg_t *cfg, srslte_softbuffer_tx_t *softbuffer,
uint8_t *data, uint16_t rnti,
@ -514,6 +460,10 @@ int srslte_pusch_uci_encode_rnti(srslte_pusch_t *q, srslte_pusch_cfg_t *cfg, srs
return SRSLTE_ERROR;
}
uint8_t tx_bits[10000];
srslte_bit_unpack_vector(q->q, tx_bits, cfg->nbits.nof_bits);
srslte_vec_save_file("tx_bits", tx_bits, sizeof(uint8_t)*cfg->nbits.nof_bits);
if (rnti != q->rnti || !q->rnti_is_set) {
srslte_sequence_t seq;
if (srslte_sequence_pusch(&seq, rnti, 2 * cfg->sf_idx, q->cell.id, cfg->nbits.nof_bits)) {
@ -542,15 +492,87 @@ int srslte_pusch_uci_encode_rnti(srslte_pusch_t *q, srslte_pusch_cfg_t *cfg, srs
}
}
}
srslte_bit_unpack_vector(q->q, tx_bits, cfg->nbits.nof_bits);
srslte_vec_save_file("tx_bits_scram", tx_bits, sizeof(uint8_t)*cfg->nbits.nof_bits);
// Bit mapping
srslte_mod_modulate_bytes(&q->mod[cfg->grant.mcs.mod], (uint8_t*) q->q, q->d, cfg->nbits.nof_bits);
srslte_vec_save_file("tx_symbols", q->d, sizeof(cf_t)*cfg->nbits.nof_re);
// DFT precoding
srslte_dft_precoding(&q->dft_precoding, q->d, q->z, cfg->grant.L_prb, cfg->nbits.nof_symb);
/* mapping to resource elements */
// Mapping to resource elements
pusch_put(q, &cfg->grant, q->z, sf_symbols);
ret = SRSLTE_SUCCESS;
}
return ret;
}
/** Decodes the PUSCH from the received symbols
*/
int srslte_pusch_decode(srslte_pusch_t *q,
srslte_pusch_cfg_t *cfg, srslte_softbuffer_rx_t *softbuffer,
cf_t *sf_symbols,
cf_t *ce, float noise_estimate,
uint8_t *data)
{
uint32_t n;
if (q != NULL &&
sf_symbols != NULL &&
data != NULL &&
cfg != NULL)
{
if (q->rnti_is_set) {
INFO("Decoding PUSCH SF: %d, Mod %s, NofBits: %d, NofRE: %d, NofSymbols=%d, NofBitsE: %d, rv_idx: %d\n",
cfg->sf_idx, srslte_mod_string(cfg->grant.mcs.mod), cfg->grant.mcs.tbs,
cfg->nbits.nof_re, cfg->nbits.nof_symb, cfg->nbits.nof_bits, cfg->rv);
/* extract symbols */
n = pusch_get(q, &cfg->grant, sf_symbols, q->d);
if (n != cfg->nbits.nof_re) {
fprintf(stderr, "Error expecting %d symbols but got %d\n", cfg->nbits.nof_re, n);
return SRSLTE_ERROR;
}
/* extract channel estimates */
n = pusch_get(q, &cfg->grant, ce, q->ce);
if (n != cfg->nbits.nof_re) {
fprintf(stderr, "Error expecting %d symbols but got %d\n", cfg->nbits.nof_re, n);
return SRSLTE_ERROR;
}
// Equalization
srslte_predecoding_single(q->d, q->ce, q->z, cfg->nbits.nof_re, noise_estimate);
// DFT predecoding
srslte_dft_predecoding(&q->dft_precoding, q->z, q->d, cfg->grant.L_prb, cfg->nbits.nof_symb);
srslte_vec_save_file("rx_symbols", q->d, sizeof(cf_t)*cfg->nbits.nof_re);
// Soft demodulation
srslte_demod_soft_demodulate(cfg->grant.mcs.mod, q->d, q->q, cfg->nbits.nof_re);
srslte_vec_save_file("rx_bits_scram", q->q, sizeof(float)*cfg->nbits.nof_bits);
// Descrambling
srslte_scrambling_f_offset(&q->seq[cfg->sf_idx], q->q, 0, cfg->nbits.nof_bits);
srslte_vec_save_file("rx_bits", q->q, sizeof(float)*cfg->nbits.nof_bits);
return srslte_ulsch_decode(&q->dl_sch, cfg, softbuffer, q->q, data);
} else {
fprintf(stderr, "Must call srslte_pusch_set_rnti() before calling srslte_pusch_decode()\n");
return SRSLTE_ERROR;
}
} else {
return SRSLTE_ERROR_INVALID_INPUTS;
}
}

@ -498,15 +498,6 @@ int srslte_dlsch_encode(srslte_sch_t *q, srslte_pdsch_cfg_t *cfg, srslte_softbuf
data, e_bits);
}
int srslte_ulsch_decode(srslte_sch_t *q, srslte_pusch_cfg_t *cfg, srslte_softbuffer_rx_t *softbuffer,
int16_t *e_bits, uint8_t *data)
{
return decode_tb(q,
softbuffer, &cfg->cb_segm,
cfg->grant.Qm, cfg->rv, cfg->nbits.nof_bits,
e_bits, data);
}
/* UL-SCH channel interleaver according to 5.2.2.8 of 36.212 */
void ulsch_interleave(uint8_t *g_bits, uint32_t Qm, uint32_t H_prime_total,
uint32_t N_pusch_symbs, uint8_t *q_bits, srslte_uci_bit_t *ri_bits, uint32_t nof_ri_bits,
@ -561,6 +552,62 @@ void ulsch_interleave(uint8_t *g_bits, uint32_t Qm, uint32_t H_prime_total,
}
}
uint16_t deinterleaver_buffer[100000];
/* UL-SCH channel deinterleaver according to 5.2.2.8 of 36.212 */
void ulsch_deinterleave(uint8_t *q_bits, uint32_t Qm, uint32_t H_prime_total,
uint32_t N_pusch_symbs, uint8_t *g_bits, srslte_uci_bit_t *ri_bits, uint32_t nof_ri_bits,
uint16_t *interleaver_buffer, uint8_t *temp_buffer, uint32_t buffer_sz)
{
uint32_t rows = H_prime_total/N_pusch_symbs;
uint32_t cols = N_pusch_symbs;
/* Compute the interleaving function on-the-fly, because it depends on number of RI bits
* Profiling show that the computation of this matrix is neglegible.
*/
uint32_t idx = 0;
for(uint32_t j=0; j<rows; j++) {
for(uint32_t i=0; i<cols; i++) {
for(uint32_t k=0; k<Qm; k++) {
if (temp_buffer[j*Qm + i*rows*Qm + k]) {
interleaver_buffer[j*Qm + i*rows*Qm + k] = 0;
} else {
if (j*Qm + i*rows*Qm + k < buffer_sz) {
interleaver_buffer[j*Qm + i*rows*Qm + k] = idx;
deinterleaver_buffer[idx] = j*Qm + i*rows*Qm + k;
idx++;
} else {
fprintf(stderr, "Error computing ULSCH interleaver. Position %d exceeds buffer size %d\n", j*Qm + i*rows*Qm + k, buffer_sz);
}
}
}
}
}
srslte_vec_fprint_s(stdout, interleaver_buffer, H_prime_total*Qm);
srslte_vec_fprint_s(stdout, deinterleaver_buffer, H_prime_total*Qm);
srslte_bit_interleave(q_bits, g_bits, deinterleaver_buffer, H_prime_total*Qm);
}
int srslte_ulsch_decode(srslte_sch_t *q, srslte_pusch_cfg_t *cfg, srslte_softbuffer_rx_t *softbuffer,
int16_t *e_bits, uint8_t *data)
{
// Interleave UL-SCH (and RI and CQI)
ulsch_deinterleave(e_bits, Qm, nb_q/Qm, cfg->nbits.nof_symb, q_bits, q->ack_ri_bits, Q_prime_ri*Qm,
q->ul_interleaver, q->temp_g_bits, SRSLTE_MAX_PRB*12*12*12);
srslte_vec_fprint_f(stdout, q->temp_g_bits, nb_q);
decode_tb(q, softbuffer, &cfg->cb_segm,
cfg->grant.Qm, cfg->rv, cfg->nbits.nof_bits,
e_bits, data);
}
int srslte_ulsch_encode(srslte_sch_t *q, srslte_pusch_cfg_t *cfg, srslte_softbuffer_tx_t *softbuffer,
uint8_t *data, uint8_t *g_bits, uint8_t *q_bits)
{
@ -625,8 +672,10 @@ int srslte_ulsch_uci_encode(srslte_sch_t *q,
}
}
//srslte_bit_unpack_vector(g_bits, kk, nb_q);
//srslte_vec_fprint_b(stdout, kk, nb_q);
uint8_t kk[10000];
srslte_bit_unpack_vector(g_bits, kk, nb_q);
srslte_vec_save_file("g_bits_tx", kk, nb_q);
srslte_vec_fprint_b(stdout, kk, nb_q);
// Interleave UL-SCH (and RI and CQI)
ulsch_interleave(g_bits, Qm, nb_q/Qm, cfg->nbits.nof_symb, q_bits, q->ack_ri_bits, Q_prime_ri*Qm,

@ -113,10 +113,12 @@ int main(int argc, char **argv) {
srslte_pusch_t pusch;
uint8_t *data = NULL;
cf_t *sf_symbols = NULL;
cf_t *ce = NULL;
int ret = -1;
struct timeval t[3];
srslte_pusch_cfg_t cfg;
srslte_softbuffer_tx_t softbuffer;
srslte_softbuffer_tx_t softbuffer_tx;
srslte_softbuffer_rx_t softbuffer_rx;
parse_args(argc,argv);
@ -184,12 +186,6 @@ int main(int argc, char **argv) {
perror("malloc");
goto quit;
}
cf_t *scfdma = srslte_vec_malloc(sizeof(cf_t) * SRSLTE_SF_LEN_PRB(cell.nof_prb));
bzero(scfdma, sizeof(cf_t) * SRSLTE_SF_LEN_PRB(cell.nof_prb));
srslte_ofdm_t fft;
srslte_ofdm_tx_init(&fft, SRSLTE_CP_NORM, cell.nof_prb);
srslte_ofdm_set_freq_shift(&fft, 0.5);
data = srslte_vec_malloc(sizeof(uint8_t) * cfg.grant.mcs.tbs);
if (!data) {
@ -201,40 +197,48 @@ int main(int argc, char **argv) {
data[i] = 1;
}
if (srslte_softbuffer_tx_init(&softbuffer, 100)) {
if (srslte_softbuffer_tx_init(&softbuffer_tx, 100)) {
fprintf(stderr, "Error initiating soft buffer\n");
goto quit;
}
if (srslte_softbuffer_rx_init(&softbuffer_rx, 100)) {
fprintf(stderr, "Error initiating soft buffer\n");
goto quit;
}
uint32_t ntrials = 100;
gettimeofday(&t[1], NULL);
for (int i=0;i<ntrials;i++) {
if (srslte_pusch_uci_encode(&pusch, &cfg, &softbuffer, data, uci_data, sf_symbols)) {
fprintf(stderr, "Error encoding TB\n");
exit(-1);
}
if (srslte_pusch_uci_encode(&pusch, &cfg, &softbuffer_tx, data, uci_data, sf_symbols)) {
fprintf(stderr, "Error encoding TB\n");
exit(-1);
}
if (rv_idx > 0) {
cfg.rv = rv_idx;
if (srslte_pusch_uci_encode(&pusch, &cfg, &softbuffer, data, uci_data, sf_symbols)) {
if (srslte_pusch_uci_encode(&pusch, &cfg, &softbuffer_tx, data, uci_data, sf_symbols)) {
fprintf(stderr, "Error encoding TB\n");
exit(-1);
}
}
srslte_ofdm_tx_sf(&fft, sf_symbols, scfdma);
ce = srslte_vec_malloc(sizeof(cf_t) * SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp));
if (!ce) {
perror("srslte_vec_malloc");
goto quit;
}
for (int j=0;j<SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp);j++) {
ce[j] = 1;
}
gettimeofday(&t[1], NULL);
int r = srslte_pusch_decode(&pusch, &cfg, &softbuffer_rx, sf_symbols, ce, 0, data);
gettimeofday(&t[2], NULL);
get_time_interval(t);
//int r = srslte_pusch_decode(&pusch, slot_symbols[0], ce, 0, data, subframe, &harq_process, rv);
int r = 0;
if (r) {
printf("Error decoding\n");
ret = -1;
goto quit;
} else {
printf("ENCODED OK in %d:%d (TBS: %d bits, TX: %.2f Mbps, Processing: %.2f Mbps)\n", (int) t[0].tv_sec,
printf("DECODED OK in %d:%d (TBS: %d bits, TX: %.2f Mbps, Processing: %.2f Mbps)\n", (int) t[0].tv_sec,
(int) t[0].tv_usec/ntrials,
cfg.grant.mcs.tbs,
(float) cfg.grant.mcs.tbs/1000,
@ -244,7 +248,7 @@ int main(int argc, char **argv) {
ret = 0;
quit:
srslte_pusch_free(&pusch);
srslte_softbuffer_tx_free(&softbuffer);
srslte_softbuffer_tx_free(&softbuffer_tx);
if (sf_symbols) {
free(sf_symbols);
@ -252,6 +256,9 @@ quit:
if (data) {
free(data);
}
if (ce) {
free(ce);
}
if (ret) {
printf("Error\n");
} else {

Loading…
Cancel
Save