嵌入式系统设计报告英文含代码Word文档格式.docx
《嵌入式系统设计报告英文含代码Word文档格式.docx》由会员分享,可在线阅读,更多相关《嵌入式系统设计报告英文含代码Word文档格式.docx(11页珍藏版)》请在冰豆网上搜索。
![嵌入式系统设计报告英文含代码Word文档格式.docx](https://file1.bdocx.com/fileroot1/2022-12/16/d6a0bf97-5ab8-45fe-82da-7cb38500e436/d6a0bf97-5ab8-45fe-82da-7cb38500e4361.gif)
5.CoreCodeandExplanationofSystem
Thecodeofthesystemislistedasfollows:
//record.crecord/playinputusingexternalmemory
#include<
stdio.h>
#include"
math.h"
dsk6416_aic23.h"
//codecsupport
Uint32fs=DSK6416_AIC23_FREQ_8KHZ;
//setsamplingrate
Uint16inputsource=DSK6416_AIC23_INPUT_MIC;
//selectinput
unsignedlongi,count,s;
shortbuffer[N];
shortbuffer1[SAMPLENUMBER];
longm;
floatmax;
voidInitForFFT();
intINPUT[SAMPLENUMBER],DATA[SAMPLENUMBER];
floatfWaveR[SAMPLENUMBER],fWaveI[SAMPLENUMBER],w[SAMPLENUMBER];
floatsin_tab[SAMPLENUMBER],cos_tab[SAMPLENUMBER];
#pragmaDATA_SECTION(buffer,"
.EXT_RAM"
)//buffer->
externalmemory
voidmain()
{
intq,t,n,m,l,tt=0;
shortplaying=0;
DSK6416_DIP_init();
DSK6416_LED_init();
comm_poll();
//initDSK,codec,McBSP
InitForFFT();
count=0;
while
(1)//infiniteloop
{
if(DSK6416_DIP_get(3)==0)//ifSW#3ispressed
{
DSK6416_LED_on(3);
//turnonLED#3
buffer[count++]=input_left_sample();
}
if(DSK6416_DIP_get(3)==1||(count>
=N-1))//ifSW#3ispressed
DSK6416_LED_off(3);
}
if(DSK6416_DIP_get(0)==0)//ifSW#0pressed
playing=1;
while(playing==1)
DSK6416_LED_on(0);
//turnonLED#0
output_left_sample(buffer[count++]);
if(count>
=N-1)
DSK6416_LED_off(0);
for(s=50;
s<
N/SAMPLENUMBER;
s++)
n=0;
for(l=SAMPLENUMBER*(s-1);
l<
s*512;
l++)
{
n=l-SAMPLENUMBER*(s-1);
buffer1[n]=buffer[l];
for(q=0;
q<
SAMPLENUMBER;
q++)
fWaveR[q]=buffer1[q];
fWaveI[q]=0.0f;
FFT(fWaveR,fWaveI);
max=w[0];
m=0;
for(t=0;
t<
SAMPLENUMBER/2;
t++)
{
if(max<
w[t])
{
max=w[t];
m=t;
}
}
}//for(l=SAMPLENUMBER*(s-1);
tt=m*8000/SAMPLENUMBER;
if(tt>
=1046&
&
tt<
=1975)
{DSK6416_LED_on
(1);
DSK6416_LED_on
(2);
}
elseif(tt>
513)DSK6416_LED_on
(2);
0)DSK6416_LED_on
(1);
else
DSK6416_LED_on(3);
DSK6416_LED_on
(1);
if(tt>
25)
printf("
%d\n"
tt);
DSK6416_LED_off
(1);
DSK6416_LED_off
(2);
DSK6416_LED_off(3);
}//for(s=1;
}//if(count>
}//while(playing==1)
playing=0;
}//if(DSK6416_DIP_get(0)==0)
}//while
(1)
}//main
voidFFT(floatdataR[SAMPLENUMBER],floatdataI[SAMPLENUMBER])
intx0,x1,x2,x3,x4,x5,x6,x7,x8,xx;
inti,j,k,b,p,L;
floatTR,TI,temp;
/**********followingcodeinvertsequence************/
for(i=0;
i<
i++)
x0=x1=x2=x3=x4=x5=x6=x7=x8=0;
x0=i&
0x01;
x1=(i/2)&
x2=(i/4)&
x3=(i/8)&
x4=(i/16)&
x5=(i/32)&
x6=(i/64)&
x7=(i/128)&
x8=(i/256)&
//x=x0*1024+x1*512+x2*256+x3*128+x4*64+x5*32+x6*16+x7*8+x8*4+x9*2+x10;
xx=x0*256+x1*128+x2*64+x3*32+x4*16+x5*8+x6*4+x7*2+x8;
dataI[xx]=dataR[i];
dataR[i]=dataI[i];
dataI[i]=0;
/**************followingcodeFFT*******************/
for(L=1;
L<
=9;
L++)
{/*for
(1)*/
b=1;
i=L-1;
while(i>
0)
b=b*2;
i--;
}/*b=2^(L-1)*/
for(j=0;
j<
=b-1;
j++)/*for
(2)*/
p=1;
i=9-L;
while(i>
0)/*p=pow(2,7-L)*j;
*/
p=p*2;
p=p*j;
for(k=j;
k<
k=k+2*b)/*for(3)*/
TR=dataR[k];
TI=dataI[k];
temp=dataR[k+b];
dataR[k]=dataR[k]+dataR[k+b]*cos_tab[p]+dataI[k+b]*sin_tab[p];
dataI[k]=dataI[k]-dataR[k+b]*sin_tab[p]+dataI[k+b]*cos_tab[p];
dataR[k+b]=TR-dataR[k+b]*cos_tab[p]-dataI[k+b]*sin_tab[p];
dataI[k+b]=TI+temp*sin_tab[p]-dataI[k+b]*cos_tab[p];
}/*ENDfor(3)*/
}/*ENDfor
(2)*/
}/*ENDfor
(1)*/
w[i]=sqrt(dataR[i]*dataR[i]+dataI[i]*dataI[i]);
}/*ENDFFT*/
Firstly,Isetthesamplingfruquencyas8Khz,andthetotalbuffernumberis512000whichmeansthatitcanrecordthevoiceaslongas64seconds.Thecoreofthecodeincludesthreeparts.Oneistherecordingpart,andthesecondisplayingpart,andthethirdistheFFTanalysispart.WhiletheDSPchipdetecttheswitchthreewaspressed,thenrecordingstarts.Recordingisaccomplishedbythefuctioncalledinput_sample.,whichcancompletetheADsamplingandstorethesampledvalueintobuffer.LEDthreewillturnoffwhilethebufferhasbeenfilledortheswitchthreeisuplifted.Thenifyoupressswitchzero,thenplayingstarts,whichcanpalywhathasbeenrecorded.Andtheplayingpartisaccomplishedbythefunctioncalledoutput_sample,whichcanreadthediscretevalueinthebufferandturnintoanalogyspeechsignal.Afterthepalyingisover,LEDzerowillturnoff,andLEDonewillturnonindicatingthatFFTwiththeradix-2analysisbegins.FFTalgorithmcomputingisaccomplishedbylookinguptotable,andthetableismadeupbythesinefunctionandcosinefuction,wewillgettherealandimaginarypartsofmagnitudes.Andthenbythewayofergodicalgorithmtofindtheaccuratenumberoflocationofthemaxmummagnitude.Wewillgetthefrequencybyequationof
AftertheFFTfinished,LEDonewillturnoff,andthespeechsignalspectrumanalyzerhasfulfilledallfunction.
6.DebuggingRecordingofSystemandTestingIllustration
Eachtime,FFTanalyze512points.SoIdividethewholebufferintolotsoflittlebuffercontaining512points.Thedebuggingprocessingmainlydependsonthelocationofbreakpoints.IsetthebreakpointinthelocationofFFTanalyzeofeachlittlebuffercalledbuffer1,andwhenthecodeexecutethelo