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

📄 exp6.html

📁 (Ebook-Pdf) Dsp - Real Time Digital Signal Processing (Usando Tms320-55Xx). 有书
💻 HTML
📖 第 1 页 / 共 4 页
字号:
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'>&nbsp;</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">/*&#13;&#10;      signal_gen2 - generate two sinewaves of f1 and f2&#13;&#10;*/&#13;&#10;#include &lt;intrindefs.h&gt;&#13;&#10;&#13;&#10;#define DELTA 0x7fa0           /* Delat - excite signal */&#13;&#10;#define UNIT  0x7fff &#13;&#10;#define THIRD 0x2aaa&#9;       /* 1/3 */&#13;&#10;#define PI    3.1415926 &#13;&#10;#define N     1024             /* Max number of samples per block */&#13;&#10;/* Fs = 8000 Sampling frequency */&#13;&#10;/* f1 = 800, f2 = 1800, f3 = 3300 */&#13;&#10;#define A1    0x678d           /* UNIT*cos(2*PI*f1/Fs) */&#13;&#10;#define A2    0x1405           /* UNIT*cos(2*PI*f2/Fs) */&#13;&#10;#define A3    0x92de           /* UNIT*cos(2*PI*f3/Fs) */&#13;&#10;#define D1    0x4b04           /* DELTA*sin(2*PI*f1/Fs) */&#13;&#10;#define D2    0x7e0e           /* DELTA*sin(2*PI*f2/Fs) */&#13;&#10;#define D3    0x42af           /* DELTA*sin(2*PI*f3/Fs) */&#13;&#10;&#13;&#10;static int w1[2]={(int)D1,0};  /* Determine the excite signal 1 */&#13;&#10;static int w2[2]={(int)D2,0};  /* Determine the excite signal 2 */&#13;&#10;static int w3[2]={(int)D3,0};  /* Determine the excite signal 3 */&#13;&#10;static int cos_w1=(int)A1;     /* Determine the coefficient 1 */&#13;&#10;static int cos_w2=(int)A2;     /* Determine the coefficient 2 */&#13;&#10;static int cos_w3=(int)A3;     /* Determine the coefficient 3 */        &#13;&#10;&#13;&#10;int  x1[N],x2[N],x3[N]; &#13;&#10;&#13;&#10;extern void sine(int *, int *, unsigned int, int);&#13;&#10;&#13;&#10;void signal_gen2(int *x, unsigned int M)&#13;&#10;{                    &#13;&#10;    unsigned int i;&#13;&#10;&#9;&#13;&#10;    sine(x1,w1,M,cos_w1);   /* x1=A1*sin(2*PI*n*f1/Fs) */&#13;&#10;    sine(x2,w2,M,cos_w2);   /* x2=A2*sin(2*PI*n*f2/Fs) */&#13;&#10;    sine(x3,w3,M,cos_w3);   /* x3=A3*sin(2*PI*n*f3/Fs) */&#13;&#10;    for (i=0; i&lt;M; i++)&#13;&#10;    {&#13;&#10;        x[i] = _smpy(x1[i],THIRD);&#13;&#10;        x[i] = _sadd(x[i], _smpy(x2[i],THIRD));&#13;&#10;        x[i] = _sadd(x[i], _smpy(x3[i],THIRD));&#13;&#10;    }&#13;&#10;}&#13;&#10;</TEXTAREA><o:p></o:p></p><p style='margin-right:36.0pt;margin-left:36.0pt'>&nbsp;</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'>&nbsp;<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">;&#13;&#10;;   sine.asm - 2nd-order resonator as sinewave generator&#13;&#10;;                                        &#13;&#10;;   It works better in the range of f/Fs=[0.125-0.975]&#13;&#10;;   Initialization condition:&#13;&#10;;       A = cos(2*PI*f/Fs)&#13;&#10;;       w[0] = sin(2*PI*f/Fs)&#13;&#10;;       w[1] = 0&#13;&#10;;&#13;&#10;;   prototype: void sinewave_gen(int *x, unsigned int N, int *x, int cos_w)&#13;&#10;;&#13;&#10;;   Entry: x[i] - AR0: output sinewave sample buffer&#13;&#10;;          wd[i] - AR1: delay-line&#13;&#10;;          N - T0: number of samples&#13;&#10;;          cos_w - T1: coefficient controls sinewave frequency &#13;&#10;;&#13;&#10;;&#13;&#10;&#13;&#10;    .def   _sine&#13;&#10;    .text&#13;&#10;&#9;&#9;&#13;&#10;_sine &#13;&#10;    pshm  ST1_55             ; Save ST1, ST2, and ST3&#13;&#10;    pshm  ST2_55&#13;&#10;    pshm  ST3_55&#13;&#10;&#13;&#10;    sub   #1,T0          &#13;&#10;    mov   mmap(T0),BRC0   &#13;&#10;    bset  FRCT        &#13;&#10;    bset  SATD               &#13;&#10;    bset  SMUL&#13;&#10;    mpym  *AR1+,T1,AC0       ; AC0=cos(w)*w[0]&#13;&#10;||  rptb  sine_loop-1        ; for(i=0;i&lt;N;i++)&#13;&#10;    sub   *AR1-&lt;&lt;#16,AC0,AC1 ; AC1=cos(w)*w[0]-w[1]&#13;&#10;    add   AC0,AC1            ; AC1=2*cos(w)*w[0]-w[1]&#13;&#10;||  delay *AR1               ; w[1]=w[0]&#13;&#10;    mov   rnd(hi(AC1)),*AR1  ; w[0]=y[i]  &#13;&#10;    mov   rnd(hi(AC1)),*AR0+ ; y[i]=2*cos(w)*w[0]-w[1]&#13;&#10;||  mpym  *AR1+,T1,AC0       ; AC0=cos(w)*w[0]&#9;&#13;&#10;sine_loop&#9;    &#13;&#10;     &#13;&#10;    popm  ST3_55             ; Restore ST1, ST2, and ST3&#13;&#10;    popm  ST2_55&#13;&#10;    popm  ST1_55&#13;&#10;    ret&#13;&#10;    .end&#9;&#13;&#10;</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">/*&#13;&#10;    Linker command file for Experiment 6 (C55x memory map) &#13;&#10;*/&#13;&#10;&#13;&#10;MEMORY&#13;&#10;{&#13;&#10;    SPRAM   : origin = 00000c0h, length = 0000040&#13;&#10;    DARAM0  : origin = 0000100h, length = 0003F00h&#13;&#10;    DARAM1  : origin = 0004000h, length = 0004000h&#13;&#10;    DARAM2  : origin = 0008000h, length = 0004000h&#13;&#10;    DARAM3  : origin = 000c000h, length = 0004000h&#13;&#10;&#13;&#10;    SARAM0  : origin = 0010000h, length = 0004000h&#13;&#10;    SARAM1  : origin = 0014000h, length = 0004000h&#13;&#10;    SARAM2  : origin = 0018000h, length = 0004000h&#13;&#10;    SARAM3  : origin = 001c000h, length = 0004000h&#13;&#10;    SARAM4  : origin = 0020000h, length = 0004000h&#13;&#10;    SARAM5  : origin = 0024000h, length = 0004000h&#13;&#10;    SARAM6  : origin = 0028000h, length = 0004000h&#13;&#10;    SARAM7  : origin = 002c000h, length = 0004000h&#13;&#10;    SARAM8  : origin = 0030000h, length = 0004000h&#13;&#10;    SARAM9  : origin = 0034000h, length = 0004000h&#13;&#10;    SARAM10 : origin = 0038000h, length = 0004000h&#13;&#10;    SARAM11 : origin = 003c000h, length = 0004000h&#13;&#10;    SARAM12 : origin = 0040000h, length = 0004000h&#13;&#10;    SARAM13 : origin = 0044000h, length = 0004000h&#13;&#10;    SARAM14 : origin = 0048000h, length = 0004000h&#13;&#10;    SARAM15 : origin = 004c000h, length = 0004000h&#13;&#10;&#13;&#10;    VECS    : origin = 0ffff00h, length = 00100h  /* reset vector */&#13;&#10;}&#9;&#13;&#10;&#13;&#10; &#13;&#10;SECTIONS&#13;&#10;{&#13;&#10;    vectors  : {} &gt; VECS             /* interrupt vector table */&#13;&#10;    .cinit   : {} &gt; SARAM0 &#13;&#10;    .text    : {} &gt; SARAM1 &#13;&#10;    .stack   : {} &gt; DARAM0 &#13;&#10;    .sysstack: {} &gt; DARAM0 &#13;&#10;    .sysmem  : {} &gt; DARAM1 &#13;&#10;    .data    : {} &gt; DARAM1 &#13;&#10;    .bss     : {} &gt; DARAM1 &#13;&#10;    .const   : {} &gt; DARAM1 &#13;&#10;&#13;&#10;    iir_coef : {} &gt; SARAM0           /* user defined sections */&#13;&#10;    iir_data : {} &gt; DARAM2 &#13;&#10;    input    : {} &gt; SARAM0&#13;&#10;    output   : {} &gt; SARAM0 &#9;&#9;/* word boundary alignment */   &#13;&#10;    iir_code : {} &gt; SARAM1 &#13;&#10;    isrs     : {} &gt; SARAM2         &#13;&#10;}</TEXTAREA><o:p></o:p></p><p style='margin-right:36.0pt;margin-left:36.0pt'>&nbsp;</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'>&nbsp;<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">/* &#13;&#10;   exp6a.c - Direct form II - IIR function implementation &#13;&#10;&#9;&#9;    in floating-point C and using signal generator&#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 */  &#13;&#10;float 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;                   -0.8659, 0.2139, 0.0992, 0.0992, 0.1984,&#13;&#10;                   -1.1249, 0.5770, 0.0992, 0.0992, 0.1984};&#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;float 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*, int, int *, float *, int, float *);&#13;&#10;&#13;&#10;/* Software signal generator */&#13;&#10;extern void signal_gen2(int *, unsigned int);&#13;&#10;&#13;&#10;         &#13;&#10;void main(void)&#13;&#10;{&#13;&#10;    int i;                                 &#13;&#10;&#13;&#10;    /* Initialize IIR filter delay line */&#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 block of samples */&#13;&#10;        iir(in,M,out,C,Ns,w); /* Filter a block of samples */                         &#13;&#10;    }&#13;&#10;}&#13;&#10;</TEXTAREA><o:p></o:p></p><p style='margin-right:36.0pt;margin-left:36.0pt'>&nbsp;<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">/*&#13;&#10;    iir.c - IIR direct form II biquads implementation&#13;&#10;    prototype: void iir(int *, int, int *, float *, int, float *);&#13;&#10;&#13;&#10;    Entry: arg0: pointer to the input sample buffer&#13;&#10;           arg1: size of the input sample buffer&#13;&#10;           arg2: pointer to the output sample buffer&#13;&#10;           arg3: pointer to the coefficients array&#13;&#10;           arg4: number of second-order IIR sections&#13;&#10;           arg5: pointer to the filter delay-line buffer&#13;&#10;&#13;&#10;    Return: None&#13;&#10;*/&#13;&#10;&#13;&#10;&#13;&#10;#define CHECK_OVERFLOW 1&#13;&#10;#if CHECK_OVERFLOW&#13;&#10;static &#9;float w_max=-1.,w_min=1.;&#13;&#10;#endif&#13;&#10;&#13;&#10;void iir(int *x, int Nx, int *y, float *coef, int Ns, float *w)&#13;&#10;{      &#13;&#10;    int i,j,n,m,k,l,p;&#13;&#10;    float temp, 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 = (float)(x[n]/32767.0);    /* Q15 to float */ &#13;&#10;        for (i=0; i&lt;Ns; i++)&#13;&#10;        {&#13;&#10;            w_0 -= *(w+l) * *(coef+j); j++; l=(l+Ns)%k;&#13;&#10;            w_0 -= *(w+l) * *(coef+j); j++; &#13;&#10;&#9;    temp = *(w+l);&#13;&#10;&#9;    *(w+l) = w_0;   &#13;&#10;&#9;    #if CHECK_OVERFLOW            &#13;&#10;            for (p=0;p&lt;k;p++)&#13;&#10;            {&#13;&#10;                if (w_max &lt;= w_0) w_max = w_0;&#13;&#10;                if (w_min &gt; w_0)  w_min = w_0; &#13;&#10;            } &#13;&#10;            #endif   &#9;&#9;&#9;                    &#13;&#10;            w_0  =   temp * *(coef+j); j++; &#13;&#10;            w_0 += *(w+l) * *(coef+j); j++; l=(l+Ns)%k;&#13;&#10;            w_0 += *(w+l) * *(coef+j); j=(j+1)%m; l=(l+1)%k;   &#13;&#10;            #if CHECK_OVERFLOW            &#13;&#10;            for (p=0;p&lt;k;p++)&#13;&#10;            {&#13;&#10;                if (w_max &lt;= w_0) w_max = w_0;&#13;&#10;                if (w_min &gt; w_0) w_min = w_0; &#13;&#10;            } &#13;&#10;            #endif           &#9;&#9;&#13;&#10;        }&#13;&#10;        y[n] = (int)(w_0*32767);        /* Q15 format output */&#13;&#10;    }&#13;&#10;}&#13;&#10;</TEXTAREA><o:p></o:p></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 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"'>&nbsp;&nbsp;&nbsp;&nbsp; </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"'>&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"'>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"'>&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:l3 level1 lfo1;tab-stops:list 36.0pt'><![if !supportLists]>4.<spanstyle='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp; </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"'>&nbsp;&nbsp;&nbsp;&nbsp; </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>&nbsp;</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'>&nbsp;<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'>&nbsp;<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 + -