From: baobrien Date: Sat, 14 Mar 2015 23:48:55 +0000 (+0000) Subject: Further work on cic interpolator, some stm32 testing X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=466134249881dbdd6101bffbaf8cc3a01d321d71;p=freetel-svn-tracking.git Further work on cic interpolator, some stm32 testing git-svn-id: https://svn.code.sf.net/p/freetel/code@2074 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/dacres.m b/codec2-dev/octave/dacres.m index 41f82424..3ef8659f 100644 --- a/codec2-dev/octave/dacres.m +++ b/codec2-dev/octave/dacres.m @@ -15,7 +15,7 @@ fi = 2E6/M; %freq of first interpolation fb = 7E5; %Bandpass frequency fc1 = fi/4; %Frequency of initial upconversion ciccb=[-0.029626 0.252638 -2.304683 16.332166 -2.304683 0.252638 -0.029626]; %CIC Compensation FIR -pcicfb = fir1(39,.5); %Interpolation LPF Fir +pcicfb = fir1(21,.5); %Interpolation LPF Fir s1fir = filter(ciccb,1,pcicfb); %Combine compensation and LPF %s1fir = [-0.00000215, -0.00008715, 0.00073915, -0.00674415, 0.05618415, 0.01629015, -0.19074815, -0.04231615, 0.53620515, 0.09933915, -1.32978715, -0.38797815, 3.97887715, 6.70888315, 3.97887715, -0.38797815, -1.32978715, 0.09933915, 0.53620515, -0.04231615, -0.19074815, ]; diff --git a/codec2-dev/stm32/src/fast_dac_ut.c b/codec2-dev/stm32/src/fast_dac_ut.c index 0790f3a1..1f9dec04 100644 --- a/codec2-dev/stm32/src/fast_dac_ut.c +++ b/codec2-dev/stm32/src/fast_dac_ut.c @@ -34,7 +34,8 @@ #include #include #include "gdb_stdio.h" - +#include "comp.h" +#include "gmsk_test_dat_m4.h" #define SINE_SAMPLES 32 @@ -54,6 +55,12 @@ float f4sine[] = {1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0 1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0, -1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,1,0,-1,0,}; +//Intermediate 80k real before tx +float tx_imm[DUC_N]; + +//Complex input to chain +COMP comp_in[DUC_N/10]; + unsigned short outbuf[DAC_DUC_BUF_SZ]; void setup_timer() @@ -71,23 +78,37 @@ void setup_timer() } int main(void) { - int tstart,tend,cyc; + int tstart,tup,tend,cyc,i; memset((void*)outbuf,0,sizeof(short)*DAC_DUC_BUF_SZ); setup_timer(); fast_dac_open(2*DAC_DUC_BUF_SZ,2*DAC_BUF_SZ); - - tstart=tend=0; + tstart=tend=tup=cyc=0; + //Initalize complex input with signal at zero + for(i=0;iGMSK_TEST_LEN) + cyc=0; + /*if(cyc%10000==0){ + printf("8c80r takes %d uSecs\n",tup-tstart); + printf("iir upconvert takes %d uSecs\n",tend-tup); + }*/ + tstart = TIM_GetCounter(TIM2); + + upconv_8c_80r(comp_in,tx_imm,1); + + tup = TIM_GetCounter(TIM2); + + iir_upconv(tx_imm,outbuf); + tend = TIM_GetCounter(TIM2); - dac1_write((short*)outbuf,DAC_DUC_BUF_SZ); + + //Sit and spin until we can get more samples into the dac + while(dac1_write((short*)outbuf,DAC_DUC_BUF_SZ)<0); } } diff --git a/codec2-dev/stm32/src/iir_duc.c b/codec2-dev/stm32/src/iir_duc.c index 3a18dc1b..f79dc609 100644 --- a/codec2-dev/stm32/src/iir_duc.c +++ b/codec2-dev/stm32/src/iir_duc.c @@ -79,17 +79,16 @@ void iir_upconv(float modin[], unsigned short dac_out[]){ } } -#define F8C80R_LEN 40 //Number of taps in the 8C80R filters -#define F8C80R_MUL 1024 +#define F8C80R_LEN 30 //Number of taps in the 8C80R filters +#define F8C80R_MUL 4096 static int int1r,int2r,int3r,int4r,cmb1r,cmb2r,cmb3r,cmb4r; //States for re combs and integrators static int int1i,int2i,int3i,int4i,cmb1i,cmb2i,cmb3i,cmb4i; //States for im combs and integrators -static float fir_8c80r_cic[]; //FIR Coeffs -static float fir_8c80r_re[F8C80R_LEN*2]; //FIR delay line for re -static float fir_8c80r_im[F8C80R_LEN*2]; //FIR delay line for im static int ptr_8c80r; //circular buffer ptr fir_8c80r_re static int w8c80r = 0; //Omega for upconversion -static int cosf4[] = {1,0,-1,0}; //Cosine table for fs/4. precomputed by meat computer -static int sinf4[] = {0,1,0,-1}; //Sine table for fs/4. + +static int fir_8c80r_cic_i[]; //FIR Coeffs +static int fir_8c80r_re[F8C80R_LEN*2]; //FIR delay line for re +static int fir_8c80r_im[F8C80R_LEN*2]; //FIR delay line for im /* Interpolate and shift from 8k complex to 80k real, centered on Fs/4. @@ -100,16 +99,20 @@ static int sinf4[] = {0,1,0,-1}; //Sine table for fs/ void upconv_8c_80r(COMP comp_8[],float real_80[],int count){ int i,j,k; //Loop indices - float nr,ni,ret; //Temporary variables + float ret; //Temporary variables + int nr,ni; int cmbr,cmbi,cmbrr,cmbii,rein,imin; //More temporaries + int inidx = 0; //Index of input + int outidx = 0; //Index of output for(i=0;i>14; + ni+=(fir_8c80r_cic_i[k]*fir_8c80r_im[ptr_8c80r+k])>>14; } ptr_8c80r++; //Spin the dealy line index if(ptr_8c80r>=F8C80R_LEN) ptr_8c80r=0; - - rein = (int)(nr*F8C80R_MUL); //Convert to int - imin = (int)(ni*F8C80R_MUL); //CIC filters must be signed,fixed point to work - + rein=nr; + imin=ni; cmbr = rein - cmb1r; cmb1r = rein; //Comb 1 real cmbrr = cmbr - cmb2r; cmb2r = cmbr; //Comb 2 real cmbr = cmbrr - cmb3r; cmb3r = cmbrr; //Comb 3 real @@ -149,9 +152,15 @@ void upconv_8c_80r(COMP comp_8[],float real_80[],int count){ int4i = int3i + int4i; //Integrator stage 4 im //Convert this complex into real and cancel out the gain from CIC //This should probably spit out integers instead of going back to float - ret = (float) (((-cosf4[w8c80r]*int4r)+(sinf4[w8c80r]*int4i))); - real_80[(i*DUC_N)+(j*5)] = ret/526024; - w8c80r = (w8c80r+1)&0x3; + switch(w8c80r&0x3){ //Do comp->real conversion by hand + case 0:ret=(float)(-int4r>>8);break; + case 1:ret=(float)(int4i>>8);break; + case 2:ret=(float)(int4r>>8);break; + case 3:ret=(float)(-int4i>>8);break; + } + real_80[outidx] = ret/8192; //Divide by 4096 to cancel out gain + outidx++; + w8c80r++; //spin omega //Next 4 stages of integration. Stage 1 can be ignored because of zero stuffing. for(k=1;k<5;k++){ int2r = int1r + int2r; //Integrator stage 2 re @@ -160,9 +169,15 @@ void upconv_8c_80r(COMP comp_8[],float real_80[],int count){ int2i = int1i + int2i; //Integrator stage 2 im int3i = int2i + int3i; //Integrator stage 3 im int4i = int3i + int4i; //Integrator stage 4 im - ret = (float)(((-cosf4[w8c80r]*int4r)+(sinf4[w8c80r]*int4i))); - real_80[(i*DUC_N)+(j*5)+k] = ret/526024; //Cancel out gain from all that. - w8c80r = (w8c80r+1)&0x3; + switch(w8c80r&0x3){ //Do comp->real conversion by hand + case 0:ret=(float)(-int4r>>8);break; + case 1:ret=(float)(int4i>>8);break; + case 2:ret=(float)(int4r>>8);break; + case 3:ret=(float)(-int4i>>8);break; + } + real_80[outidx] = ret/8192; //Cancel out gain from all that. + outidx++; + w8c80r++; } } } @@ -207,10 +222,10 @@ int main(void) { for(i=0;i