📄 exp7.html
字号:
E7-10 List of <span style='font-family:"Courier New"'>exp7c.c</span></p>
<form>
<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="exp7c.c">/* exp7c.c - Example to test FFT and IFFT */ #include "icomplex.h" #include "input7_i.dat" /* Experiment data file */ extern void fft(complex *, unsigned int, complex *, unsigned int); extern void bit_rev(complex *, unsigned int); extern void w_table(complex *, unsigned int); #define N 128 /* Number of FFT points */ #define EXP 7 /* log2(N) */ #pragma DATA_SECTION(U, "fft_coef"); #pragma DATA_SECTION(X, "fft_in"); #pragma DATA_SECTION(spectrum, "fft_out"); #pragma DATA_SECTION(ltemp, "fft_temp"); #pragma DATA_SECTION(temp, "fft_temp"); #pragma CODE_SECTION(main, "fft_code"); complex X[N]; /* Declare input array */ complex U[N]; /* Twiddle e^(-j2pi/N) table */ complex temp; lcomplex ltemp; int spectrum[N]; int re1[N],im1[N],re2[N],im2[N]; void main() { unsigned int i,j; /* Create Twiddle lookup table for FFT */ w_table(U, EXP); /* Start FFT test */ j=0; for (;;) { for (i=0; i<N; i++) { /* Generate input samples */ X[i].re = input7_i[j++]; X[i].im = 0; /* Copy to reference buffer */ re1[i] = X[i].re; im1[i] = X[i].im; if (j==1664) j=0; 	} /* Start FFT */ bit_rev(X,EXP); /* Arrange X[] in bit reversal order */ fft(X,EXP,U,1); /* Perform FFT */ /* Use spectrum to verify FFT result */ for (i=0; i<N; i++) { 	 ltemp.re = (long)X[i].re*X[i].re; ltemp.im = (long)X[i].im*X[i].im; spectrum[i] = (int)((ltemp.re+ltemp.im)>>13); } /* Inverse FFT */ for (i=0; i<N; i++) /* Change the sign of imag part */ { X[i].im = -X[i].im; } bit_rev(X,EXP); /* Arrange sample in bit reversal order */ fft(X,EXP,U,0); /* Perform IFFT */ /* Store IFFT output samples for verification */ for (i=0; i<N; i++) { re2[i] = X[i].re; im2[i] = X[i].im; } } } </TEXTAREA></p>
</form>
<p style='margin-right:1.0in;margin-left:1.0in'> </p>
<p style='margin-right:1.0in;margin-left:1.0in'>For Experiment 7C, go over the
following 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:l3 level1 lfo8;
tab-stops:list .5in'><![if !supportLists]>1.<span style='font:7.0pt "Times New Roman"'>
</span><![endif]>Create the project <span style='font-family:"Courier New"'>epx7c</span>,
and include <span style='font-family:"Courier New"'>exp7.cmd</span>, <span
style='font-family:"Courier New"'>exp7c.c</span>, <span style='font-family:
"Courier New"'>w_table.c</span>, <span style='font-family:"Courier New"'>fft.asm</span>,
and <span style='font-family:"Courier New"'>bit_rev.asm</span>.</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:l3 level1 lfo8;
tab-stops:list .5in'><![if !supportLists]>2.<span style='font:7.0pt "Times New Roman"'>
</span><![endif]>Build and view the IFFT result by plotting and comparing the
input sample reference array <span style='font-family:"Courier New"'>re1[]</span>
and IFFT output reference array <span style='font-family:"Courier New"'>re2[]</span>.
Make sure that the scale flag for the FFT routine is set to 1, and the IFFT
routine is set to zero.</p>
<p style='margin-right:1.0in;margin-left:1.0in'> </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 style='margin-right:1.0in;margin-left:1.0in'><span style='font-size:13.5pt;
color:blue'>Experiment 7C - Fast Convolution</span></p>
<p style='margin-right:1.0in;margin-left:1.0in'>For higher order filtering
process, fast convolution using FFT is preferred. The fast convolution can be
done applying the FFT function to the input samples and filter impulse
response. The time domain convolution is then performed in frequency domain as
multiplication. The result is converted to time domain using the inverse FFT.</p>
<p style='margin-right:1.0in;margin-left:1.0in'>This experiment implements the
FFT convolution using the overlap-add method. Besides the functions and
routines we introduced in the previous experiments, there are two more assembly
routines needed for the fast convolution. First, the routine <a
href="exp7/freqflt.asm"><span style='font-family:"Courier New"'>freqflt.asm</span></a>
that is used to perform the filter operation in frequency domain; it is listed
in Table E7-11.</p>
<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'>Table
E7-11 Routine <span style='font-family:"Courier New"'>freqflt.asm</span></p>
<form>
<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="freqflt.asm">; ; freqflt.asm - Routine to perform frequency domain filtering ; ; Protptye: void freqflt(complex *, complex *, unsigned int); ; ; Entry: arg0: AR0 is the pointer to X[] ; arg1: AR1 is the pointer to H[] ; arg2: T0 is the bin numbers of the FFT, N 	.global	_freqflt 	.sect	"fft_code" 	 _freqflt: pshm ST1_55 pshm ST3_55 sub #1,T0 mov T0,BRC0 ; Loop trip counter = N-1 mov #2,T0 ; Offset of H[] update bset SMUL bset SATD bset FRCT || rptblocal product_loop-1 ; for (i=0; i<N; i++) mpym *AR0+,*AR1+,AC1 ; AC1 = X[i].re * H[i].re masm *AR0-,*AR1,AC1 ; AC1 -= X[i].im * H[i].im mpym *AR0+,*AR1-,AC0 ; AC0 = X[i].re * H[i].im macm *AR0-,*(AR1+T0),AC0 ; AC0 += X[i].im * H[i].re mov rnd(hi(AC1)),*AR0+ ; X[i].re = AC1>>16 || neg AC0 ; X[i].im = -AC0>>16 mov rnd(hi(AC0)),*AR0+ product_loop popm ST3_55 popm ST1_55 	ret 	 .end </TEXTAREA></p>
</form>
<p style='margin-right:.5in;margin-left:.5in'> </p>
<p style='margin-right:1.0in;margin-left:1.0in'>The second routine <a
href="exp7/olap_add.asm"><span style='font-family:"Courier New"'>olap_add.asm</span></a><span
style='font-family:"Courier New"'> </span>is needed for the overlap-add method.
It is given in Table E7-12. For test, we also include several filter
coefficient files.</p>
<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'>Table
E7-12 Routine <span style='font-family:"Courier New"'>olap_add.asm</span></p>
<form>
<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="olap_add.asm">; ; olap_add.asm - Routine to perform overlap and add operation ; ; Protptye: void olap_add(complex *, int *, unsigned int, unsigned int, unsigned int); ; ; Entry: arg0: AR0 is the pointer to X[] ; arg1: AR1 is the pointer to OVRLAP[] ; arg2: T0 is the number of filter coefficients, L ; arg3: T1 is the number of data samples, M ; arg4: AR2 is the bin numbers of the FFT, N 	.global	_olap_add 	.sect	"fft_code" 	 _olap_add: sub #2,T0 mov T0,BRC0 ; BRC0 = L-2 mov T0,CSR ; CSR = L-2 mov XAR0,XAR4 mov XAR1,XAR3 || rptblocal olap_add-1 ; for (i=0; i<L-1; i++) mov dbl(*AR4),AC0 ; X[i].re += OVRLAP[i]; add *AR3+ <<#16,AC0 mov AC0,dbl(*AR4+) olap_add sfts T1,#1 add T1,AR0 mov #2,T0 || rpt CSR ; for (k=0, i=M; i<N; i++) mov *(AR0+T0),*AR1+ ; OVRLAP[k++] = X[i].re; ret .end 	 </TEXTAREA></p>
</form>
<p style='margin-right:.5in;margin-left:.5in'> </p>
<p style='margin-right:1.0in;margin-left:1.0in'>The experiment is conducted
using <a href="exp7/exp7d.c"><span style='font-family:"Courier New"'>exp7d.c</span></a>,
in Table E7-13.</p>
<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'>Table
E7-13 Fast convolution experiment</p>
<form>
<p align=center style='margin-right:.5in;margin-left:.5in;text-align:center'><TEXTAREA ROWS="7" COLS="70" NAME="exp7d.c">/* exp7d.c - Experiment for FFT convolution using Overlap-Add method */ #include "icomplex.h" #include "input7.dat" /* This is the data file used in Chapter 5 */ #define L 48 /* Filter length */ #define N 1024 /* FFT size, N >= L+M-1 */ #define EXP 10 /* MM = log2(N) */ #define M (N-L+1) /* Data sample length */ #pragma DATA_SECTION(U, "fft_twd"); #pragma DATA_SECTION(X, "fft_temp"); #pragma DATA_SECTION(H, "fft_coef"); #pragma DATA_SECTION(LP_h, "fft_coef"); #pragma DATA_SECTION(OVRLAP, "fft_in"); #pragma DATA_SECTION(re1, "fft_temp"); #pragma DATA_SECTION(re2, "fft_temp"); #pragma CODE_SECTION(main, "fft_code"); complex X[N]; /* Signal buffer */ complex H[N]; /* Frequency domain Filter */ complex U[N]; /* Twiddle e^(-j2pi/N) table */ int OVRLAP[L-1]; /* Frequency domain overlap buffer */ int re1[N],re2[N]; /* Low-pass FIR filter coefficients */ #include "firlp48.dat" /* This is the same filter used in Chaper 5 */ //#include "firlp8.dat" //#include "firlp16.dat" //#include "firlp32.dat" //#include "firlp64.dat" //#include "firlp128.dat" //#include "firlp256.dat" //#include "firlp512.dat" extern void fft(complex *, unsigned int, complex *, int); extern void bit_rev(complex *, unsigned int); extern void w_table(complex *, unsigned int); extern void olap_add(complex *, int *, unsigned int, unsigned int, unsigned int); extern void freqflt(complex *, complex *, unsigned int); main() { unsigned int i,j; /* Initialization */ for (i=0; i<L-1; i++) /* Initialize overlap buffer[L-1] */ OVRLAP[i] =0; for (i=0; i<L; i++) /* Copy filter coefficient to work buffer */ { X[i].re = LP_h[i]; X[i].im = 0; } for (i=i; i<N; i++) /* Fill zeros to the remaining work buffer */ { X[i].re = 0; X[i].im = 0; } w_table(U,EXP); /* Create Twiddle lookup table for FFT */ bit_rev(X,EXP); /* Bit reversal arrange the coefficient */ 	fft(X,EXP,U,1); /* FFT to the filter coefficients */ 	for (i=0; i<N; i++) /* Save frequency domain coefficients */ 	{ 	 H[i].re = X[i].re <<EXP; 	 H[i].im = X[i].im <<EXP; } 	 /* Start FFT Convolution test */ j=0; for (;;) { for (i=0; i<M; i++) { X[i].re = input[j++]; /* Generate input samples */ X[i].im = 0; re1[i] = X[i].re; /* Copy to reference buffer */ if (j==160) j=0; 	} 	 	for (i=i; i<N; i++) /* Fill zeros to data buffer */ { X[i].re = 0; X[i].im = 0; } 	 	 /* Start FFT convolution */ bit_rev(X,EXP); /* Arrange sample in bit reversal order */ fft(X,EXP,U,1); /* Perform FFT */ freqflt(X,H,N); /* Perform frequency domain filtering */ bit_rev(X,EXP); /* Arrange sample in bit reversal order */ fft(X,EXP,U,0); /* Perform IFFT */ olap_add(X,OVRLAP,L,M,N); /* Overlap and add algorithm */ /* end of FFT convolution */ for (i=0; i<M; i++) /* Save filtered data for reference */ { re2[i] = X[i].re; } } } </TEXTAREA></p>
</form>
<p style='margin-right:1.0in;margin-left:1.0in'> </p>
<p style='margin-right:1.0in;margin-left:1.0in'>For Experiment 7D, 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:l1 level1 lfo10;
tab-stops:list .5in'><![if !supportLists]>1.<span style='font:7.0pt "Times New Roman"'>
</span><![endif]>Create the project <span style='font-family:"Courier New"'>exp7d</span>,
and include <span style='font-family:"Courier New"'>exp7.cmd</span>, <span
style='font-family:"Courier New"'>exp7d.c</span>, <span style='font-family:
"Courier New"'>w_table.c</span>, <span style='font-family:"Courier New"'>fft.asm</span>,
<span style='font-family:"Courier New"'>bit_rev.asm</span>, <span
style='font-family:"Courier New"'>freqflt.asm</span>, <span style='font-family:
"Courier New"'>and olap_add.asm</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:l1 level1 lfo10;
tab-stops:list .5in'><![if !supportLists]>2.<span style='font:7.0pt "Times New Roman"'>
</span><![endif]>Build and verify the FFT convolution result, and compare the
filter result with Experiment 5A.</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:l1 level1 lfo10;
tab-stops:list .5in'><![if !supportLists]>3.<span style='font:7.0pt "Times New Roman"'>
</span><![endif]>Profile the run-time of the FFT fast convolution experiment
with various FIR filter lengths by using different filter coefficient file <span
style='font-family:"Courier New"'>firlp8.dat</span>, <span style='font-family:
"Courier New"'>firlp16.dat</span>, <span style='font-family:"Courier New"'>firlp32.dat</span>,
<span style='font-family:"Courier New"'>firlp64.dat</span>, <span
style='font-family:"Courier New"'>firlp128.dat</span>, <span style='font-family:
"Courier New"'>firlp256.dat</span>, and <span style='font-family:"Courier New"'>firlp512.dat</span>.
These files are included in the experimental software package.</p>
<p style='margin-right:1.0in;margin-left:1.0in'> </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><i><u><span style='font-size:7.5pt'>copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -