📄 exp6.html
字号:
<p align=center style='margin-right:36.0pt;margin-left:36.0pt;text-align:center'>FigureE6-2 Output of the filter in frequency and time domain.</p><p><a href="#top"><span style='font-size:7.5pt'>Back to Top</span></a> <input type=button value="go back" onclick="history.go(-1)"></p><div class=MsoNormal align=center style='text-align:center'><hr size=3 width="100%" align=center></div><form><p align=center style='text-align:center'><strong><span style='font-size:13.5pt;color:blue'>Experiment 6B - Fixed-point C Implementation Using Intrinsics</span></strong></p><p style='margin-right:72.0pt;margin-left:72.0pt'>Experiment 6B introduces theC intrinsics for TMS320C55x programming in C. Using C intrinsics is anefficient way to prototype the DSP applications. In some cases, it may providethe performance efficient enough for use. The programs using intrinsics can beused as a design reference for bit-exactness verification between C andassembly languages. The use of intrinsics is similar to a C function call. Thespecific computation is carried out as assembly instructions and inserted tothe code directly. The C function <a href="exp6/exp6b.c"><spanstyle='font-family:"Courier New"'>exp6b.c</span></a> for Experiment 6B islisted in Table E6-6 for reference. The IIR filter C function that usesintrinsics <a href="exp6/iir_i1.c"><span style='font-family:"Courier New"'>iir_i1.c</span></a><em>,</em>which uses intrinsics is given in Table E6-7. </p><p align=center style='text-align:center'> </p><p align=center style='text-align:center'>Table E6-6 List of C function forExperiment 6B.</p><p align=center style='text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="exp6b.c">/* exp6b.c - Direct form II - IIR function implementation in Fixed-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 in Q14 format */ int C[Ns*5]={ /* i=section number */ /* A[i][1],A[i][2],B[i][2],B[i][0],B[i][1] */ -14187, 3505, 1624, 1624, 3249, -18430, 9454, 1624, 1624, 3249}; /* IIR filter delay line: w[]=w[i][n-1],w[i+1][n-1],...,w[i][n-2],w[i+1][n-2],... */ int w[Ns*2];	 int out[M]; int in[M]; /* IIR filter function */ extern void iir(int*, int, int *, int *, int, int *); /* Software signal generator */ extern void signal_gen2(int *, unsigned int); void main(void) { int i; /* Initialize IIR filter delay line and signal generator */ for (i=0; i<Ns*2; i++) w[i]=0; /* IIR filter experiment start */ for (;;) { signal_gen2(in,M); /* Generate a buffer of samples */ iir(in,M,out,C,Ns,w); /* Filter a buffer of samples */ } } </TEXTAREA></p><p align=center style='text-align:center'> </p><p align=center style='text-align:center'>Table E6-7 IIR filter using Cintrinsics.</p><p align=center style='text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="iir_i1.c">/* iir_i1.c - IIR direct form II biquads filter in Fixed-point implementation */ #include <intrindefs.h> #define SCALE 1 void iir(int *x, int Nx, int *y, int *coef, int Ns, int *w) { int i,j,n,m,k,l; int temp; long 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 = (long)x[n]<<(15-SCALE); /* Q14 input (scaled) */ for (i=0; i<Ns; i++) { w_0 = _smas(w_0,*(w+l),*(coef+j)); j++; l=(l+Ns)%k; w_0 = _smas(w_0,*(w+l),*(coef+j)); j++; 	 temp = *(w+l); 	 *(w+l) = w_0>>15; 	 w_0 = _lsmpy( temp,*(coef+j)); j++; 	 w_0 = _smac(w_0,*(w+l),*(coef+j)); j++; l=(l+Ns)%k; w_0 = _smac(w_0,*(w+l),*(coef+j)); j=(j+1)%m; l=(l+1)%k; } y[n] = w_0>>(15-SCALE); /* Q15 format output */ } } </TEXTAREA></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 6B,following these steps:</p></form><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:l1 level1 lfo2;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"'>exp6b</span> and includethe linker command file <span style='font-family:"Courier New"'>exp6.cmd</span>,the C function <span style='font-family:"Courier New"'>exp6b.c</span>,<spanstyle='font-family:"Courier New"'> iir_i1.c</span>,<span style='font-family:"Courier New"'> signal_gen2.c</span>, and the assembly routine <spanstyle='font-family:"Courier New"'>sine.asm</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:l1 level1 lfo2;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"'>exp6b</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:l1 level1 lfo2;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:l1 level1 lfo2;tab-stops:list 36.0pt'><![if !supportLists]>4.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>Profilethe IIR filter <span style='font-family:"Courier New"'>iir_i1()</span> andcompare the result with those obtained in Experiment 6A.</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:l1 level1 lfo2;tab-stops:list 36.0pt'><![if !supportLists]>5.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>Infile <span style='font-family:"Courier New"'>iir_i1()</span> set the scalefactor, <span style='font-family:"Courier New"'>SCALE</span>, to 0 so thesamples will not be scaled. Rebuild the project and run the IIR filterexperiment in the ANIMATION mode. You will see the output waveform distortionscaused by the intermediate overflow.</p><p><a href="#top"><span style='font-size:7.5pt'>Back to Top</span></a> <input type=button value="go back" onclick="history.go(-1)"></p><div class=MsoNormal align=center style='text-align:center'><hr size=3 width="100%" align=center></div><form><p align=center style='text-align:center'><strong><span style='font-size:13.5pt;color:blue'>Experiment 6C - Fixed-point C Programming ImplementationConsideration</span></strong></p><p style='margin-right:72.0pt;margin-left:72.0pt'>Familiar with the assemblycode generated by the TMS320C55x C compiler can help us to understand and writea better-structured C code for C compiler. Some basic considerations whenprogramming in C are the use of build-in library functions, loop counters,loops and local -repeat loop, as well as compiler optimization options. Experiment6C demonstrates how an IIR filter can be better written for the C compiler.Table E6-8 and Table E6-9 give the function <a href="exp6/exp6c.c"><spanstyle='font-family:"Courier New"'>exp6c.c</span></a> and modified IIR function <ahref="exp6/iir_i2.c"><span style='font-family:"Courier New"'>iir_i2.c</span></a>,respectively.</p><p style='margin-right:36.0pt;margin-left:36.0pt'> </p><p align=center style='text-align:center'>Table E6-8 List of C function forExperiment 6C.</p><p align=center style='text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="exp6c.c">/* exp6c.c - Direct form II - IIR function implementation in Fixed-point C and using signal generator */ #define M 128 /* Number of samples per block */ #define Ns 2 /* Number od 2nd order sections */ #pragma DATA_SECTION(C, "iir_coef"); #pragma DATA_SECTION(w, "iir_data"); #pragma DATA_SECTION(out, "iir_out"); #pragma DATA_SECTION(in, "iir_in"); #pragma CODE_SECTION(main, "iir_code"); /* Low-pass IIR filter coefficients in Q14 format */ int C[Ns*5]={ /* i=section number */ /* A[i][1],A[i][2],B[i][2],B[i][0],B[i][1] */ -14187, 3505, 1624, 1624, 3249, -18430, 9454, 1624, 1624, 3249}; /* IIR filter delay line: w[]=w[i][n-1],w[i+1][n-1],...,w[i][n-2],w[i+1][n-2],... */ 	 int w[Ns*2]; int out[M]; int in[M]; /* IIR filter function */ extern void iir(int*, unsigned int, int *, int *, unsigned int, int *); /* Software signal generator */ extern void signal_gen2(int *, unsigned int); void main(void) { unsigned int i; int *ptr=&w[0]; /* Initialize IIR filter delay line and signal generator */ for (i=Ns*2; i>0; i--) *ptr++ = 0; /* IIR filter */ for (;;) { signal_gen2(in,M); /* Generate a buffer of samples */ iir(in,M,out,C,Ns,w); /* Filter a buffer of samples */ } } </TEXTAREA></p><p align=center style='text-align:center'> </p><p align=center style='text-align:center'>Table E6-9 Modified IIR filterfunction.</p><p align=center style='text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="iir_i2.c">/* 	iir_i2.c - IIR direct form II biquads filter in Fixed-point implementation */ #include <intrindefs.h> #pragma CODE_SECTION(iir, "iir_code"); #define SCALE 1 void iir(int *x, unsigned int Nx, int *y, int *coef, unsigned int Ns, int *w) { unsigned int i,j,n,m,k,l; int temp; long w_0; m=Ns*5; /* Setup for circular buffer coef[] */ k=(Ns<<1)-1; /* Setup for circular buffer d[] */ for (j=0,l=0,n=Nx; n>0; n--) /* IIR filter */ { w_0 = (long)*x <<(15-SCALE); *x++; /* Q14 input (scaled) */ for (i=Ns; i>0; i--) { w_0 = _smas(w_0,*(w+l),*(coef+j)); j++; l=(l+Ns)&k; w_0 = _smas(w_0,*(w+l),*(coef+j)); j++;	 temp = *(w+l); *(w+l) = w_0>>15; w_0 = _lsmpy( temp,*(coef+j)); j++;	 w_0 = _smac(w_0,*(w+l),*(coef+j)); j++; l=(l+Ns)&k; w_0 = _smac(w_0,*(w+l),*(coef+j)); j=(j+1)%m; l=(l+1)&k; } *y++ = w_0>>(15-SCALE); /* Q15 format output */ } } </TEXTAREA></p><p align=center style='text-align:center'> </p><p style='margin-right:72.0pt;margin-left:72.0pt'>To conduct Experiment 6C,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:l0 level1 lfo3;tab-stops:list 36.0pt'><![if !supportLists]>1.<span
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -