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.
191 lines
5.4 KiB
C
191 lines
5.4 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 <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
10 years ago
|
#include "srslte/dft/dft.h"
|
||
10 years ago
|
#include "srslte/utils/vector.h"
|
||
|
#include "srslte/utils/convolution.h"
|
||
11 years ago
|
|
||
|
|
||
10 years ago
|
int srslte_conv_fft_cc_init(srslte_conv_fft_cc_t *q, uint32_t input_len, uint32_t filter_len) {
|
||
11 years ago
|
q->input_len = input_len;
|
||
|
q->filter_len = filter_len;
|
||
|
q->output_len = input_len+filter_len;
|
||
10 years ago
|
q->input_fft = srslte_vec_malloc(sizeof(cf_t)*q->output_len);
|
||
|
q->filter_fft = srslte_vec_malloc(sizeof(cf_t)*q->output_len);
|
||
|
q->output_fft = srslte_vec_malloc(sizeof(cf_t)*q->output_len);
|
||
11 years ago
|
if (!q->input_fft || !q->filter_fft || !q->output_fft) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
10 years ago
|
if (srslte_dft_plan(&q->input_plan,q->output_len,SRSLTE_DFT_FORWARD,SRSLTE_DFT_COMPLEX)) {
|
||
10 years ago
|
fprintf(stderr, "Error initiating input plan\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
10 years ago
|
if (srslte_dft_plan(&q->filter_plan,q->output_len,SRSLTE_DFT_FORWARD,SRSLTE_DFT_COMPLEX)) {
|
||
10 years ago
|
fprintf(stderr, "Error initiating filter plan\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
10 years ago
|
if (srslte_dft_plan(&q->output_plan,q->output_len,SRSLTE_DFT_BACKWARD,SRSLTE_DFT_COMPLEX)) {
|
||
10 years ago
|
fprintf(stderr, "Error initiating output plan\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
10 years ago
|
srslte_dft_plan_set_norm(&q->input_plan, true);
|
||
|
srslte_dft_plan_set_norm(&q->filter_plan, true);
|
||
|
srslte_dft_plan_set_norm(&q->output_plan, false);
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
void srslte_conv_fft_cc_free(srslte_conv_fft_cc_t *q) {
|
||
11 years ago
|
if (q->input_fft) {
|
||
|
free(q->input_fft);
|
||
11 years ago
|
}
|
||
11 years ago
|
if (q->filter_fft) {
|
||
|
free(q->filter_fft);
|
||
11 years ago
|
}
|
||
11 years ago
|
if (q->output_fft) {
|
||
|
free(q->output_fft);
|
||
11 years ago
|
}
|
||
10 years ago
|
srslte_dft_plan_free(&q->input_plan);
|
||
|
srslte_dft_plan_free(&q->filter_plan);
|
||
|
srslte_dft_plan_free(&q->output_plan);
|
||
10 years ago
|
|
||
10 years ago
|
bzero(q, sizeof(srslte_conv_fft_cc_t));
|
||
10 years ago
|
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
uint32_t srslte_conv_fft_cc_run(srslte_conv_fft_cc_t *q, cf_t *input, cf_t *filter, cf_t *output) {
|
||
11 years ago
|
|
||
10 years ago
|
srslte_dft_run_c(&q->input_plan, input, q->input_fft);
|
||
|
srslte_dft_run_c(&q->filter_plan, filter, q->filter_fft);
|
||
11 years ago
|
|
||
10 years ago
|
srslte_vec_prod_ccc(q->input_fft,q->filter_fft,q->output_fft,q->output_len);
|
||
11 years ago
|
|
||
10 years ago
|
srslte_dft_run_c(&q->output_plan, q->output_fft, output);
|
||
11 years ago
|
|
||
11 years ago
|
return q->output_len-1;
|
||
11 years ago
|
|
||
|
}
|
||
|
|
||
10 years ago
|
uint32_t srslte_conv_cc(cf_t *input, cf_t *filter, cf_t *output, uint32_t input_len, uint32_t filter_len) {
|
||
10 years ago
|
uint32_t i;
|
||
|
uint32_t M = filter_len;
|
||
|
uint32_t N = input_len;
|
||
|
|
||
|
for (i=0;i<M;i++) {
|
||
10 years ago
|
output[i]=srslte_vec_dot_prod_ccc(&input[i],&filter[i],i);
|
||
10 years ago
|
}
|
||
|
for (;i<M+N-1;i++) {
|
||
10 years ago
|
output[i] = srslte_vec_dot_prod_ccc(&input[i-M], filter, M);
|
||
11 years ago
|
}
|
||
10 years ago
|
return M+N-1;
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
|
/* Centered convolution. Returns the same number of input elements. Equivalent to conv(x,h,'same') in matlab.
|
||
|
* y(n)=sum_i x(n+i-M/2)*h(i) for n=1..N with N input samples and M filter len
|
||
|
*/
|
||
10 years ago
|
uint32_t srslte_conv_same_cc(cf_t *input, cf_t *filter, cf_t *output, uint32_t input_len, uint32_t filter_len) {
|
||
10 years ago
|
uint32_t i;
|
||
|
uint32_t M = filter_len;
|
||
|
uint32_t N = input_len;
|
||
|
|
||
|
for (i=0;i<M/2;i++) {
|
||
10 years ago
|
output[i]=srslte_vec_dot_prod_ccc(&input[i],&filter[M/2-i],M-M/2+i);
|
||
10 years ago
|
}
|
||
|
for (;i<N-M/2;i++) {
|
||
10 years ago
|
output[i]=srslte_vec_dot_prod_ccc(&input[i-M/2],filter,M);
|
||
10 years ago
|
}
|
||
|
for (;i<N;i++) {
|
||
10 years ago
|
output[i]=srslte_vec_dot_prod_ccc(&input[i-M/2],filter,N-i+M/2);
|
||
10 years ago
|
}
|
||
|
return N;
|
||
|
}
|
||
|
|
||
10 years ago
|
|
||
|
#define conv_same_extrapolates_extremes
|
||
|
|
||
|
#ifdef conv_same_extrapolates_extremes
|
||
|
uint32_t srslte_conv_same_cf(cf_t *input, float *filter, cf_t *output,
|
||
|
uint32_t input_len, uint32_t filter_len) {
|
||
|
uint32_t i;
|
||
|
uint32_t M = filter_len;
|
||
|
uint32_t N = input_len;
|
||
|
cf_t first[filter_len+filter_len/2];
|
||
|
cf_t last[filter_len+filter_len/2];
|
||
|
|
||
|
for (i=0;i<M+M/2;i++) {
|
||
|
if (i<M/2) {
|
||
|
first[i] = (2+M/2-i)*input[1]-(1+M/2-i)*input[0];
|
||
|
} else {
|
||
|
first[i] = input[i-M/2];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (i=0;i<M+M/2;i++) {
|
||
|
if (i>=M-1) {
|
||
|
last[i] = (2+i-M/2)*input[N-1]-(1+i-M/2)*input[N-2];
|
||
|
} else {
|
||
|
last[i] = input[N-M+i+1];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (i=0;i<M/2;i++) {
|
||
|
output[i]=srslte_vec_dot_prod_cfc(&first[i],filter,M);
|
||
|
}
|
||
|
|
||
|
for (;i<N-M/2;i++) {
|
||
|
output[i]=srslte_vec_dot_prod_cfc(&input[i-M/2],filter,M);
|
||
|
}
|
||
|
int j=0;
|
||
|
for (;i<N;i++) {
|
||
|
output[i]=srslte_vec_dot_prod_cfc(&last[j++],filter,M);
|
||
|
}
|
||
|
return N;
|
||
|
}
|
||
|
#else
|
||
|
|
||
10 years ago
|
uint32_t srslte_conv_same_cf(cf_t *input, float *filter, cf_t *output,
|
||
10 years ago
|
uint32_t input_len, uint32_t filter_len) {
|
||
|
uint32_t i;
|
||
|
uint32_t M = filter_len;
|
||
|
uint32_t N = input_len;
|
||
|
|
||
|
for (i=0;i<M/2;i++) {
|
||
10 years ago
|
output[i]=srslte_vec_dot_prod_cfc(&input[i],&filter[M/2-i],M-M/2+i);
|
||
10 years ago
|
}
|
||
|
for (;i<N-M/2;i++) {
|
||
10 years ago
|
output[i]=srslte_vec_dot_prod_cfc(&input[i-M/2],filter,M);
|
||
10 years ago
|
}
|
||
|
for (;i<N;i++) {
|
||
10 years ago
|
output[i]=srslte_vec_dot_prod_cfc(&input[i-M/2],filter,N-i+M/2);
|
||
10 years ago
|
}
|
||
|
return N;
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
#endif
|