[srslte-users] Resampling on N210
Justin Tallon
justin.tallon at softwareradiosystems.com
Thu May 16 09:47:21 UTC 2019
Hey Frederico,
There has been some work done on integrating the fractional resampling
functions with the UHD code but it is with an older version of the code.
It is available in a repo, can be found at this link.
https://github.com/yagoda/srsLTE_Wishful/blob/master/lib/src/phy/rf/rf_uhd_imp.c
Hope this can provide some help.
Regards,
Justin
On Tue, 14 May 2019, 20:02 Federico Quattrin, <fede.quattrin at gmail.com>
wrote:
> Hi srsLTE community,
>
> I'm trying to write a piece of code in order to make a resample for the
> N210. Until now I read the source code and found that this piece of code
> must be written in the file rf_uhd_impl.c so i did that, most specifically
> I wrote it in the function rf_uhd_recv_with_time_multi. What i thought
> was: The N210 has a resampling frequency of 100 Msps, but srsLTE works with
> different frequency, so i need to get all the samples from UHD, save them
> into a array or buffer, and then do a resample of these data with the
> srsLTE resampling functions and send these new array of data as the final
> array of data.
> To achieve this I modified the code of the function
> rf_uhd_recv_with_time_multi as it follow:
>
> int rf_uhd_recv_with_time_multi(void *h,
> void *data[SRSLTE_MAX_PORTS],
> uint32_t nsamples,
> bool blocking,
> time_t *secs,
> double *frac_secs)
> {
> rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
> uhd_rx_metadata_handle *md = &handler->rx_md_first;
> size_t rxd_samples = 0;
> size_t rxd_samples_total_new = 0;
>
> float sratio = 192.0 * 3.0 / (625.0 * 4.0); //added for resampling
> (1/sratio = 4.340277778) The idea is to resample from 100 Msps to 23.04
> Msps.
>
>
> // we need to convert all the vector to a new size in order to get all
> the samples.
>
> nsamples = nsamples / sratio; //added for resampling. We should receive
> more sampling due to different sample rate and same time.
>
> size_t rxd_samples_total = 0;
> int trials = 0;
>
> if (blocking) {
> while (rxd_samples_total < nsamples && trials < 100) {
> void *buffs_ptr[4];
> void *buff_new[4] ;
> cf_t * puntero;
> puntero = &data_c[rxd_samples_total]; // Here I try to imitate the
> behavior of buffs_ptr
> for (int i=0;i<handler->nof_rx_channels;i++) {
> cf_t *data_c = (cf_t*) data[i];
> buffs_ptr[i] = &data_c[rxd_samples_total];
> buff_new[i] = malloc(nsamples) ; //these is the pointer where i
> would keep all the samples coming from UHD.
> }
>
> size_t num_samps_left = nsamples - rxd_samples_total;
> size_t num_rx_samples = (num_samps_left > (handler->rx_nof_samples /
> sratio)) ? (handler->rx_nof_samples / sratio) : num_samps_left;
> // /sratio added for resampling.
>
> rxd_samples = 0;
>
> /*So these is the function that, as i understood, receive the
> samples from UHD. Originally said buffs_ptr instead of buff_new, but
> because I don't want to write the data with the samples that comes from UHD
> I give her buff_new.*/
> uhd_error error = uhd_rx_streamer_recv(handler->rx_stream,
> /*buffs_ptr*/ buff_new,
> num_rx_samples, md, 1.0,
> false, &rxd_samples);
>
> //Implementation of the resampling
> srslte_resample_arb_t r;
> srslte_resample_arb_init(&r,sratio,0);
> size_t new_rxd_sample[SRSLTE_MAX_PORTS];
> for(int i = 0 ; i < handler->nof_rx_channels ; i++){
> new_rxd_sample[i] = srslte_resample_arb_compute(&r,(cf_t*)
> buff_new[i], puntero, rxd_samples); //function returns new length.
> }
>
> for(int i = 0; i < handler->nof_rx_channels ; i++){
> free(buff_new[i]); //we need to free the memory because we did a
> malloc.
> }
>
>
>
> if (error) {
> fprintf(stderr, "Error receiving from UHD: %d\n", error);
> log_rx_error(handler);
> return -1;
> }
> uhd_rx_metadata_error_code_t error_code = 0;
> uhd_rx_metadata_error_code(*md, &error_code);
>
> md = &handler->rx_md;
> rxd_samples_total_new += new_rxd_sample[0];
> rxd_samples_total += rxd_samples;
> printf("\n----------------------------------------\nrxd samples
> total new= %ld\nrxd samples total normal %ld\nrxd samples normal %ld\nrxd
> samples new
> %ld\n-----------------------------------------------\n",rxd_samples_total_new,rxd_samples_total,rxd_samples,new_rxd_sample[0]);
> // I add these printf because I wanted to see the values of these variables.
> trials++;
>
> if (error_code == UHD_RX_METADATA_ERROR_CODE_OVERFLOW) {
> log_overflow(handler);
> } else if (error_code == UHD_RX_METADATA_ERROR_CODE_LATE_COMMAND) {
> log_late(handler, true);
> } else if (error_code == UHD_RX_METADATA_ERROR_CODE_TIMEOUT) {
> fprintf(stderr, "Error timed out while receiving samples from
> UHD.\n");
> return -1;
> } else if (error_code != UHD_RX_METADATA_ERROR_CODE_NONE ) {
> fprintf(stderr, "Error code 0x%x was returned during streaming.
> Aborting.\n", error_code);
> }
> }
> } else {
> uhd_error error = uhd_rx_streamer_recv(handler->rx_stream, data,
> nsamples, md, 0.0, false, &rxd_samples);
> rxd_samples_total = rxd_samples;
> printf("NO entramos al IF\n");
>
> if (error) {
> fprintf(stderr, "Error receiving from UHD: %d\n", error);
> log_rx_error(handler);
> return -1;
> }
> }
> if (secs && frac_secs) {
>
> uhd_rx_metadata_time_spec(handler->rx_md_first, secs, frac_secs);
> }
> printf("\n\nOUT OF THE FUNCTION\n\n");
> return rxd_samples_total_new; //I return the new length, I mean the
> length the the resampled data will have, not the length of the data I
> received from UHD.
> }
>
>
>
>
>
> So after I run the code, that is what I receive:
>
> # srsenb
>
> Built in Release mode using 18.12.0.
>
> --- Software Radio Systems LTE eNodeB ---
>
> Reading configuration file /root/.config/srslte/enb.conf...
> [INFO] [UHD] linux; GNU C++ version 8.3.0; Boost_106700;
> UHD_3.14.0.HEAD-0-g6875d061
> Opening USRP with args:
> [INFO] [USRP2] Opening a USRP2/N-Series device...
> [INFO] [USRP2] Current recv frame size: 1472 bytes
> [INFO] [USRP2] Current send frame size: 1472 bytes
> [WARNING] [MULTI_USRP] The hardware does not support the requested RX
> sample rate:
> Target sample rate: 1.920000 MSps
> Actual sample rate: 1.923077 MSps
>
> [WARNING] [MULTI_USRP] The hardware does not support the requested TX
> sample rate:
> Target sample rate: 1.920000 MSps
> Actual sample rate: 1.923077 MSps
>
> Setting frequency: DL=2685.0 Mhz, UL=2565.0 MHz
> Setting Sampling frequency 23.04 MHz
> Setting manual TX/RX offset to 100 samples
>
> ==== eNodeB started ===
> Type <t> to view trace
> S1 Setup Failure. Cause: misc - unknown-PLMN
>
> ----------------------------------------
> rxd samples total new= 84
> rxd samples total normal 363
> rxd samples normal 363
> rxd samples new 84
> -----------------------------------------------
>
> ----------------------------------------
> rxd samples total new= 168
> rxd samples total normal 726
> rxd samples normal 363
> rxd samples new 84
> -----------------------------------------------
>
> ----------------------------------------
> rxd samples total new= 172
> rxd samples total normal 742
> rxd samples normal 16
> rxd samples new 4
> -----------------------------------------------
>
> ----------------------------------------
> rxd samples total new= 172
> rxd samples total normal 742
> rxd samples normal 0
> rxd samples new 0
> -----------------------------------------------
> O
> ----------------------------------------
> rxd samples total new= 172
> rxd samples total normal 742
> rxd samples normal 0
> rxd samples new 0
> -----------------------------------------------
> Error timed out while receiving samples from UHD.
>
> LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
> ----------------------------------------
> rxd samples total new= 0
> rxd samples total normal 0
> rxd samples normal 0
> rxd samples new 0
> -----------------------------------------------
> Error timed out while receiving samples from UHD.
> LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
> ----------------------------------------
> rxd samples total new= 0
> rxd samples total normal 0
> rxd samples normal 0
> rxd samples new 0
> -----------------------------------------------
> Error timed out while receiving samples from UHD.
> LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
> ----------------------------------------
> rxd samples total new= 0
> rxd samples total normal 0
> rxd samples normal 0
> rxd samples new 0
> -----------------------------------------------
> Error timed out while receiving samples from UHD.
> LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
> ----------------------------------------
> rxd samples total new= 0
> rxd samples total normal 0
> rxd samples normal 0
> rxd samples new 0
> -----------------------------------------------
> Error timed out while receiving samples from UHD.
> LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
> ----------------------------------------
> rxd samples total new= 0
> rxd samples total normal 0
> rxd samples normal 0
> rxd samples new 0
> -----------------------------------------------
> Error timed out while receiving samples from UHD.
> LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
> ----------------------------------------
> rxd samples total new= 0
> rxd samples total normal 0
> rxd samples normal 0
> rxd samples new 0
> -----------------------------------------------
> Error timed out while receiving samples from UHD.
> LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL^CStopping
> srsENB... Press Ctrl+C 9 more times to force stop
>
> ----------------------------------------
> rxd samples total new= 0
> rxd samples total normal 0
> rxd samples normal 0
> rxd samples new 0
> -----------------------------------------------
> Error timed out while receiving samples from UHD.
> LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
> ----------------------------------------
> rxd samples total new= 0
> rxd samples total normal 0
> rxd samples normal 0
> rxd samples new 0
> -----------------------------------------------
> Error timed out while receiving samples from UHD.
> LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL---
> exiting ---
>
>
> One thing that I noticed is that the UHD always receive 742 samples and
> then do not receive a simple sample more.
> I don't know if i need to edit somewhere else in the code, but these of
> the 742 samples looks like that doesn't belong to the resampling problem.
>
> I would be really grateful if any of you guys could give some help
>
> Thanks in advance
> Greeting!
> Federico
>
> _______________________________________________
> srslte-users mailing list
> srslte-users at lists.softwareradiosystems.com
> http://www.softwareradiosystems.com/mailman/listinfo/srslte-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.srsran.com/pipermail/srsran-users/attachments/20190516/ee96ca3a/attachment.htm>
More information about the srsran-users
mailing list