mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
226 lines
6.1 KiB
C
226 lines
6.1 KiB
C
11 years ago
|
/**
|
||
11 years ago
|
*
|
||
11 years ago
|
* \section COPYRIGHT
|
||
11 years ago
|
*
|
||
9 years ago
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||
11 years ago
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
10 years ago
|
* This file is part of the srsLTE library.
|
||
11 years ago
|
*
|
||
10 years ago
|
* srsLTE is free software: you can redistribute it and/or modify
|
||
10 years ago
|
* it under the terms of the GNU Affero General Public License as
|
||
11 years ago
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
10 years ago
|
* srsLTE is distributed in the hope that it will be useful,
|
||
11 years ago
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
10 years ago
|
* GNU Affero General Public License for more details.
|
||
11 years ago
|
*
|
||
10 years ago
|
* A copy of the GNU Affero General Public License can be found in
|
||
11 years ago
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
11 years ago
|
*/
|
||
11 years ago
|
|
||
11 years ago
|
#include <complex.h>
|
||
|
#include <math.h>
|
||
11 years ago
|
#include <stdlib.h>
|
||
10 years ago
|
#include <strings.h>
|
||
11 years ago
|
|
||
10 years ago
|
#include "srslte/resampling/interp.h"
|
||
|
#include "srslte/utils/vector.h"
|
||
|
#include "srslte/utils/debug.h"
|
||
11 years ago
|
|
||
10 years ago
|
/*************** STATIC FUNCTIONS ***********************/
|
||
11 years ago
|
|
||
10 years ago
|
cf_t srslte_interp_linear_onesample(cf_t input0, cf_t input1) {
|
||
10 years ago
|
return 2*input1-input0;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
cf_t srslte_interp_linear_onesample_cabs(cf_t input0, cf_t input1) {
|
||
10 years ago
|
float re0=0, im0=0, re1=0, im1=0, re=0, im=0;
|
||
10 years ago
|
re0 = crealf(input0);
|
||
|
im0 = cimagf(input1);
|
||
|
re1 = crealf(input0);
|
||
|
im1 = cimagf(input1);
|
||
10 years ago
|
re = 2*re1-re0;
|
||
|
im = 2*im1-im0;
|
||
|
return (re+im*_Complex_I);
|
||
|
}
|
||
|
|
||
10 years ago
|
|
||
|
/* Performs 1st order integer linear interpolation */
|
||
10 years ago
|
void srslte_interp_linear_f(float *input, float *output, uint32_t M, uint32_t len) {
|
||
10 years ago
|
uint32_t i, j;
|
||
|
for (i=0;i<len-1;i++) {
|
||
|
for (j=0;j<M;j++) {
|
||
|
output[i*M+j] = input[i] + j * (input[i+1]-input[i]) / M;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
11 years ago
|
/* Performs 1st order linear interpolation with out-of-bound interpolation */
|
||
10 years ago
|
void srslte_interp_linear_offset_cabs(cf_t *input, cf_t *output,
|
||
10 years ago
|
uint32_t M, uint32_t len,
|
||
|
uint32_t off_st, uint32_t off_end)
|
||
|
{
|
||
11 years ago
|
uint32_t i, j;
|
||
11 years ago
|
float mag0=0, mag1=0, arg0=0, arg1=0, mag=0, arg=0;
|
||
11 years ago
|
|
||
11 years ago
|
for (i=0;i<len-1;i++) {
|
||
|
mag0 = cabsf(input[i]);
|
||
|
mag1 = cabsf(input[i+1]);
|
||
|
arg0 = cargf(input[i]);
|
||
|
arg1 = cargf(input[i+1]);
|
||
|
if (i==0) {
|
||
|
for (j=0;j<off_st;j++) {
|
||
|
mag = mag0 - (j+1)*(mag1-mag0)/M;
|
||
|
arg = arg0 - (j+1)*(arg1-arg0)/M;
|
||
|
output[j] = mag * cexpf(I * arg);
|
||
|
}
|
||
|
}
|
||
|
for (j=0;j<M;j++) {
|
||
|
mag = mag0 + j*(mag1-mag0)/M;
|
||
|
arg = arg0 + j*(arg1-arg0)/M;
|
||
|
output[i*M+j+off_st] = mag * cexpf(I * arg);
|
||
|
}
|
||
|
}
|
||
|
if (len > 1) {
|
||
|
for (j=0;j<off_end;j++) {
|
||
|
mag = mag1 + j*(mag1-mag0)/M;
|
||
|
arg = arg1 + j*(arg1-arg0)/M;
|
||
|
output[i*M+j+off_st] = mag * cexpf(I * arg);
|
||
|
}
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
int srslte_interp_linear_vector_init(srslte_interp_linsrslte_vec_t *q, uint32_t vector_len)
|
||
10 years ago
|
{
|
||
10 years ago
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
if (q) {
|
||
10 years ago
|
bzero(q, sizeof(srslte_interp_linsrslte_vec_t));
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
10 years ago
|
q->diff_vec = srslte_vec_malloc(vector_len * sizeof(cf_t));
|
||
10 years ago
|
if (!q->diff_vec) {
|
||
|
perror("malloc");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
|
q->vector_len = vector_len;
|
||
|
}
|
||
|
return ret;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
10 years ago
|
void srslte_interp_linear_vector_free(srslte_interp_linsrslte_vec_t *q) {
|
||
10 years ago
|
if (q->diff_vec) {
|
||
|
free(q->diff_vec);
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
bzero(q, sizeof(srslte_interp_linsrslte_vec_t));
|
||
10 years ago
|
|
||
10 years ago
|
}
|
||
11 years ago
|
|
||
10 years ago
|
void srslte_interp_linear_vector(srslte_interp_linsrslte_vec_t *q, cf_t *in0, cf_t *in1, cf_t *between, uint32_t M)
|
||
9 years ago
|
{
|
||
|
srslte_interp_linear_vector2(q, in0, in1, NULL, between, M);
|
||
|
}
|
||
|
|
||
|
void srslte_interp_linear_vector2(srslte_interp_linsrslte_vec_t *q, cf_t *in0, cf_t *in1, cf_t *start, cf_t *between, uint32_t M)
|
||
10 years ago
|
{
|
||
|
uint32_t i;
|
||
|
|
||
10 years ago
|
srslte_vec_sub_ccc(in1, in0, q->diff_vec, q->vector_len);
|
||
9 years ago
|
srslte_vec_sc_prod_cfc(q->diff_vec, (float) 1/(M+1), q->diff_vec, q->vector_len);
|
||
|
if (start) {
|
||
|
srslte_vec_sum_ccc(start, q->diff_vec, between, q->vector_len);
|
||
|
} else {
|
||
|
srslte_vec_sum_ccc(in0, q->diff_vec, between, q->vector_len);
|
||
|
}
|
||
10 years ago
|
for (i=0;i<M-1;i++) {
|
||
10 years ago
|
srslte_vec_sum_ccc(between, q->diff_vec, &between[q->vector_len], q->vector_len);
|
||
10 years ago
|
between += q->vector_len;
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
int srslte_interp_linear_init(srslte_interp_lin_t *q, uint32_t vector_len, uint32_t M)
|
||
10 years ago
|
{
|
||
10 years ago
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
if (q) {
|
||
10 years ago
|
bzero(q, sizeof(srslte_interp_lin_t));
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
10 years ago
|
q->diff_vec = srslte_vec_malloc(vector_len * sizeof(cf_t));
|
||
10 years ago
|
if (!q->diff_vec) {
|
||
|
perror("malloc");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
10 years ago
|
q->diff_vec2 = srslte_vec_malloc(M * vector_len * sizeof(cf_t));
|
||
10 years ago
|
if (!q->diff_vec2) {
|
||
|
perror("malloc");
|
||
|
free(q->diff_vec);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
10 years ago
|
q->ramp = srslte_vec_malloc(M * sizeof(float));
|
||
10 years ago
|
if (!q->ramp) {
|
||
|
perror("malloc");
|
||
|
free(q->ramp);
|
||
|
free(q->diff_vec);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
|
|
||
|
for (int i=0;i<M;i++) {
|
||
|
q->ramp[i] = (float) i;
|
||
|
}
|
||
|
|
||
|
q->vector_len = vector_len;
|
||
|
q->M = M;
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
10 years ago
|
void srslte_interp_linear_free(srslte_interp_lin_t *q) {
|
||
10 years ago
|
if (q->diff_vec) {
|
||
|
free(q->diff_vec);
|
||
|
}
|
||
10 years ago
|
if (q->diff_vec2) {
|
||
|
free(q->diff_vec2);
|
||
|
}
|
||
|
if (q->ramp) {
|
||
|
free(q->ramp);
|
||
|
}
|
||
|
|
||
10 years ago
|
bzero(q, sizeof(srslte_interp_lin_t));
|
||
10 years ago
|
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void srslte_interp_linear_offset(srslte_interp_lin_t *q, cf_t *input, cf_t *output,
|
||
10 years ago
|
uint32_t off_st, uint32_t off_end)
|
||
|
{
|
||
11 years ago
|
uint32_t i, j;
|
||
10 years ago
|
cf_t diff;
|
||
|
|
||
|
i=0;
|
||
|
for (j=0;j<off_st;j++) {
|
||
9 years ago
|
output[off_st-j-1] = input[i] - (j+1) * (input[i+1]-input[i]) / q->M;
|
||
10 years ago
|
}
|
||
10 years ago
|
srslte_vec_sub_ccc(&input[1], input, q->diff_vec, (q->vector_len-1));
|
||
|
srslte_vec_sc_prod_cfc(q->diff_vec, (float) 1/q->M, q->diff_vec, q->vector_len-1);
|
||
10 years ago
|
for (i=0;i<q->vector_len-1;i++) {
|
||
|
for (j=0;j<q->M;j++) {
|
||
|
output[i*q->M+j+off_st] = input[i];
|
||
|
q->diff_vec2[i*q->M+j] = q->diff_vec[i];
|
||
|
}
|
||
10 years ago
|
srslte_vec_prod_cfc(&q->diff_vec2[i*q->M],q->ramp,&q->diff_vec2[i*q->M],q->M);
|
||
10 years ago
|
}
|
||
10 years ago
|
srslte_vec_sum_ccc(&output[off_st], q->diff_vec2, &output[off_st], q->M*(q->vector_len-1));
|
||
10 years ago
|
|
||
|
if (q->vector_len > 1) {
|
||
|
diff = input[q->vector_len-1]-input[q->vector_len-2];
|
||
|
for (j=0;j<off_end;j++) {
|
||
|
output[i*q->M+j+off_st] = input[i] + j * diff / q->M;
|
||
11 years ago
|
}
|
||
|
}
|
||
11 years ago
|
}
|
||
10 years ago
|
|