1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include <vector>
#include <iostream>
#include <boost/circular_buffer.hpp>
void wci_nyq_filt_boost ( int32_t i_symb, // I symbol input
int32_t q_symb, // Q symbol input
int32_t *nyq_coeffs, // Nyquist coefficients for I and Q
//int32_t coeff_len, // Coefficient length
boost::circular_buffer<int32_t> &nyq_delay_i, // I delay line storage
boost::circular_buffer<int32_t> &nyq_delay_q, // Q delay line storage
int32_t *nyq_iout, // I output from Nyquist filter
int32_t *nyq_qout) // Q output from Nyquist filter
{
int32_t sumI, sumQ;
boost::circular_buffer<int32_t>::iterator iter;
*nyq_iout = 0 ;
*nyq_qout = 0 ;
sumI = sumQ = 0;
int32_t
*arr_i = nyq_delay_i.array_one().first,
*arr_q = nyq_delay_q.array_one().first;
size_t size = nyq_delay_i.array_one().second;
//Compute the next filter output
size_t K;
for (K=0 ; K < size ; K++ ) {
sumI += arr_i[K] * nyq_coeffs[K];
sumQ += arr_q[K] * nyq_coeffs[K];
}
arr_i = nyq_delay_i.array_two().first;
arr_q = nyq_delay_q.array_two().first;
size = nyq_delay_i.array_two().second;
for (size_t L=0; L < size; L++,K++ ) {
sumI += arr_i[L] * nyq_coeffs[K];
sumQ += arr_q[L] * nyq_coeffs[K];
}
*nyq_iout = sumI;
*nyq_qout = sumQ;
nyq_delay_i.push_front(i_symb);
nyq_delay_q.push_front(q_symb);
}
//the other functions
int main(int argc, char **argv){
if(argc<2) return 1;
enum algorithm{vector, circ_buffer, foo}; //to avoid recompilation
algorithm choice;
if( std::string(argv[1]) == "vector" ) choice=vector;
else if( std::string(argv[1]) == "circ_buffer" ) choice=circ_buffer;
else choice=foo;
std::srand(42); //the same random data, always
const size_t COEFF_LEN = 256*8;
std::vector<int32_t> vec_delay_i(COEFF_LEN,0), vec_delay_q(COEFF_LEN,0);
boost::circular_buffer<int32_t> bcb_delay_i(COEFF_LEN, COEFF_LEN, 0), bcb_delay_q(COEFF_LEN, COEFF_LEN, 0);
int32_t nyq_coeffs[COEFF_LEN], nyq_out_i, nyq_out_q;
for(size_t K=0; K<COEFF_LEN; ++K) //random initialization
nyq_coeffs[K] = rand()%100;
for(size_t K=0; K<1<<20; ++K){
int32_t i_symb = rand()%1000, q_symb = rand()%1000; //random generation
switch(choice){
case vector:
wci_nyq_filt_vector(i_symb, q_symb,
nyq_coeffs, COEFF_LEN,
vec_delay_i, vec_delay_q,
&nyq_out_i, &nyq_out_q);
break;
case circ_buffer:
wci_nyq_filt_boost(i_symb, q_symb,
nyq_coeffs, //COEFF_LEN,
bcb_delay_i, bcb_delay_q,
&nyq_out_i, &nyq_out_q);
break;
default:
baz(i_symb, q_symb,
nyq_coeffs,
vec_delay_i, vec_delay_q,
&nyq_out_i, &nyq_out_q);
}
}
std::cout << "Results " << nyq_out_i << ' ' << nyq_out_q << '\n';
return 0;
}
|