Commit 791d449b authored by Huang's avatar Huang

Resampling module for USRP. Not completed. In progress.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5085 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 18e4f19e
# compiles the openair_usrp
#OPENAIRTARGETS_DIR ?=../../../..
#OPENAIROBJS += $(OPENAIRTARGETS_DIR)/ARCH/USRP/USERSPACE/LIB/openair0_lib.o
#CFLAGS += -I$(OPENAIRTARGETS_DIR)/ARCH/USRP/USERSPACE/LIB -I$(OPENAIRTARGETS_DIR)/ARCH/USRP/DEFS
#example: example.o $(OPENAIROBJS)
# gcc -o $@ $(CFLAGS) -lm $(OPENAIROBJS) $<
#openair_usrp.o:
# $(CXX) -c openair_usrp.cpp -o openair_usrp.o
#clean:
# rm -f *.o *~
#a rm -f example
USRP_OBJ += $(OPENAIR_TARGETS)/ARCH/USRP/USERSPACE/LIB/openair_usrp.o
PPS_OBJ += $(OPENAIR_TARGETS)/ARCH/USRP/USERSPACE/LIB/polyphaseResample.o
USRP_FILE_OBJ += $(OPENAIR_TARGETS)/ARCH/USRP/USERSPACE/LIB/openair_usrp.cpp
PPS_FILE_OBJ += $(OPENAIR_TARGETS)/ARCH/USRP/USERSPACE/LIB/polyphaseResample.cpp
USRP_CFLAGS += -I$(OPENAIR_TARGETS)/ARCH/USRP/USERSPACE/LIB/
This diff is collapsed.
This diff is collapsed.
#include <stdarg.h>
#define SAMPLES_PER_FRM 76800
#define SAMPLES_PER_FRM_USRP 62500
#define SAMPLES_PER_SLOT 3840
#define SAMPLES_PER_SLOT_USRP 6250
#define HW_offset 32
#define N_slot_offset 4
#define T_start 3840*20*100
void format_printf(int flag,const char * fmt, ...)
{
if(flag)
{
va_list args;
va_start(args,fmt);
vprintf(fmt,args);
va_end(args);
}
}
This diff is collapsed.
This diff is collapsed.
#include "polyphaseResample.h"
#include <iostream>
#include <stdio.h>
using namespace std;
// table_len should be decied by the length of the filter output
// but a default value of 50000 is adequate for our app
void buildPolyphaseCache(const int P, const int Q, int *&branch_table, int *&offset_table, const int table_len) {
branch_table = new int[table_len];
offset_table = new int[table_len];
for (int i = 0; i < table_len; ++i) {
branch_table[i] = (i * Q) % P;
offset_table[i] = (i * Q - branch_table[i]) / P;
}
}
void polyphaseResample(short *in_data, unsigned int in_sample_count,
short *out_data, unsigned int out_sample_count,
short *filter_coeff, unsigned int filter_len,
const int P, const int Q, const unsigned int fix_shift,
int *branch_table, int *offset_table) {
buildPolyphaseCache( P, Q, branch_table, offset_table, 50000);
// calculate the sample count of output
out_sample_count = (int)(in_sample_count * (float)P / (float)Q);
short *output_ptr = out_data;
unsigned int output_ix = 0;
short const *input_end = in_data + in_sample_count * 2;
short const *output_end = out_data + out_sample_count * 2;
short const *filter_end = filter_coeff + filter_len;
while (output_ptr < output_end)
{
int output_branch = branch_table[output_ix];
int input_offset = offset_table[output_ix];
short *input_ptr = in_data + 2 * input_offset;
short *filter_ptr = filter_coeff + output_branch;
while (input_ptr >= input_end) {
input_ptr -= 2;
filter_ptr += P;
}
int sum_real = 0, sum_imag = 0;
while ((input_ptr >= in_data) && (filter_ptr < filter_end)) {
sum_real += (int)(*input_ptr) * (int)(*filter_ptr);
sum_imag += (int)(*(input_ptr + 1)) * (int)(*filter_ptr);
input_ptr -= 2;
filter_ptr += P;
}
*output_ptr = (short)(sum_real >> fix_shift);
*(output_ptr + 1) = (short)(sum_imag >> fix_shift);
output_ptr += 2;
output_ix++;
}
}
#ifndef _POLYPHASERESAMPLE_H_
#include <cmath>
//#include "coeff_3072_to_25.h"
void buildPolyphaseCache(const int P, const int Q, int *&branch_table, int *&offset_table, const int filter_len = 50000);
/**
* @brief polyphase resampler
* @param in_data input data, layout as [real,imag,real,imag...]
* @param in_sample_count count of input samples, i.e. a complex
* cosisting of two short int counts as one
* @param out_data output data, layout same as in_data
* @param out_sample_count sample count of result, as return
* @param filter_coeff filter with only real coeffcients
* @param filter_len count of coeffcients
* @param P order of upper sampling
* @param Q order of down sampling
**/
void polyphaseResample(short *in_data, unsigned int in_sample_count,
short *out_data, unsigned int out_sample_count,
short *filter_coeff, unsigned int filter_len,
const int P, const int Q, const unsigned int fix_shift,
int *branch_table, int *offset_table);
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment