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

📄 exp7.html

📁 (Ebook-Pdf) Dsp - Real Time Digital Signal Processing (Usando Tms320-55Xx). 有书
💻 HTML
📖 第 1 页 / 共 4 页
字号:
tab-stops:list .5in'><![if !supportLists]>4.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;
</span><![endif]>Experiment 7C - Fast Convolution</p>

<p style='margin-right:1.0in;margin-left:1.0in'>For the experiments in this
section, we first implement the decimation-in-time FFT algorithm using the
methodology of floating-point C - fixed-point C - assembly language approach as
we learned from Chapter 6. We then implement the inverse Fast Fourier Transform
(IFFT) using the same FFT routine. Finally, we apply both FFT and IFFT as a
linear convolution example for an FIR filter application. The linker command
file <a href="exp7/exp7.cmd"><span style='font-family:"Courier New"'>exp7.cmd</span></a>
for the experiments is listed in Table E7-1, below.</p>

<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'>Table
E7-1 Linker command file for experiments in Chapter 7</p>

<form>

<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="exp7.cmd">/*&#13;&#10;    Linker command file for Experiments (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;    fft_coef : {} &gt; SARAM3         /* user defined sections */&#13;&#10;    fft_temp : {} &gt; DARAM2 &#13;&#10;    fft_twdl : {} &gt; SARAM4 &#13;&#10;    fft_in   : {} &gt; SARAM0 align 4 /* word boundary alignment */&#13;&#10;    fft_out  : {} &gt; SARAM0 align 4 /* word boundary alignment */   &#13;&#10;    iir_code : {} &gt; SARAM1 &#13;&#10;    isrs     : {} &gt; SARAM2         &#13;&#10;}&#13;&#10;</TEXTAREA></p>

</form>


<div class=MsoNormal align=center style='text-align:center'>

<hr size=3 width="100%" align=center>

</div>


<p style='margin-right:1.0in;margin-left:1.0in'><span style='font-size:13.5pt;
color:blue'>Experiment 7A - Radix-2 Complex FFT in C</span></p>

<p style='margin-right:1.0in;margin-left:1.0in'>This experiment will present
the decimation-in-time of the FFT butterfly computation. The fixed-point C
function for computing a radix-2 complex decimation-in-time FFT is listed in
Table 7-2. This program will compute an N-point FFT of a sinusoid function
using the C55x intrinsics. The output of this program should be all zeros
except for the FFT bins at the frequency of the analysis signals. Since this is
a complex radix-2 FFT routine, the imaginary portion of the complex sample
buffer must to be zeroed if the samples we use a real data sequence.</p>

<p style='margin-right:1.0in;margin-left:1.0in'>For better understand the FFT
and to create a reference model, the readers are encouraged to complete the
step 1 of the Experiment 7A - to build the floating-point C model.</p>

<p style='margin-right:1.0in;margin-left:1.0in'>The fixed-point C FFT function
consists of two components, the FFT function <a href="exp7/fft_a.c"><span
style='font-family:"Courier New"'>fft_a.c</span></a> and the bit reversal
function <a href="exp7/ibit_rev.c"><span style='font-family:"Courier New"'>ibit_rev.c</span></a><span
style='font-family:"Courier New"'>, </span>listed in Table E7-2 and Table E7-3,
respectively.</p>

<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'>Table
E7-2 List of fixed-point FFT function using the C55x intrinsics</p>

<form>

<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="fft_a.c">/*&#13;&#10;    fft_a.c - Radix 2 decimation in time FFT &#13;&#10;    Using C55x C intrinsics to perform in place FFT, &#13;&#10;    the output overwrite the input array&#13;&#10;*/&#13;&#10;&#13;&#10;#include &quot;icomplex.h&quot;&#13;&#10;#include &lt;intrindefs.h&gt; &#13;&#10;&#13;&#10;#define  SFT16 16&#13;&#10;&#13;&#10;void fft(complex *X, unsigned int EXP, complex *W, unsigned int SCALE)&#13;&#10;{&#13;&#10;    complex temp;          /* temporary storage of int complex variable */      &#13;&#10;    lcomplex ltemp;        /* temporary storage of long complex variable */    &#13;&#10;    complex U;             /* Twiddle factor W^k */&#13;&#10;    unsigned int i,j;&#13;&#10;    unsigned int id;       /* Index for lower point in butterfly */&#13;&#10;    unsigned int N=1&lt;&lt;EXP; /* Number of points for FFT */&#13;&#10;    unsigned int L;        /* FFT stage */&#13;&#10;    unsigned int LE;       /* Number of points in sub DFT at stage L&#13;&#10;                              and offset to next DFT in stage */&#13;&#10;    unsigned int LE1;      /* Number of butterflies in one DFT at&#13;&#10;                              stage L.  Also is offset to lower point&#13;&#10;                              in butterfly at stage L */&#13;&#10;    int scale;&#13;&#10;    &#13;&#10;    scale = 1;     &#13;&#10;    if (SCALE == 0)         &#13;&#10;        scale = 0;&#13;&#10;&#13;&#10;    for (L=1; L&lt;=EXP; L++) /* FFT butterfly */&#13;&#10;    {&#13;&#10;        LE=1&lt;&lt;L;    /* LE=2^L=points of sub DFT */&#13;&#10;        LE1=LE&gt;&gt;1;  /* Number of butterflies in sub DFT */&#13;&#10;        U.re = 0x7fff;&#13;&#10;        U.im = 0;&#13;&#10;&#13;&#10;        for (j=0; j&lt;LE1;j++)&#13;&#10;        {&#13;&#10;            for(i=j; i&lt;N; i+=LE) /* Do the butterflies */&#13;&#10;            {&#13;&#10;                id=i+LE1;                 &#13;&#10;                ltemp.re = _lsmpy(X[id].re, U.re);&#13;&#10;                temp.re = (_smas(ltemp.re, X[id].im, U.im)&gt;&gt;SFT16);  &#13;&#10;                temp.re = _sadd(temp.re, 1)&gt;&gt;scale; /* Rounding &amp; scale */&#13;&#10;                ltemp.im = _lsmpy(X[id].im, U.re);&#13;&#10;                temp.im = (_smac(ltemp.im, X[id].re, U.im)&gt;&gt;SFT16);&#13;&#10;                temp.im = _sadd(temp.im, 1)&gt;&gt;scale; /* Rounding &amp; scale */&#13;&#10;                X[id].re = _ssub(X[i].re&gt;&gt;scale, temp.re);&#13;&#10;                X[id].im = _ssub(X[i].im&gt;&gt;scale, temp.im);&#13;&#10;                X[i].re = _sadd(X[i].re&gt;&gt;scale, temp.re);&#13;&#10;                X[i].im = _sadd(X[i].im&gt;&gt;scale, temp.im);&#13;&#10;            }&#13;&#10;            &#13;&#10;            /* Recursive compute W^k as W*W^(k-1) */&#13;&#10;            ltemp.re = _lsmpy(U.re, W[L-1].re);&#13;&#10;            ltemp.re = _smas(ltemp.re, U.im, W[L-1].im);  &#13;&#10;            ltemp.im = _lsmpy(U.re, W[L-1].im);&#13;&#10;            ltemp.im = _smac(ltemp.im, U.im, W[L-1].re);&#13;&#10;            U.re = ltemp.re&gt;&gt;SFT16;            &#13;&#10;            U.im = ltemp.im&gt;&gt;SFT16;&#13;&#10;        }&#13;&#10;    }&#13;&#10;}  &#13;&#10;</TEXTAREA></p>

</form>

<p style='margin-right:1.0in;margin-left:1.0in'>&nbsp;</p>

<p style='margin-right:1.0in;margin-left:1.0in'>Intrinsics is intended to
reduce the programming effort when using C language and to improve the DSP run time
by accessing the assembly instructions directly from the C function.</p>

<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'>Table
E7-3 Fixed-point bit reversal function</p>

<form>

<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="ibit_rev.c">/* Arrange input samples in bit-reverse addressing order&#13;&#10;   the index j is the bit reverse of i */&#13;&#10;&#13;&#10;#include &quot;icomplex.h&quot;    /* integer complex.h header file */&#13;&#10;&#13;&#10;void bit_rev(complex *X, unsigned int EXP)&#13;&#10;{&#13;&#10;    unsigned int i,j,k;&#13;&#10;    unsigned int N=1&lt;&lt;EXP; /* Number of points for FFT */&#13;&#10;    unsigned int N2=N&gt;&gt;1;&#13;&#10;    complex temp;          /* temporary storage of int complex variable */&#9;&#13;&#10;&#9;&#13;&#10;    for (j=0,i=1;i&lt;N-1;i++)&#13;&#10;    {&#13;&#10;        k=N2;&#13;&#10;        while(k&lt;=j)&#13;&#10;        {&#13;&#10;            j-=k;&#13;&#10;            k&gt;&gt;=1;&#13;&#10;        }&#13;&#10;        j+=k;&#13;&#10;&#13;&#10;        if (i&lt;j)&#13;&#10;        {&#13;&#10;            temp = X[j];&#13;&#10;            X[j] = X[i];&#13;&#10;            X[i] = temp;&#13;&#10;        }&#13;&#10;    }  &#13;&#10;}&#13;&#10;</TEXTAREA></p>

</form>

<p style='margin-right:.5in;margin-left:.5in'>&nbsp;</p>

<p style='margin-right:1.0in;margin-left:1.0in'>The FFT function uses complex
data type. The header file <a href="exp7/icomplex.h"><span style='font-family:
"Courier New"'>icomplex.h</span></a> in Table E7-4 shows how to define the
complex data type.</p>

<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'>Table
E7-4 Header file defining the complex data type</p>

<form>

<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="icomplex.h">/*&#13;&#10;&#9;Header file icomplex.h for fixed-point&#13;&#10;*/&#13;&#10;&#13;&#10;struct cmpx      /* Q15 format */&#13;&#10;{&#13;&#10;&#9;int re;&#13;&#10;&#9;int im;&#13;&#10;};&#13;&#10;typedef struct cmpx complex;&#13;&#10;&#13;&#10;struct lcmpx     /* Q31 format */&#13;&#10;{&#13;&#10;&#9;long re;&#13;&#10;&#9;long im;&#13;&#10;};&#13;&#10;typedef struct lcmpx lcomplex;&#13;&#10;&#13;&#10;</TEXTAREA></p>

</form>

<p style='margin-right:.5in;margin-left:.5in'>&nbsp;</p>

<p style='margin-right:1.0in;margin-left:1.0in'>The function <a
href="exp7/exp7a.c"><span style='font-family:"Courier New"'>exp7a.c</span></a>
controls the experiment. From Table E7-5, one can see that the data is read in
one block a time, then the function bit reversal and FFT are called.</p>

<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'>Table
E7-5 List of <span style='font-family:"Courier New"'>exp7a.c</span></p>

<form>

<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="exp7a.c">/*&#13;&#10;     exp7a.c - Example to test FFT&#13;&#10;*/&#13;&#10;&#13;&#10;#include &lt;math.h&gt;   &#13;&#10;#include &quot;icomplex.h&quot;    /* integer complex.h header file */&#13;&#10;#include &quot;input7_i.dat&quot;&#13;&#10;&#13;&#10;extern void fft(complex *, unsigned int, complex *, unsigned int);&#13;&#10;extern void bit_rev(complex *, unsigned int);&#13;&#10;&#13;&#10;#define N 128           /* Number of FFT points */&#13;&#10;#define EXP 7           /* EXP=log2(N)              */&#13;&#10;#define pi 3.1415926535897  &#13;&#10;#define K 3             /* Index of Xk (0&lt;K&lt; N/2) */ &#13;&#10;                       &#13;&#10;complex X[N];           /* Declare input array  */&#13;&#10;complex W[EXP];         /* Twiddle e^(-j2pi/N) table */    &#13;&#10;lcomplex ltemp;&#13;&#10;int spectrum[N];&#13;&#10;int re1[N],im1[N];&#13;&#10;&#13;&#10;void main()&#13;&#10;{&#13;&#10;    unsigned int i,j,L,LE,LE1;   &#13;&#10;&#13;&#10;    for (L=1; L&lt;=EXP; L++) /* Create twiddle factor table */&#13;&#10;    {&#13;&#10;        LE=1&lt;&lt;L;           /* LE=2^L=points of sub DFT */&#13;&#10;        LE1=LE&gt;&gt;1;     &#9;   /* Number of butterflies in sub-DFT */&#13;&#10;        W[L-1].re = (int)((0x7fff*cos(pi/LE1))+0.5);&#13;&#10;        W[L-1].im = -(int)((0x7fff*sin(pi/LE1))+0.5);&#13;&#10;    }    &#13;&#10;    &#13;&#10;    j=0;&#13;&#10;    for (;;)&#13;&#10;    {&#13;&#10;        for (i=0; i&lt;N; i++) &#13;&#10;        {&#13;&#10;            /* Construct input samples */&#13;&#10;            X[i].re = input7_i[j++];&#13;&#10;            X[i].im = 0;        &#13;&#10;            /* Copy to reference buffer */&#13;&#10;            re1[i] = X[i].re;&#13;&#10;            im1[i] = X[i].im;&#13;&#10; &#13;&#10;            if (j==1664)&#13;&#10;                j=0;&#13;&#10;        } &#9;&#13;&#10;&#13;&#10;        /* Start FFT */&#13;&#10;        bit_rev(X,EXP);     /* Arrange X[] in bit-reverse order */&#13;&#10;        fft(X,EXP,W,1);&#9;    /* Perform FFT */&#13;&#10;&#13;&#10;        for (i=0; i&lt;N; i++) /* Verify FFT result */&#13;&#10;        {&#13;&#10;            ltemp.re = (long)X[i].re*X[i].re;&#13;&#10;            ltemp.im = (long)X[i].im*X[i].im;        &#13;&#10;            spectrum[i] = (int)((ltemp.re+ltemp.im)&gt;&gt;13);&#13;&#10;        }&#13;&#10;    }&#13;&#10;}&#13;&#10;&#13;&#10;</TEXTAREA></p>

</form>

<p style='margin-right:.5in;margin-left:.5in'>&nbsp;</p>

<p style='margin-right:1.0in;margin-left:1.0in'>For Experiment 7A, follow these
steps:</p>

<p class=MsoNormal style='margin-right:1.0in;mso-margin-top-alt:auto;
mso-margin-bottom-alt:auto;margin-left:1.5in;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .5in'><![if !supportLists]>1.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;
</span><![endif]>Verify the floating-point FFT C program, including: <span
style='font-family:"Courier New"'>test_fft.c</span>, <span style='font-family:
"Courier New"'>fft_float.c</span>, <span style='font-family:"Courier New"'>fbit_rev.c</span>,
and <span style='font-family:"Courier New"'>fcomplex.h</span>, using your
computer or C55x emulator. The output should be all zeros except the squared
amplitudes of the complex outputs of X<span style='font-size:7.5pt'>k </span>and
X<span style='font-size:7.5pt'>N-k</span>. They are equal to 1.0. The
floating-point model will be used as our reference for the code development
from the fixed-point C to assembly language. The floating-point model uses the
data file input7_f.dat, while the fixed-point data file input7_i.dat will be
used for the rest of the experiments.</p>

<p class=MsoNormal style='margin-right:1.0in;mso-margin-top-alt:auto;
mso-margin-bottom-alt:auto;margin-left:1.5in;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .5in'><![if !supportLists]>2.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;
</span><![endif]>Create the project <span style='font-family:"Courier New"'>exp7a</span>
using CCS. Add the command file <span style='font-family:"Courier New"'>exp7.cmd</span>,
function <span style='font-family:"Courier New"'>epx7a.c</span>, <span
style='font-family:"Courier New"'>fft_a.c</span>, <span style='font-family:
"Courier New"'>ibit_rev.c</span>, and the header file <span style='font-family:
"Courier New"'>icomplex.h</span> from the experimental software package.</p>

<p class=MsoNormal style='margin-right:1.0in;mso-margin-top-alt:auto;
mso-margin-bottom-alt:auto;margin-left:1.5in;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .5in'><![if !supportLists]>3.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;
</span><![endif]>Build the fixed-point FFT project and verify the fixed-point
FFT result. Comparing it with the floating-point complex radix-2 FFT results
obtained by running it on the PC. </p>

<p class=MsoNormal style='margin-right:1.0in;mso-margin-top-alt:auto;
mso-margin-bottom-alt:auto;margin-left:1.5in;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .5in'><![if !supportLists]>4.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;
</span><![endif]>The FFT samples are squared and are also placed into a buffer
named <span style='font-family:"Courier New"'>spectrum[]</span>. This
represents the frequency spectrum of the input. Use CCS to plot the FFT result
by displaying the <span style='font-family:"Courier New"'>spectrum[]</span> and
<span style='font-family:"Courier New"'>re1[]</span> array of the experiment. </p>

<p class=MsoNormal style='margin-right:1.0in;mso-margin-top-alt:auto;
mso-margin-bottom-alt:auto;margin-left:1.5in;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .5in'><![if !supportLists]>5.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -