Commit 17137877 authored by frtabu's avatar frtabu

add tools to compare oai/kiss dfts

parent 7c628ca6
...@@ -1417,7 +1417,7 @@ add_library(coding MODULE ${PHY_TURBOSRC} ) ...@@ -1417,7 +1417,7 @@ add_library(coding MODULE ${PHY_TURBOSRC} )
add_library(dfts MODULE ${OPENAIR1_DIR}/PHY/TOOLS/oai_dfts.c ) add_library(dfts MODULE ${OPENAIR1_DIR}/PHY/TOOLS/oai_dfts.c )
set(KISSFFT_DIR ${OPENAIR_DIR}/kiss_fft130) set(KISSFFT_DIR ${OPENAIR_DIR}/kiss_fft130)
add_library(dfts_fpkiss MODULE ${OPENAIR1_DIR}/PHY/TOOLS/oai_kissdfts.c ${KISSFFT_DIR}/kiss_fft.c) add_library(dfts_fpkiss MODULE ${OPENAIR1_DIR}/PHY/TOOLS/oai_kissdfts.c ${OPENAIR1_DIR}/PHY/TOOLS/oai_dfts_tmp.c ${KISSFFT_DIR}/kiss_fft.c)
target_compile_definitions(dfts_fpkiss PUBLIC -DFIXED_POINT=16 ) target_compile_definitions(dfts_fpkiss PUBLIC -DFIXED_POINT=16 )
target_compile_options(dfts_fpkiss PUBLIC -O3 -mtune=native -ffast-math -fomit-frame-pointer -dA -fverbose-asm ) target_compile_options(dfts_fpkiss PUBLIC -O3 -mtune=native -ffast-math -fomit-frame-pointer -dA -fverbose-asm )
add_library(dfts_flkiss MODULE ${OPENAIR1_DIR}/PHY/TOOLS/oai_kissdfts.c ${KISSFFT_DIR}/kiss_fft.c) add_library(dfts_flkiss MODULE ${OPENAIR1_DIR}/PHY/TOOLS/oai_kissdfts.c ${KISSFFT_DIR}/kiss_fft.c)
......
...@@ -9650,7 +9650,6 @@ int dfts_autoinit(void) ...@@ -9650,7 +9650,6 @@ int dfts_autoinit(void)
} }
#ifndef MR_MAIN #ifndef MR_MAIN
void dft(uint8_t sizeidx, int16_t *sigF,int16_t *sig,unsigned char scale_flag){ void dft(uint8_t sizeidx, int16_t *sigF,int16_t *sig,unsigned char scale_flag){
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <stdint.h> #include <stdint.h>
#include <math.h> #include <math.h>
#include <execinfo.h> #include <execinfo.h>
#include <limits.h>
#define OAIDFTS_LIB #define OAIDFTS_LIB
#include "PHY/defs_common.h" #include "PHY/defs_common.h"
#include "PHY/impl_defs_top.h" #include "PHY/impl_defs_top.h"
...@@ -59,49 +60,92 @@ int dfts_autoinit(void) ...@@ -59,49 +60,92 @@ int dfts_autoinit(void)
for (int i=0; i<IDFT_SIZE_IDXTABLESIZE ; i++) { for (int i=0; i<IDFT_SIZE_IDXTABLESIZE ; i++) {
ifftcfg[i]=kiss_fft_alloc(ifftsizes[i],1,NULL,NULL); ifftcfg[i]=kiss_fft_alloc(ifftsizes[i],1,NULL,NULL);
} }
#ifdef FIXED_POINT
olddfts_autoinit();
#endif
return 0; return 0;
} }
#ifndef FIXED_POINT
static float input_float[98304*2];
static float output_float[98304*2];
static float input_float2[98304*2];
static float output_float2[98304*2];
#endif
void convert_shorttofloat(int sizeidx,short *input,float *output){
for (int i=0;i<sizeidx;i=i+2){
output[2*i]=(float)input[2*i];
output[(2*i)+1]=(float)input[(2*i)+1];
void convert_shorttofloat(int size,short *input,float *output,int factor){
for (int i=0;i<(size-2);i++){
output[2*i]=(float)(input[2*i]*factor);
output[(2*i)+1]=(float)((input[(2*i)+1])*factor);
} }
} }
void convert_floattoshort(int sizeidx,float *input,short *output){ void convert_floattoshort(int size,float *input,short *output,int factor){
for (int i=0;i<sizeidx;i=i+2){ for (int i=0;i<(size-2);i++){
output[2*i]=(short)input[2*i]; output[2*i]=(int16_t)(((int)(roundf(input[2*i])))/factor);
output[(2*i)+1]=(short)input[(2*i)+1]; output[(2*i)+1]=(int16_t)(((int)(roundf(input[(2*i)+1])))/factor);
}
}
void rescale(int size,int16_t *input,int16_t *output){
for (int i=0;i<(size*2);i=i+1){
output[i]=(input[i]*32);
} }
} }
void idft_fixedpoint(uint8_t sizeidx, int16_t *input,int16_t *output,unsigned char scale_flag){
kiss_fft(ifftcfg[sizeidx],(kiss_fft_cpx *)input,(kiss_fft_cpx *)output);
};
void rescale_dftin(int size,int16_t *input){
for (int i=0;i<(size*2);i=i+1){
input[i]=(input[i]*32);
}
}
void rescale_dftout(int size,int16_t *input, int factor){
for (int i=0;i<(size*2);i=i+1){
input[i]=(input[i]/factor);
}
}
void print_minmax(int size,int16_t *buf,int scale_flag) {
int16_t vmin=0, vmax=0;
for (int i=0;i<(size*2);i=i+1){
if (buf[i]>vmax) vmax=buf[i];
if (buf[i]<vmin) vmin=buf[i];
}
// if (scale_flag == 0 || (vmax - vmin)>150)
// printf("%i: %i - %i\n",scale_flag,vmin,vmax);
}
void dft(uint8_t sizeidx,int16_t *input,int16_t *output,unsigned char scale_flag){ void dft(uint8_t sizeidx,int16_t *input,int16_t *output,unsigned char scale_flag){
#ifndef FIXED_POINT #ifndef FIXED_POINT
convert_shorttofloat(sizeidx,input,input_float); float input_float[98304*2];
float output_float[98304*2];
convert_shorttofloat(fftsizes[sizeidx],input,input_float,1);
kiss_fft(fftcfg[sizeidx],(kiss_fft_cpx *)input_float,(kiss_fft_cpx *)output_float); kiss_fft(fftcfg[sizeidx],(kiss_fft_cpx *)input_float,(kiss_fft_cpx *)output_float);
convert_floattoshort(sizeidx,output_float,output); if (scale_flag)
convert_floattoshort(fftsizes[sizeidx],output_float,output,786732);
else
convert_floattoshort(fftsizes[sizeidx],output_float,output,98304);
#else #else
rescale_dftin(fftsizes[sizeidx],input);
kiss_fft(fftcfg[sizeidx],(kiss_fft_cpx *)input,(kiss_fft_cpx *)output); kiss_fft(fftcfg[sizeidx],(kiss_fft_cpx *)input,(kiss_fft_cpx *)output);
if (scale_flag)
rescale_dftout(fftsizes[sizeidx],output,32);
else
rescale_dftout(fftsizes[sizeidx],output,8);
// olddft(sizeidx,input,output,scale_flag);
print_minmax(fftsizes[sizeidx],output,scale_flag);
#endif #endif
}; };
void idft(uint8_t sizeidx, int16_t *input,int16_t *output,unsigned char scale_flag){ void idft(uint8_t sizeidx, int16_t *input,int16_t *output,unsigned char scale_flag){
#ifndef FIXED_POINT #ifndef FIXED_POINT
convert_shorttofloat(sizeidx,input,input_float2); float input_float2[98304*2];
kiss_fft(fftcfg[sizeidx],(kiss_fft_cpx *)input_float2,(kiss_fft_cpx *)output_float2); float output_float2[98304*2];
convert_floattoshort(sizeidx,output_float2,output); convert_shorttofloat(ifftsizes[sizeidx],input,input_float2,8192);
kiss_fft(ifftcfg[sizeidx],(kiss_fft_cpx *)input_float2,(kiss_fft_cpx *)output_float2);
convert_floattoshort(ifftsizes[sizeidx],output_float2,output,98304);
#else #else
kiss_fft(fftcfg[sizeidx],(kiss_fft_cpx *)input,(kiss_fft_cpx *)output); int16_t inputrs[98304*2];
if (scale_flag)
rescale(ifftsizes[sizeidx],input,inputrs);
kiss_fft(ifftcfg[sizeidx],(kiss_fft_cpx *)inputrs,(kiss_fft_cpx *)output);
#endif #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