📄 exp3.html
字号:
<p align=center style='margin-right:72.0pt;margin-left:72.0pt;text-align:center'>(a)Without saturation protection - overflow causes the data errors</p><p align=center style='margin-right:72.0pt;margin-left:72.0pt;text-align:center'><imgborder=0 width=533 height=444 id="_x0000_i1031" src="exp3/fe3-2b.jpg"></p><p align=center style='margin-right:72.0pt;margin-left:72.0pt;text-align:center'>(b)with saturation protection - the data saturated when overflow occurs</p><p align=center style='margin-right:72.0pt;margin-left:72.0pt;text-align:center'>FigureE3-2 Examples of overflow and saturation.</p><p align=center style='margin-right:72.0pt;margin-left:72.0pt;text-align:center'> </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><p align=center style='text-align:center'><strong><span style='font-size:13.5pt;color:blue'>Experiment 3D - Quantization of Coefficients</span></strong></p><p style='margin-right:72.0pt;margin-left:72.0pt'>Filters are widely used forDSP applications. Due to quantization, the filter in fixed-point representationwill no longer the same as the floating-point filter obtained from most filterdesign packages. In this experiment, we use assembly routine <ahref="exp3/exp3d_iir.asm"><span style='font-family:"Courier New"'>exp3d_iir.asm</span></a>to show the quantization effects to filter coefficients. More filter experimentswill be presented later in Chapter 5 and Chapter 6. The function <ahref="exp3/exp3d.c"><span style='font-family:"Courier New"'>exp3d.c</span></a>for this experiment and the assembly routine <a href="exp3/exp3d_iir.asm"><spanstyle='font-family:"Courier New"'>exp3d_iir.asm</span></a> are listed in TableE3-5 and Table E3-6, respectively.</p><p style='margin-right:72.0pt;margin-left:72.0pt'> </p><p align=center style='text-align:center'>Table E3-5 List of C function forExperiment 3D.</p><p align=center style='text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="exp3d.c">/* ------------------------------------------- exp3d.c 	 Quantization effect to an IIR filter ---------------------------------------------- */ #define FILELENGTH 27956 /* # of sample of input file timit1.asc */ extern int iir4(int); extern void init_iir4(void); int indata,outdata; void main(void) { int i; 	 init_iir4(); for (i = 0; i < FILELENGTH; i++) outdata = iir4(indata); } </TEXTAREA></p><p align=center style='text-align:center'> </p><p align=center style='text-align:center'>Table E3-6 List of the IIR filterroutine for Experiment 3D.</p><p align=center style='text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="exp3d_iir.asm">;---------------------------------------------- ; ; exp3d_IIR.asm ;	 ; 4th Order IIR filter ; ;---------------------------------------------- MASK .set 0xFFFF .def _iir4 .def _init_iir4 ; ; Original coefficients 0-1800Hz 4th order IIR LPF ; with sampling frequency 8000Hz ; ; int b[5]={0.0072, 0.00287, 0.0431, 0.0287, 0.0072}; ; int a[5]={1.0000, -2.16860,2.0097,-0.8766, 0.1505}; ; .data ; Q13 formatted coefficients ; coeff ; b0, b1, b2, b3, b4 .word 0x003B&MASK, 0x00EB&MASK .word 0x0161&MASK, 0x00EB&MASK, 0x003B&MASK ; -a1, -a2, -a3, -a4 .word 0x4564&MASK, -0x404F&MASK .word 0x1C0D&MASK, -0x04D1&MASK .bss x,5 ; x delay line .bss y,4 ; y delay line .text _init_iir4 pshboth XAR5 amov #x,XAR5 rpt #4 mov #0,*AR5+ amov #y,XAR5 		 rpt #3 mov #0,*AR5+ popboth XAR5	 ret 	 ; ; 4th Order IIR filter ; Entry T0 = sample ; Exit T0 = filtered sample ; _iir4 pshboth XAR5	 pshboth XAR6 bset SATD bset SXM 	 amov #x,XAR5 amov #y,XAR6 amov #coeff,XCDP 	 bset FRCT || mov T0,*AR5 ; x[0] = indata ; ; perform IIR filter ; mpym *AR5+,*CDP+,AC0 ; AC0=x[0]*bn[0] || rpt	 #3 ; i=1,2,3,4 macm *AR5+,*CDP+,AC0 ; AC0+=x[i]*bn[i] rpt #3 ; i=0,1,2,3 macm *AR6+,*CDP+,AC0 ; AC0+=y[i]*an[i] amov #y+2,XAR5 amov #y+3,XAR6 sfts AC0,#2 ; Scale to Q15 format || rpt #2 mov *AR5-,*AR6- ; Update y[] mov hi(AC0),*AR6 || mov hi(AC0),T0 ; return y[0] in T0 amov #x+3,XAR5 amov #x+4,XAR6 bclr FRCT	 || rpt #3 mov *AR5-,*AR6- ; Update x[] 	 popboth XAR6 popboth XAR5 bclr SXM bclr SATD || ret 	 .end </TEXTAREA></p><p style='margin-right:72.0pt;margin-left:72.0pt'>To conduct Experiment 3D,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:l1 level1 lfo5;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"'>exp3d</span> and includethe linker command file <span style='font-family:"Courier New"'>exp3.cmd</span>,the function <span style='font-family:"Courier New"'>exp3d()</span>, andassembly routine <span style='font-family:"Courier New"'>exp3d_iir.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 lfo5;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 <spanstyle='font-family:"Courier New"'>main()</span> function initialization andbuild the project.</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 lfo5;tab-stops:list 36.0pt'><![if !supportLists]>3.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>Buildthe project. Debug is needed.</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 lfo5;tab-stops:list 36.0pt'><![if !supportLists]>4.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>Interfacethe project with a signal source, such as the speech file <spanstyle='font-family:"Courier New"'>timit1.asc</span>. Process the data and savethe filter output.</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 lfo5;tab-stops:list 36.0pt'><![if !supportLists]>5.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>Listenthe IIR filte output file generated with different coefficient wordlengths.</p><p align=center style='margin-right:72.0pt;margin-left:72.0pt;text-align:center'> </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><p align=center style='text-align:center'><strong><span style='font-size:13.5pt;color:blue'>Experiment 3E - Function Approximation in Fixed-point NumberRepresentation </span></strong></p><p style='margin-right:72.0pt;margin-left:72.0pt'>For DSP applications, weoften use Q-format to represent fractional numbers. We have introducedquantization and overflow protection in previous experiments. In thisexperiment, we will present another useful method - polynomial approximationwith sinusoid function example to further study and understand the fixed-pointarithmetic operation and overflow control. The function <a href="exp3/exp3e.c"><spanstyle='font-family:"Courier New"'>exp3e.c</span></a> for this experiment andthe assembly routine <a href="exp3/sine_cos.asm"><span style='font-family:"Courier New"'>sine_cos.asm</span></a>are listed in Table E3-7 and Table E3-8, respectively.</p><p style='margin-right:72.0pt;margin-left:72.0pt'> </p><p align=center style='text-align:center'>Table E3-7 List of C function forExperiment 3E.</p><p align=center style='text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="exp3e.c">/* --------------------------------- exp3e.c 	 Fixed-point representaion ------------------------------------ */ extern void sine_cos(int, int *); const int theta[16]={ 0x9556,0xa000,0xaaab,0xc000, /* -150, -135, -120, -90 */ 0xd555,0xe000,0xeaab,0xffff, /* -60, -45, -30, -0 */ 0x1555,0x2000,0x2aaa,0x4000, /* 30, 45, 60, 90 */ 0x5555,0x6000,0x6aaa,0x7fff}; /* 120, 135, 150, 180 */ int	result_buf[32]; int Wn_buf[2]; void main() { int *result, *Wn; int i; for (i=0; i<32; i++) result_buf[i]=0; 			 result = result_buf; Wn = Wn_buf; 	 /* 3rd quadrant angles */ sine_cos(theta[0], Wn); /* -150 */ *result++ = *Wn++; *result++ = *Wn--; sine_cos(theta[1], Wn); /* -135 */ *result++ = *Wn++; *result++ = *Wn--;	 sine_cos(theta[2], Wn); /* -120 */ *result++ = *Wn++; *result++ = *Wn--; sine_cos(theta[3], Wn); /* -90 */ *result++ = *Wn++; *result++ = *Wn--; 		 /* 4th quadrant angles */ sine_cos(theta[4], Wn); /* -60 */ *result++ = *Wn++; *result++ = *Wn--; sine_cos(theta[5], Wn); /* -45 */ *result++ = *Wn++; *result++ = *Wn--; sine_cos(theta[6], Wn); /* -30 */ *result++ = *Wn++; *result++ = *Wn--; sine_cos(theta[7], Wn); /* -0 */ *result++ = *Wn++; *result++ = *Wn--; 	 /* 1st quadrant angles */ sine_cos(theta[8], Wn); /* 30 */ *result++ = *Wn++; *result++ = *Wn--; sine_cos(theta[9], Wn);	 /* 45 */ *result++ = *Wn++; *result++ = *Wn--; sine_cos(theta[10], Wn); /* 60 */ *result++ = *Wn++; *result++ = *Wn--; sine_cos(theta[11], Wn); /* 90 */ *result++ = *Wn++; *result++ = *Wn--; 		 /* 2nd quadrant angles */ sine_cos(theta[12], Wn); /* 120 */ *result++ = *Wn++; *result++ = *Wn--; sine_cos(theta[13], Wn); /* 135 */ *result++ = *Wn++; *result++ = *Wn--; sine_cos(theta[14], Wn); /* 150 */ *result++ = *Wn++; *result++ = *Wn--; sine_cos(theta[15], Wn); /* 180 */ *result++ = *Wn++; *result++ = *Wn--; } </TEXTAREA></p><p align=center style='text-align:center'> </p><p align=center style='text-align:center'>Table E3-8 List of the sine-cosine generatorfor Experiment 3E.</p><p align=center style='text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="sine_cos.asm">; ; sine_cos: 16-bit sine(x) and cos(x) approximation function ; ; Entry: T0 = x, in the range of [-pi=0x8000 pi=0x7fff] ;			AR0 -> Pointer ; Return: None ; Update: ; AR0->[0] = cos(x) = d0+d1*x+d2*x^2+d3*x^3+d4*x^4+d5*x^5 ; AR0->[1] = sin(x) = c1*x+c2*x^2+c3*x^3+c4*x^4+c5*x^5 ; ; 36 cycles ; .def _sine_cos 		 ; ; Approximation coefficients in Q12 (4096) format ; .data coeff ; Sine appoximation coefficients .word 0x3240 ; c1 = 3.140625 .word 0x0053 ; c2 = 0.02026367 .word 0xaacc ; c3 = -5.325196 .word 0x08b7 ; c4 = 0.54467780 .word 0x1cce ; c5 = 1.80029300 ; Cosine appoximation coefficients .word 0x1000 ; d0 = 1.0000 .word 0xfff8 ; d1 = -0.001922133 .word 0xb199 ; d2 = -4.90014738 .word 0xfbc3 ; d3 = -0.2648921 .word 0x50ba ; d4 = 5.0454103 .word 0xe332 ; d5 = -1.800293 ; ; Function starts ; .text _sine_cos pshboth XAR5 		; Save AR5 amov #14,AR5 btstp AR5,T0 ; Test bit 15 and 14 ; ; Start cos(x) ;	 amov #coeff+10,XAR5 ; Pointer to the end of coefficients xcc _neg_x,TC1 neg T0 ; Negate if bit 14 is set _neg_x	 	 and #0x7fff,T0 ; Mask out sign bit mov *AR5-<<#16,AC0 ; AC0 = d5 || bset SATD ; Set Saturate bit 	 mov *AR5-<<#16,AC1 ; AC1 = d4 || bset FRCT ; Set up fractional bit	 mac AC0,T0,AC1 ; AC1 = (d5*x+c4) || mov *AR5-<<#16,AC0 ; AC0 = d3	 mac AC1,T0,AC0 ; AC0 = (d5*x^2+d4*x+d3) || mov *AR5-<<#16,AC1 ; AC1 = d2	 mac AC0,T0,AC1 ; AC1 = (d5*x^3+d4*x^2+d3*x+d2) || mov *AR5-<<#16,AC0 ; AC0 = d1	 mac AC1,T0,AC0 ; AC0 = (d5*x^4+d4*x^3+d3*x^2+d2*x+d1) || mov *AR5-<<#16,AC1 ; AC1 = d0 macr AC0,T0,AC1	 ; AC1 = (d5*x^4+d4*x^3+d3*x^2+d2*x+d1)*x+d0 || xcc _neg_result1,TC2 neg AC1 _neg_result1	 mov *AR5-<<#16,AC0 ; AC0 = c5 || xcc _neg_result2,TC1 neg AC1 _neg_result2 mov hi(saturate(AC1<<#3)),*AR0+ ; return cos(x) in Q15 ; ; Start sin(x) computation ; mov *AR5-<<#16,AC1 ; AC1 = c4 mac AC0,T0,AC1 ; AC1 = (c5*x+c4) || mov *AR5-<<#16,AC0 ; AC0 = c3	 mac AC1,T0,AC0 ; AC0 = (c5*x^2+c4*x+c3) || mov *AR5-<<#16,AC1 ; AC1 = c2	 mac AC0,T0,AC1 ; AC1 = (c5*x^3+c4*x^2+c3*x+c2) || mov *AR5-<<#16,AC0 ; AC0 = c1	 mac AC1,T0,AC0 ; AC0 = (c5*x^4+c4*x^3+c3*x^2+c2*x+c1) || popboth XAR5 ; Restore AR5 mpyr T0,AC0,AC1 ; AC1 = (c5*x^4+c4*x^3+c3*x^2+c2*x+c1)*x || xcc _neg_result3,TC2 neg AC1 _neg_result3	 mov hi(saturate(AC1<<#3)),*AR0- ; return sin(x) in Q15		 || bclr FRCT ; Reset fractional bit	 bclr SATD ; Reset saturate bit ret .end </TEXTAREA></p><p style='margin-right:72.0pt;margin-left:72.0pt'>To conduct Experiment 3D,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:l4 level1 lfo6;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"'>exp3e</span> and includethe linker command file <span style='font-family:"Courier New"'>exp3.cmd</span>,the function <span style='font-family:"Courier New"'>exp3e()</span>, andassembly routine <span style='font-family:"Courier New"'>sine_cos.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:l4 level1 lfo6;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 <spanstyle='font-family:"Courier New"'>main()</span> function initialization andbuild the project.</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:l4 level1 lfo6;tab-stops:list 36.0pt'><![if !supportLists]>3.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>Buildthe project. Debug is needed.</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:l4 level1 lfo6;tab-stops:list 36.0pt'><![if !supportLists]>4.<spanstyle='font:7.0pt "Times New Roman"'> </span><![endif]>Calculatethe values of sin(<span style='font-family:Symbol'>q</span>) and cos(<spanstyle='font-family:Symbol'>q</span>) functions for 0<<span style='font-family:Symbol'>q</span><2<span style='font-family:Symbol'>p</span>.</p><p align=center style='margin-right:72.0pt;margin-left:72.0pt;text-align:center'> </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></form><div class=MsoNormal align=center style='text-align:center'><hr size=3 width="100%" align=center></div><p><i><u><span style='font-size:7.5pt'>copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -