📄 exp6.html
字号:
operations, while C code can do well in data manipulation, like data formattingand arrangement. Finally, we show a special IIR filter application - resonatorin the last experiment.<o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'><imgborder=0 width=373 height=699 id="_x0000_i1026" src="exp6/figuree6-1.jpg"><o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'>FigureE6-1 DSP software development flow chart.</p><p style='margin-right:36.0pt;margin-left:36.0pt'> </p><form><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'>TableE6-1 The software signal generator for Experiment 6A, 6B, 6C and 6D.<o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="signal_gen2.c">/* signal_gen2 - generate two sinewaves of f1 and f2 */ #include <intrindefs.h> #define DELTA 0x7fa0 /* Delat - excite signal */ #define UNIT 0x7fff #define THIRD 0x2aaa	 /* 1/3 */ #define PI 3.1415926 #define N 1024 /* Max number of samples per block */ /* Fs = 8000 Sampling frequency */ /* f1 = 800, f2 = 1800, f3 = 3300 */ #define A1 0x678d /* UNIT*cos(2*PI*f1/Fs) */ #define A2 0x1405 /* UNIT*cos(2*PI*f2/Fs) */ #define A3 0x92de /* UNIT*cos(2*PI*f3/Fs) */ #define D1 0x4b04 /* DELTA*sin(2*PI*f1/Fs) */ #define D2 0x7e0e /* DELTA*sin(2*PI*f2/Fs) */ #define D3 0x42af /* DELTA*sin(2*PI*f3/Fs) */ static int w1[2]={(int)D1,0}; /* Determine the excite signal 1 */ static int w2[2]={(int)D2,0}; /* Determine the excite signal 2 */ static int w3[2]={(int)D3,0}; /* Determine the excite signal 3 */ static int cos_w1=(int)A1; /* Determine the coefficient 1 */ static int cos_w2=(int)A2; /* Determine the coefficient 2 */ static int cos_w3=(int)A3; /* Determine the coefficient 3 */ int x1[N],x2[N],x3[N]; extern void sine(int *, int *, unsigned int, int); void signal_gen2(int *x, unsigned int M) { unsigned int i; 	 sine(x1,w1,M,cos_w1); /* x1=A1*sin(2*PI*n*f1/Fs) */ sine(x2,w2,M,cos_w2); /* x2=A2*sin(2*PI*n*f2/Fs) */ sine(x3,w3,M,cos_w3); /* x3=A3*sin(2*PI*n*f3/Fs) */ for (i=0; i<M; i++) { x[i] = _smpy(x1[i],THIRD); x[i] = _sadd(x[i], _smpy(x2[i],THIRD)); x[i] = _sadd(x[i], _smpy(x3[i],THIRD)); } } </TEXTAREA><o:p></o:p></p><p style='margin-right:36.0pt;margin-left:36.0pt'> </p><p style='margin-right:72.0pt;margin-left:72.0pt'>Table E6-1 shows the softwaresignal generator <a href="exp6/signal_gen2.c"><span style='font-family:"Courier New"'>signal_gen2.c</span></a>for the experiments in this section. It is written using fixed-point C . Theassembly routine <a href="exp6/sine.asm"><span style='font-family:"Courier New"'>sine.asm</span></a>used by the <span style='font-family:"Courier New"'>signal_gen2()</span> isgiven in Table E6-2. The command file <a href="exp6/exp6.cmd"><spanstyle='font-family:"Courier New"'>exp6.cmd</span></a> is given in Table E6-3.</p><p style='margin-right:36.0pt;margin-left:36.0pt'> <o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'>TableE6-2 The IIR second-order resonator.<o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="sine.asm">; ; sine.asm - 2nd-order resonator as sinewave generator ; ; It works better in the range of f/Fs=[0.125-0.975] ; Initialization condition: ; A = cos(2*PI*f/Fs) ; w[0] = sin(2*PI*f/Fs) ; w[1] = 0 ; ; prototype: void sinewave_gen(int *x, unsigned int N, int *x, int cos_w) ; ; Entry: x[i] - AR0: output sinewave sample buffer ; wd[i] - AR1: delay-line ; N - T0: number of samples ; cos_w - T1: coefficient controls sinewave frequency ; ; .def _sine .text 		 _sine pshm ST1_55 ; Save ST1, ST2, and ST3 pshm ST2_55 pshm ST3_55 sub #1,T0 mov mmap(T0),BRC0 bset FRCT bset SATD bset SMUL mpym *AR1+,T1,AC0 ; AC0=cos(w)*w[0] || rptb sine_loop-1 ; for(i=0;i<N;i++) sub *AR1-<<#16,AC0,AC1 ; AC1=cos(w)*w[0]-w[1] add AC0,AC1 ; AC1=2*cos(w)*w[0]-w[1] || delay *AR1 ; w[1]=w[0] mov rnd(hi(AC1)),*AR1 ; w[0]=y[i] mov rnd(hi(AC1)),*AR0+ ; y[i]=2*cos(w)*w[0]-w[1] || mpym *AR1+,T1,AC0 ; AC0=cos(w)*w[0]	 sine_loop	 popm ST3_55 ; Restore ST1, ST2, and ST3 popm ST2_55 popm ST1_55 ret .end	 </TEXTAREA></p></form><form><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'>TableE6-3 The linker command file.<o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="exp6.cmd">/* Linker command file for Experiment 6 (C55x memory map) */ MEMORY { SPRAM : origin = 00000c0h, length = 0000040 DARAM0 : origin = 0000100h, length = 0003F00h DARAM1 : origin = 0004000h, length = 0004000h DARAM2 : origin = 0008000h, length = 0004000h DARAM3 : origin = 000c000h, length = 0004000h SARAM0 : origin = 0010000h, length = 0004000h SARAM1 : origin = 0014000h, length = 0004000h SARAM2 : origin = 0018000h, length = 0004000h SARAM3 : origin = 001c000h, length = 0004000h SARAM4 : origin = 0020000h, length = 0004000h SARAM5 : origin = 0024000h, length = 0004000h SARAM6 : origin = 0028000h, length = 0004000h SARAM7 : origin = 002c000h, length = 0004000h SARAM8 : origin = 0030000h, length = 0004000h SARAM9 : origin = 0034000h, length = 0004000h SARAM10 : origin = 0038000h, length = 0004000h SARAM11 : origin = 003c000h, length = 0004000h SARAM12 : origin = 0040000h, length = 0004000h SARAM13 : origin = 0044000h, length = 0004000h SARAM14 : origin = 0048000h, length = 0004000h SARAM15 : origin = 004c000h, length = 0004000h VECS : origin = 0ffff00h, length = 00100h /* reset vector */ }	 SECTIONS { vectors : {} > VECS /* interrupt vector table */ .cinit : {} > SARAM0 .text : {} > SARAM1 .stack : {} > DARAM0 .sysstack: {} > DARAM0 .sysmem : {} > DARAM1 .data : {} > DARAM1 .bss : {} > DARAM1 .const : {} > DARAM1 iir_coef : {} > SARAM0 /* user defined sections */ iir_data : {} > DARAM2 input : {} > SARAM0 output : {} > SARAM0 		/* word boundary alignment */ iir_code : {} > SARAM1 isrs : {} > SARAM2 }</TEXTAREA><o:p></o:p></p><p style='margin-right:36.0pt;margin-left:36.0pt'> </p></form><form></form><div class=MsoNormal align=center style='text-align:center'><hr size=3 width="100%" align=center></div><p align=center style='margin-right:72.0pt;margin-left:72.0pt;text-align:center'><strong><spanstyle='font-size:13.5pt;color:blue'>Experiment 6A - IIR Filter ImplementationUsing Floating-point C</span></strong></p><p style='margin-right:72.0pt;margin-left:72.0pt'>This experiment demonstratesthe first stage of the design flow of a lowpass IIR filter using TMS320C55x.The main C function <a href="exp6/exp6a.c"><span style='font-family:"Courier New"'>exp6a.c</span></a>in Table E6-4 and software signal generator listed in Table E6-1 and Table E6-2are used to aid the experiment. Table E6-5 gives the IIR Filter <ahref="exp6/iir.c"><span style='font-family:"Courier New"'>iir.c</span></a>.</p><p style='margin-right:36.0pt;margin-left:36.0pt'> <o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'>TableE6-4 The list of C function for Experiment 6A.<o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="exp6a">/* exp6a.c - Direct form II - IIR function implementation 		 in floating-point C and using signal generator */ #define M 128 /* Number of samples per block */ #define Ns 2 /* Number od 2nd order sections */ /* Low-pass IIR filter coefficients */ float C[Ns*5]={ /* i=section number */ /* A[i][1],A[i][2],B[i][2],B[i][0],B[i][1] */ -0.8659, 0.2139, 0.0992, 0.0992, 0.1984, -1.1249, 0.5770, 0.0992, 0.0992, 0.1984}; /* IIR filter delay line: w[]=w[i][n-1],w[i+1][n-1],...,w[i][n-2],w[i+1][n-2],... */ float w[Ns*2]; int out[M]; int in[M]; /* IIR filter function */ extern void iir(int*, int, int *, float *, int, float *); /* Software signal generator */ extern void signal_gen2(int *, unsigned int); void main(void) { int i; /* Initialize IIR filter delay line */ for (i=0; i<Ns*2;i++) w[i]=0; /* IIR filter experiment start */ for (;;) { signal_gen2(in,M); /* Generate a block of samples */ iir(in,M,out,C,Ns,w); /* Filter a block of samples */ } } </TEXTAREA><o:p></o:p></p><p style='margin-right:36.0pt;margin-left:36.0pt'> <o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'>TableE6-5 The floating-point C IIR filter routine.<o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="iir.c">/* iir.c - IIR direct form II biquads implementation prototype: void iir(int *, int, int *, float *, int, float *); Entry: arg0: pointer to the input sample buffer arg1: size of the input sample buffer arg2: pointer to the output sample buffer arg3: pointer to the coefficients array arg4: number of second-order IIR sections arg5: pointer to the filter delay-line buffer Return: None */ #define CHECK_OVERFLOW 1 #if CHECK_OVERFLOW static 	float w_max=-1.,w_min=1.; #endif void iir(int *x, int Nx, int *y, float *coef, int Ns, float *w) { int i,j,n,m,k,l,p; float temp, w_0; m=Ns*5; /* Setup for circular buffer coef[] */ k=Ns*2; /* Setup for circular buffer d[] */ for (j=0,l=0,n=0; n<Nx; n++) /* IIR filter */ { w_0 = (float)(x[n]/32767.0); /* Q15 to float */ for (i=0; i<Ns; i++) { w_0 -= *(w+l) * *(coef+j); j++; l=(l+Ns)%k; w_0 -= *(w+l) * *(coef+j); j++; 	 temp = *(w+l); 	 *(w+l) = w_0; 	 #if CHECK_OVERFLOW for (p=0;p<k;p++) { if (w_max <= w_0) w_max = w_0; if (w_min > w_0) w_min = w_0; } #endif 			 w_0 = temp * *(coef+j); j++; w_0 += *(w+l) * *(coef+j); j++; l=(l+Ns)%k; w_0 += *(w+l) * *(coef+j); j=(j+1)%m; l=(l+1)%k; #if CHECK_OVERFLOW for (p=0;p<k;p++) { if (w_max <= w_0) w_max = w_0; if (w_min > w_0) w_min = w_0; } #endif 		 } y[n] = (int)(w_0*32767); /* Q15 format output */ } } </TEXTAREA><o:p></o:p></p><p style='margin-right:36.0pt;margin-left:36.0pt'> </p><p style='margin-right:72.0pt;margin-left:72.0pt'>To conduct Experiment 6A,following these steps:</p><p class=MsoNormal style='margin-right:72.0pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:108.0pt;text-indent:-18.0pt;mso-list:l3 level1 lfo1;tab-stops:list 36.0pt'><![if !supportLists]>1.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>Createthe project, <span style='font-family:"Courier New"'>exp6a</span> and includethe linker command file <span style='font-family:"Courier New"'>exp6.cmd</span>,the C function <span style='font-family:"Courier New"'>exp6a.c</span>, <spanstyle='font-family:"Courier New"'>iir.c</span>, <span style='font-family:"Courier New"'>signal_gen2.c</span>,and the assembly routine <span style='font-family:"Courier New"'>sine.asm</span>.The lowpass filter <span style='font-family:"Courier New"'>iir()</span> willremove high frequency components from the input signal generated by the signalgenerator <span style='font-family:"Courier New"'>signal_gen2() </span>whichuses the resonator sinewave function<span style='font-family:"Courier New"'>sine()</span> to generate three sinewaves in 800Hz, 1.8kHz, and 3.3 kHz.</p><p class=MsoNormal style='margin-right:72.0pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:108.0pt;text-indent:-18.0pt;mso-list:l3 level1 lfo1;tab-stops:list 36.0pt'><![if !supportLists]>2.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>Use<span style='font-family:"Courier New"'>rts55.lib </span>for the C function <spanstyle='font-family:"Courier New"'>main()</span>initialization and build theproject <span style='font-family:"Courier New"'>exp6a</span>.</p><p class=MsoNormal style='margin-right:72.0pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:108.0pt;text-indent:-18.0pt;mso-list:l3 level1 lfo1;tab-stops:list 36.0pt'><![if !supportLists]>3.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>Enablebreak point at the statement <span style='font-family:"Courier New"'>for(;;)</span>ofthe <span style='font-family:"Courier New"'>main()</span> function and use CCSgraphic function to view the 16-bit integer output samples in the buffer <spanstyle='font-family:"Courier New"'>out[]</span>, set data length to 128 forviewing one block data a time. Animate the filtering process and observe thefilter output as a clean sine wave of 800 Hz.</p><p class=MsoNormal style='margin-right:72.0pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:108.0pt;text-indent:-18.0pt;mso-list:l3 level1 lfo1;tab-stops:list 36.0pt'><![if !supportLists]>4.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>ProfileIIR filter <span style='font-family:"Courier New"'>iir()</span> performance andrecord the memory space usage.</p><p class=MsoNormal style='margin-right:72.0pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:108.0pt;text-indent:-18.0pt;mso-list:l3 level1 lfo1;tab-stops:list 36.0pt'><![if !supportLists]>5.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>Checkthe IIR filter function for possible overflow. Use CCS watch window to view <spanstyle='font-family:"Courier New"'>w_max</span> and <span style='font-family:"Courier New"'>w_min</span> in animation.</p><p> </p><p style='margin-right:108.0pt;margin-left:108.0pt'>Figure E6-1 and Figure E6-2show the plots of the first block of input and output samples of Experiment 6Ain frequency and time domain.</p><p style='margin-right:36.0pt;margin-left:36.0pt'> <o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'><imgborder=0 width=399 height=498 id="_x0000_i1028" src="exp6/input.jpg"><o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'>FigureE6-1 Input of the filter in frequency and time domain.<o:p></o:p></p><p style='margin-right:36.0pt;margin-left:36.0pt'> <o:p></o:p></p><p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'><imgborder=0 width=396 height=497 id="_x0000_i1029" src="exp6/output.jpg"><o:p></o:p></p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -