⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exp6.html

📁 (Ebook-Pdf) Dsp - Real Time Digital Signal Processing (Usando Tms320-55Xx). 有书
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<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'>&nbsp;</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">/* &#13;&#10;   exp6b.c - Direct form II - IIR function implementation &#13;&#10;             in Fixed-point C and using signal generator&#13;&#10;*/                           &#13;&#10;&#13;&#10;#define M       128    /* Number of samples per block */&#13;&#10;#define Ns      2      /* Number od 2nd order sections */&#13;&#10;&#13;&#10;/* Low-pass IIR filter coefficients in Q14 format */&#13;&#10;int C[Ns*5]={ /* i=section number */&#13;&#10;              /* A[i][1],A[i][2],B[i][2],B[i][0],B[i][1] */&#13;&#10;                  -14187,   3505,   1624,   1624,   3249,&#13;&#10;                  -18430,   9454,   1624,   1624,   3249};&#13;&#10;/* IIR filter delay line:&#13;&#10;w[]=w[i][n-1],w[i+1][n-1],...,w[i][n-2],w[i+1][n-2],... */&#13;&#10;int w[Ns*2];&#9; &#13;&#10;&#13;&#10;int out[M];  &#13;&#10;int in[M];  &#13;&#10;&#13;&#10;/* IIR filter function */&#13;&#10;extern void iir(int*, int, int *, int *, int, int *);&#13;&#10;&#13;&#10;/* Software signal generator */&#13;&#10;extern void signal_gen2(int *, unsigned int);&#13;&#10;&#13;&#10;void main(void)&#13;&#10;{&#13;&#10;    int i;&#13;&#10;&#13;&#10;    /* Initialize IIR filter delay line and signal generator */&#13;&#10;    for (i=0; i&lt;Ns*2; i++)&#13;&#10;        w[i]=0; &#13;&#10;&#13;&#10;    /* IIR filter experiment start */  &#13;&#10;    for (;;)           &#13;&#10;    {&#13;&#10;        signal_gen2(in,M);     /* Generate a buffer of samples */&#13;&#10;        iir(in,M,out,C,Ns,w);  /* Filter a buffer of samples */                         &#13;&#10;    }&#13;&#10;}&#13;&#10;</TEXTAREA></p><p align=center style='text-align:center'>&nbsp;</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">/*&#13;&#10;    iir_i1.c - IIR direct form II biquads filter&#13;&#10;               in Fixed-point implementation&#13;&#10;*/&#13;&#10;&#13;&#10;#include &lt;intrindefs.h&gt;&#13;&#10;#define  SCALE 1&#13;&#10;&#13;&#10;void iir(int *x, int Nx, int *y, int *coef, int Ns, int *w)&#13;&#10;{      &#13;&#10;    int i,j,n,m,k,l;&#13;&#10;    int temp;&#13;&#10;    long w_0;&#13;&#10;        &#13;&#10;    m=Ns*5;             /* Setup for circular buffer coef[] */&#13;&#10;    k=Ns*2;             /* Setup for circular buffer d[] */&#13;&#10;&#13;&#10;    for (j=0,l=0,n=0; n&lt;Nx; n++)        /* IIR filter */ &#13;&#10;    {&#13;&#10;        w_0 = (long)x[n]&lt;&lt;(15-SCALE);   /* Q14 input (scaled) */ &#13;&#10;        for (i=0; i&lt;Ns; i++)&#13;&#10;        {    &#13;&#10;            w_0 = _smas(w_0,*(w+l),*(coef+j)); j++; l=(l+Ns)%k;&#13;&#10;            w_0 = _smas(w_0,*(w+l),*(coef+j)); j++;&#13;&#10;       &#9;    temp = *(w+l);&#13;&#10;&#9;    *(w+l) = w_0&gt;&gt;15;                  &#13;&#10;&#9;    w_0 = _lsmpy(     temp,*(coef+j)); j++; &#13;&#10; &#9;    w_0 = _smac(w_0,*(w+l),*(coef+j)); j++; l=(l+Ns)%k; &#13;&#10;            w_0 = _smac(w_0,*(w+l),*(coef+j)); j=(j+1)%m; l=(l+1)%k;&#13;&#10;        }&#13;&#10;        y[n] = w_0&gt;&gt;(15-SCALE);         /* Q15 format output */&#13;&#10;    }&#13;&#10;}&#13;&#10;</TEXTAREA></p><p style='margin-right:36.0pt;margin-left:36.0pt'>&nbsp;</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"'>&nbsp;&nbsp;&nbsp;&nbsp; </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"'>&nbsp;&nbsp;&nbsp;&nbsp; </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"'>&nbsp;&nbsp;&nbsp;&nbsp; </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"'>&nbsp;&nbsp;&nbsp;&nbsp; </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"'>&nbsp;&nbsp;&nbsp;&nbsp; </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'>&nbsp;</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">/* &#13;&#10;   exp6c.c - Direct form II - IIR function implementation &#13;&#10;             in Fixed-point C and using signal generator&#13;&#10;*/                           &#13;&#10;&#13;&#10;#define M       128    /* Number of samples per block */&#13;&#10;#define Ns      2      /* Number od 2nd order sections */&#13;&#10;&#13;&#10;#pragma DATA_SECTION(C, &quot;iir_coef&quot;);&#13;&#10;#pragma DATA_SECTION(w, &quot;iir_data&quot;); &#13;&#10;#pragma DATA_SECTION(out, &quot;iir_out&quot;); &#13;&#10;#pragma DATA_SECTION(in, &quot;iir_in&quot;); &#13;&#10;#pragma CODE_SECTION(main, &quot;iir_code&quot;);&#13;&#10;&#13;&#10;/* Low-pass IIR filter coefficients in Q14 format */&#13;&#10;int C[Ns*5]={ /* i=section number */&#13;&#10;              /* A[i][1],A[i][2],B[i][2],B[i][0],B[i][1] */&#13;&#10;                  -14187,   3505,   1624,   1624,   3249,&#13;&#10;                  -18430,   9454,   1624,   1624,   3249};&#13;&#10;/* IIR filter delay line:&#13;&#10;w[]=w[i][n-1],w[i+1][n-1],...,w[i][n-2],w[i+1][n-2],... */ &#9;   &#13;&#10;int w[Ns*2];&#13;&#10;&#13;&#10;int out[M];  &#13;&#10;int in[M];  &#13;&#10;&#13;&#10;/* IIR filter function */&#13;&#10;extern void iir(int*, unsigned int, int *, int *, unsigned int, int *);&#13;&#10;&#13;&#10;/* Software signal generator */&#13;&#10;extern void signal_gen2(int *, unsigned int);&#13;&#10;&#13;&#10;void main(void)&#13;&#10;{&#13;&#10;    unsigned int i;&#13;&#10;    int *ptr=&amp;w[0];&#13;&#10;    &#13;&#10;    /* Initialize IIR filter delay line and signal generator */&#13;&#10;    for (i=Ns*2; i&gt;0; i--)&#13;&#10;        *ptr++ = 0; &#13;&#10;            &#13;&#10;    /* IIR filter */  &#13;&#10;    for (;;)           &#13;&#10;    {&#13;&#10;        signal_gen2(in,M);     /* Generate a buffer of samples */&#13;&#10;        iir(in,M,out,C,Ns,w);  /* Filter a buffer of samples */                         &#13;&#10;    }&#13;&#10;}&#13;&#10;</TEXTAREA></p><p align=center style='text-align:center'>&nbsp;</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">/*&#13;&#10;&#9;iir_i2.c - IIR direct form II biquads filter&#13;&#10;                   in Fixed-point implementation&#13;&#10;*/&#13;&#10;&#13;&#10;#include &lt;intrindefs.h&gt;&#13;&#10;&#13;&#10;#pragma CODE_SECTION(iir, &quot;iir_code&quot;);&#13;&#10;&#13;&#10;#define SCALE 1   &#13;&#10;&#13;&#10;void iir(int *x, unsigned int Nx, int *y, int *coef, unsigned int Ns, int *w)&#13;&#10;{      &#13;&#10;    unsigned int i,j,n,m,k,l;&#13;&#10;    int temp;&#13;&#10;    long w_0;&#13;&#10;        &#13;&#10;    m=Ns*5;             /* Setup for circular buffer coef[] */&#13;&#10;    k=(Ns&lt;&lt;1)-1;        /* Setup for circular buffer d[] */&#13;&#10;&#13;&#10;    for (j=0,l=0,n=Nx; n&gt;0; n--)           /* IIR filter */ &#13;&#10;    {&#13;&#10;        w_0 = (long)*x &lt;&lt;(15-SCALE); *x++; /* Q14 input (scaled) */ &#13;&#10;        for (i=Ns; i&gt;0; i--)&#13;&#10;        {    &#13;&#10;            w_0 = _smas(w_0,*(w+l),*(coef+j)); j++; l=(l+Ns)&amp;k; &#13;&#10;            w_0 = _smas(w_0,*(w+l),*(coef+j)); j++;&#9;&#13;&#10;            temp = *(w+l);&#13;&#10;            *(w+l) = w_0&gt;&gt;15;                  &#13;&#10;            w_0 = _lsmpy(     temp,*(coef+j)); j++;&#9; &#13;&#10;            w_0 = _smac(w_0,*(w+l),*(coef+j)); j++; l=(l+Ns)&amp;k;  &#13;&#10;            w_0 = _smac(w_0,*(w+l),*(coef+j)); j=(j+1)%m; l=(l+1)&amp;k;&#13;&#10;        }&#13;&#10;        *y++ = w_0&gt;&gt;(15-SCALE);             /* Q15 format output */&#13;&#10;    }&#13;&#10;}&#13;&#10;</TEXTAREA></p><p align=center style='text-align:center'>&nbsp;</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 + -