太原理工大学DSP课程设计.docx

上传人:b****8 文档编号:28143808 上传时间:2023-07-08 格式:DOCX 页数:15 大小:16.43KB
下载 相关 举报
太原理工大学DSP课程设计.docx_第1页
第1页 / 共15页
太原理工大学DSP课程设计.docx_第2页
第2页 / 共15页
太原理工大学DSP课程设计.docx_第3页
第3页 / 共15页
太原理工大学DSP课程设计.docx_第4页
第4页 / 共15页
太原理工大学DSP课程设计.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

太原理工大学DSP课程设计.docx

《太原理工大学DSP课程设计.docx》由会员分享,可在线阅读,更多相关《太原理工大学DSP课程设计.docx(15页珍藏版)》请在冰豆网上搜索。

太原理工大学DSP课程设计.docx

太原理工大学DSP课程设计

正弦信号发生器程序:

.asm

.mmregs

.defstart

.defd_xs,d_sinx,d_xc,d_cosx,sinx,cosx

sin_x:

.usect"sin_x",360

STACK:

.usect"STACK",10H

k_theta.set286;theta=pi/360(0.5deg)

start:

.text

STM#STACK+10H,SP

STMk_theta,AR0

STM0,AR1

STM#sin_x,AR6

STM#90,BRC

RPTBloop1-1

LDMAR1,A

LD#d_xs,DP

STLA,@d_xs

STLA,@d_xc

CALLsinx;d_sinx=sin(x)

CALLcosx;d_cosx=cos(x)

LD#d_sinx,DP

LD@d_sinx,16,A;A=sin(x)

MPYA@d_cosx;B=sin(x)*cos(x)

STHB,1,*AR6+;AR6----2*sin(x)

MAR*AR1+0

loop1:

STM#sin_x+89,AR7;sin91(deg.)-sin179(deg.)

STM#88,BRC

RPTBloop2-1

LD*AR7-,A

STLA,*AR6+

loop2:

STM#179,BRC;sin180(deg.)-sin359(deg.)

STM#sin_x,AR7

RPTBloop3-1

LD*AR7+,A

NEGA

STLA,*AR6+

loop3:

STM#sin_x,AR6;generatesinwave

STM#1,AR0

STM#360,BK

Bloop3

sinx:

.defd_xs,d_sinx

.data

table_s.word01C7H;C1=1/(8*9)

.word030BH;C2=1/(6*7)

.word0666H;C3=1/(4*5)

.word1556H;C4=1/(2*3)

d_coef_s.usect"coef_s",4

d_xs.usect"sin_vars",1

d_squr_xs.usect"sin_vars",1

d_temp_s.usect"sin_vars",1

d_sinx.usect"sin_vars",1

d_l_s.usect"sin_vars",1

.text

SSBXFRCT

STM#d_coef_s,AR5;movecoeffstable_s

RPT#3

MVPD#table_s,*AR5+

STM#d_coef_s,AR3

STM#d_xs,AR2

STM#d_l_s,AR4

ST#7FFFH,d_l_s

SQUR*AR2+,A;A=x^2

STA,*AR2;(AR2)=x^2

||LD*AR4,B;B=1

MASR*AR2+,*AR3+,B,A;A=1-x^2/72,T=x^2

MPYAA;A=T*A=x^2(1-x^2/72)

STHA,*AR2;(d_temp)=x^2(1-x^2/72)

MASR*AR2-,*AR3+,B,A;A=1-x^2/42(1-x^2/72);T=x^2(1-x^2/72)

MPYA*AR2+;B=x^2(1-x^2/42(1-x^2/72))

STB,*AR2;(d_temp)=x^2(1-x^2/42(1-x^2/72))

||LD*AR4,B;B=1

MASR*AR2-,*AR3+,B,A;A=1-x^2/20(1-x^2/42(1-x^2/72))

MPYA*AR2+;B=x^2(1-x^2/20(1-x^2/42(1-x^2/72)))

STB,*AR2;(d_temp)=B

||LD*AR4,B;B=1

MASR*AR2-,*AR3+,B,A;A=1-x^2/6(1-x^2/20(1-x^2/42(1-x^2/72)))

MPYAd_xs;B=x(1-x^2/6(1-x^2/20(1-x^2/42(1-x^2/72))))

STHB,d_sinx;sin(theta)

RET

cosx:

.defd_xc,d_cosx

d_coef_c.usect"coef_c",4

.data

table_c.word0249H;C1=1/(7*8)

.word0444H;C2=1/(5*6)

.word0AABH;C3=1/(3*4)

.word4000H;C4=1/2

d_xc.usect"cos_vars",1

d_squr_xc.usect"cos_vars",1

d_temp_c.usect"cos_vars",1

d_cosx.usect"cos_vars",1

c_l_c.usect"cos_vars",1

.text

SSBXFRCT

STM#d_coef_c,AR5;movecoeffstable_c

RPT#3

MVPD#table_c,*AR5+

STM#d_coef_c,AR3

STM#d_xc,AR2

STM#c_l_c,AR4

ST#7FFFH,c_l_c

SQUR*AR2+,A;A=x^2

STA,*AR2;(AR2)=x^2

||LD*AR4,B;B=1

MASR*AR2+,*AR3+,B,A;A=1-x^2/56,T=x^2

MPYAA;A=T*A=x^2(1-x^2/56)

STHA,*AR2;(d_temp)=x^2(1-x^2/56)

MASR*AR2-,*AR3+,B,A;A=1-x^2/30(1-x^2/56);T=x^2(1-x^2/56)

MPYA*AR2+;B=x^2(1-x^2/30(1-x^2/56))

STB,*AR2;(d_temp)=x^2(1-x^2/30(1-x^2/56))

||LD*AR4,B;B=1

MASR*AR2-,*AR3+,B,A;A=1-x^2/12(1-x^2/30(1-x^2/56))

SFTAA,-1,A;-1/2

NEGA

MPYA*AR2+;B=-x^2/2(1-x^2/12(1-x^2/30(1-x^2/56)))

MAR*AR2+

RETD

ADD*AR4,16,B;B=-x^2/2(1-x^2/12(1-x^2/30(1-x^2/56)))

STHB,*AR2;cos(theta)

RET

.end

FFT变换:

..c

#include"math.h"

#definesample_1256

#definesignal_1_f60

#definesignal_2_f200

#definesignal_sample_f512

#definepi3.1415926

intinput[sample_1];

floatfwaver[sample_1],fwavei[sample_1],w[sample_1];

floatsin_tab[sample_1];

floatcos_tab[sample_1];

voidinit_fft_tab();

voidinput_data();

voidfft(floatdatar[sample_1],floatdatai[sample_1]);

voidmain()

{

inti;

init_fft_tab();

input_data();

for(i=0;i

{

fwaver[i]=input[i];

fwavei[i]=0.0f;

w[i]=0.0f;

}

fft(fwaver,fwavei);

while

(1);

}

voidinit_fft_tab()

{

floatwt1;

floatwt2;

inti;

for(i=0;i

{

wt1=2*pi*i*signal_1_f;

wt1=wt1/signal_sample_f;

wt2=2*pi*i*signal_2_f;

wt2=wt2/signal_sample_f;

input[i]=(cos(wt1)+cos(wt2))/2*32768;

}

}

voidinput_data()

{

inti;

for(i=0;i

{

sin_tab[i]=sin(2*pi*i/sample_1);

cos_tab[i]=cos(2*pi*i/sample_1);

}

}

voidfft(floatdatar[sample_1],floatdatai[sample_1])

{

intx0,x1,x2,x3,x4,x5,x6,x7,xx;

inti,j,k,b,p,L;

floatTR,TI,temp;

for(i=0;i

{

x0=x1=x2=x3=x4=x5=x6=0;

x0=i&0x01;x1=(i/2)&0x01;x2=(i/4)&0x01;x3=(i/8)&0x01;

x4=(i/16)&0x01;x5=(i/32)&0x01;x6=(i/64)&0x01;x7=(i/128)&0x01;

xx=x0*128+x1*64+x2*32+x3*16+x4*8+x5*4+x6*2+x7;

datai[xx]=datar[i];

}

for(i=0;i

{

datar[i]=datai[i];datai[i]=0;

}

for(L=1;L<=8;L++)

{

b=1;i=L-1;

while(i>0)

{

b=b*2;i--;

}

for(j=0;j<=b-1;j++)

{

p=1;i=8-L;

while(i>0)

{

p=p*2;i--;

}

p=p*j;

for(k=j;k<256;k=k+2*b)

{

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];

}

}

}

for(i=0;i

{

w[i]=sqrt(datar[i]*datar[i]+datai[i]*datai[i]);

}

}

.asm

.global_fir,_init,_B,_outdata

_fir

bsetfrct

amov#_B,xdp

mov#_B,cdp

movt0,ac0

sub#1,ac0

movac0,mmap(csr)

addac0,ar0

mov#0,ac0

rptcsr

macmz*ar0-,*cdp+,ac0

movhi(ac0),t0

ret

_init

movmmap(t0),ac0

sub#1,ac0

movac0,ar7

rptzac0,ar7

movac0,*ar0+

ret

_outdata

movt1,ac0

sub#2,ac0

movac0,mmap(csr)

addac0,ar0

rptcsr

delay*ar0-

mar*ar0+

movt0,*ar0

ret

FIR滤波器:

.c

#include"s.h"

#include"math.h"

#definesignal_1_f200

#definesignal_2_f620

#definesignal_sample_f2000

#definepi3.1415926

#definecoff_L23

#definebufer_L256

intdata_in[bufer_L];

intout[bufer_L];

intfirout;

intx[coff_L+1];

intk=0;

intbufer=bufer_L;

externintfir(int*,int);

externintinit(int*,int);

externintoutdata(int*,int,int);

voidinputwave();

voidmain()

{

inputwave();

init(x,BL);

while

(1)

{

x[0]=data_in[k];

firout=fir(x,BL);

outdata(out,firout,bufer);

k++;

if(k>=bufer_L)

{

k=0;

}

}

}

voidinputwave()

{

floatwt1;

floatwt2;

inti;

for(i=0;i<=bufer_L;i++)

{

wt1=2*pi*i*signal_1_f;

wt1=wt1/signal_sample_f;

wt2=2*pi*i*signal_2_f;

wt2=wt2/signal_sample_f;

data_in[i]=(cos(wt1)+cos(wt2))/2*32768;

}

}

IIR滤波器:

.c

#include"math.h"

#definesignal_1_f500

#definesignal_2_f10000

#definesignal_sample_f25000

#definepi3.1415926

#defineIIRNUMBER_L2

#definebufer_L256

intN_L=IIRNUMBER_L;

intdata_in[bufer_L];

intout[bufer_L];

intx[IIRNUMBER_L+1];

inty[IIRNUMBER_L+1];

intk=0;

intbufer=bufer_L;

intfBn[IIRNUMBER_L]={0,0x634a};

intfAn[IIRNUMBER_L]={0xe5c,0xe5c};

externintiir(int*x,int*y,int*fAn,int*fBn,intN_L);

externintinit(int*,int*,int);

externintoutdata(int*,int,int);

voidinputwave();

voidmain()

{

intiirout;

inputwave();

init(x,y,N_L);

while

(1)

{

x[0]=data_in[k];

iirout=iir(x,y,fAn,fBn,N_L);

outdata(out,iirout,bufer);

k++;

if(k>=bufer_L)

{

k=0;

}

}

}

voidinputwave()

{

floatwt1;

floatwt2;

inti;

for(i=0;i<=bufer_L;i++)

{

wt1=2*pi*i*signal_1_f;

wt1=wt1/signal_sample_f;

wt2=2*pi*i*signal_2_f;

wt2=wt2/signal_sample_f;

data_in[i]=(cos(wt1)+cos(wt2))/2*32768;

}

}

.asm

.global_iir,_init,_outdata

_iir

bsetfrct

sub#1,t0

movt0,mmap(csr)

addt0,ar0

movxar2,xdp

movar2,cdp

mov#0,ac0

rptcsr

macmz*ar0-,*cdp+,ac0

addt0,ar1

movxar3,xdp

movar3,cdp

rptcsr

macmz*ar1-,*cdp+,ac0

mar*ar1+

movhi(ac0),*ar1

movhi(ac0),t0

bclrfrct

ret

_init

sub#1,t0

movt0,mmap(csr)

mov#0,ac0

rptcsr

movac0,*ar0+

rptcsr

movac0,*ar1+

ret

_outdata

movt1,ac0

sub#2,ac0

movac0,mmap(csr)

addac0,ar0

rptcsr

delay*ar0-

mar*ar0+

movt0,*ar0

ret

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 家庭教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1