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.
99 lines
3.0 KiB
C
99 lines
3.0 KiB
C
11 years ago
|
/**
|
||
11 years ago
|
*
|
||
11 years ago
|
* \section COPYRIGHT
|
||
11 years ago
|
*
|
||
11 years ago
|
* Copyright 2013-2014 The libLTE Developers. See the
|
||
|
* COPYRIGHT file at the top-level directory of this distribution.
|
||
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
|
* This file is part of the libLTE library.
|
||
|
*
|
||
|
* libLTE is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Lesser General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
|
* libLTE 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
|
||
|
* GNU Lesser General Public License for more details.
|
||
|
*
|
||
11 years ago
|
* A copy of the GNU Lesser 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/.
|
||
|
*
|
||
11 years ago
|
*/
|
||
|
|
||
11 years ago
|
|
||
11 years ago
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
11 years ago
|
#include "liblte/phy/utils/dft.h"
|
||
|
#include "liblte/phy/utils/vector.h"
|
||
|
#include "liblte/phy/utils/convolution.h"
|
||
11 years ago
|
|
||
|
|
||
|
int conv_fft_cc_init(conv_fft_cc_t *state, int input_len, int filter_len) {
|
||
11 years ago
|
state->input_len = input_len;
|
||
|
state->filter_len = filter_len;
|
||
|
state->output_len = input_len+filter_len-1;
|
||
|
state->input_fft = vec_malloc(sizeof(_Complex float)*state->output_len);
|
||
|
state->filter_fft = vec_malloc(sizeof(_Complex float)*state->output_len);
|
||
|
state->output_fft = vec_malloc(sizeof(_Complex float)*state->output_len);
|
||
|
if (!state->input_fft || !state->filter_fft || !state->output_fft) {
|
||
|
return -1;
|
||
|
}
|
||
11 years ago
|
if (dft_plan(&state->input_plan,state->output_len,COMPLEX_2_COMPLEX,FORWARD)) {
|
||
11 years ago
|
return -2;
|
||
|
}
|
||
11 years ago
|
if (dft_plan(&state->filter_plan,state->output_len,COMPLEX_2_COMPLEX,FORWARD)) {
|
||
11 years ago
|
return -3;
|
||
|
}
|
||
11 years ago
|
if (dft_plan(&state->output_plan,state->output_len,COMPLEX_2_COMPLEX,BACKWARD)) {
|
||
11 years ago
|
return -4;
|
||
|
}
|
||
|
return 0;
|
||
11 years ago
|
}
|
||
|
|
||
|
void conv_fft_cc_free(conv_fft_cc_t *state) {
|
||
11 years ago
|
if (state->input_fft) {
|
||
|
free(state->input_fft);
|
||
|
}
|
||
|
if (state->filter_fft) {
|
||
|
free(state->filter_fft);
|
||
|
}
|
||
|
if (state->output_fft) {
|
||
|
free(state->output_fft);
|
||
|
}
|
||
|
dft_plan_free(&state->input_plan);
|
||
|
dft_plan_free(&state->filter_plan);
|
||
|
dft_plan_free(&state->output_plan);
|
||
11 years ago
|
}
|
||
|
|
||
|
int conv_fft_cc_run(conv_fft_cc_t *state, _Complex float *input, _Complex float *filter, _Complex float *output) {
|
||
|
|
||
11 years ago
|
dft_run_c2c(&state->input_plan, input, state->input_fft);
|
||
|
dft_run_c2c(&state->filter_plan, filter, state->filter_fft);
|
||
11 years ago
|
|
||
11 years ago
|
vec_prod_ccc(state->input_fft,state->filter_fft,state->output_fft,state->output_len);
|
||
11 years ago
|
|
||
11 years ago
|
dft_run_c2c(&state->output_plan, state->output_fft, output);
|
||
11 years ago
|
|
||
11 years ago
|
return state->output_len;
|
||
11 years ago
|
|
||
|
}
|
||
|
|
||
|
int conv_cc(_Complex float *input, _Complex float *filter, _Complex float *output, int input_len, int filter_len) {
|
||
11 years ago
|
int i,j;
|
||
|
int output_len;
|
||
|
output_len=input_len+filter_len-1;
|
||
|
memset(output,0,output_len*sizeof(_Complex float));
|
||
|
for (i=0;i<input_len;i++) {
|
||
|
for (j=0;j<filter_len;j++) {
|
||
|
output[i+j]+=input[i]*filter[j];
|
||
|
}
|
||
|
}
|
||
|
return output_len;
|
||
11 years ago
|
}
|