1、太原理工大学DSP课程设计正弦信号发生器程序:.asm .mmregs .def start .def d_xs,d_sinx,d_xc,d_cosx,sinx,cosxsin_x: .usect sin_x,360STACK: .usect STACK,10Hk_theta .set 286 ;theta=pi/360(0.5deg)start: .text STM #STACK+10H,SP STM k_theta,AR0 STM 0,AR1 STM #sin_x,AR6 STM #90,BRC RPTB loop1-1 LDM AR1,A LD #d_xs,DP STL A,d_xs S
2、TL A,d_xc CALL sinx ;d_sinx=sin(x) CALL cosx ;d_cosx=cos(x) LD #d_sinx,DP LD d_sinx,16,A ;A=sin(x) MPYA d_cosx ;B=sin(x)*cos(x) STH B,1,*AR6+ ;AR6-2*sin(x) MAR *AR1+0loop1: STM #sin_x+89, AR7 ;sin91(deg.)-sin179(deg.) STM #88,BRC RPTB loop2-1 LD *AR7-,A STL A,*AR6+loop2: STM #179,BRC ;sin180(deg.)-s
3、in359(deg.) STM #sin_x,AR7 RPTB loop3-1 LD *AR7+,A NEG A STL A,*AR6+loop3: STM #sin_x,AR6 ;generate sin wave STM #1,AR0 STM #360,BK B loop3sinx: .def d_xs,d_sinx .datatable_s .word 01C7H ;C1=1/(8*9) .word 030BH ;C2=1/(6*7) .word 0666H ;C3=1/(4*5) .word 1556H ;C4=1/(2*3)d_coef_s .usect coef_s,4d_xs .
4、usect sin_vars,1d_squr_xs .usect sin_vars,1d_temp_s .usect sin_vars,1d_sinx .usect sin_vars,1d_l_s .usect sin_vars,1 .text SSBX FRCT STM #d_coef_s,AR5 ;move coeffs table_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=x2 ST A,*AR2 ;(AR2)=x2
5、 |LD *AR4,B ;B=1 MASR *AR2+,*AR3+,B,A ;A=1-x2/72,T=x2 MPYA A ;A=T*A=x2(1-x2/72) STH A,*AR2 ;(d_temp)=x2(1-x2/72) MASR *AR2-,*AR3+,B,A ;A=1-x2/42(1-x2/72);T=x2(1-x2/72) MPYA *AR2+ ;B=x2(1-x2/42(1-x2/72) ST B,*AR2 ;(d_temp)=x2(1-x2/42(1-x2/72) |LD *AR4,B ;B=1 MASR *AR2-,*AR3+,B,A ;A=1-x2/20(1-x2/42(1-
6、x2/72) MPYA *AR2+ ;B=x2(1-x2/20(1-x2/42(1-x2/72) ST B,*AR2 ;(d_temp)=B |LD *AR4,B ;B=1 MASR *AR2-,*AR3+,B,A ;A=1-x2/6(1-x2/20(1-x2/42(1-x2/72) MPYA d_xs ;B=x(1-x2/6(1-x2/20(1-x2/42(1-x2/72) STH B,d_sinx ;sin(theta) RETcosx: .def d_xc,d_cosxd_coef_c .usect coef_c,4 .datatable_c .word 0249H ;C1=1/(7*8
7、) .word 0444H ;C2=1/(5*6) .word 0AABH ;C3=1/(3*4) .word 4000H ;C4=1/2d_xc .usect cos_vars,1d_squr_xc .usect cos_vars,1d_temp_c .usect cos_vars,1d_cosx .usect cos_vars,1c_l_c .usect cos_vars,1 .text SSBX FRCT STM #d_coef_c,AR5 ;move coeffs table_c RPT #3 MVPD #table_c,*AR5+ STM #d_coef_c,AR3 STM #d_x
8、c,AR2 STM #c_l_c,AR4 ST #7FFFH,c_l_c SQUR *AR2+,A ;A=x2 ST A,*AR2 ;(AR2)=x2 |LD *AR4,B ;B=1 MASR *AR2+,*AR3+,B,A ;A=1-x2/56,T=x2 MPYA A ;A=T*A=x2(1-x2/56) STH A,*AR2 ;(d_temp)=x2(1-x2/56) MASR *AR2-,*AR3+,B,A ;A=1-x2/30(1-x2/56); T=x2(1-x2/56) MPYA *AR2+ ;B=x2(1-x2/30(1-x2/56) ST B,*AR2 ;(d_temp)=x2
9、(1-x2/30(1-x2/56) |LD *AR4,B ;B=1 MASR *AR2-,*AR3+,B,A ;A=1-x2/12(1-x2/30(1-x2/56) SFTA A,-1,A ;-1/2 NEG A MPYA *AR2+ ;B=-x2/2(1-x2/12(1-x2/30(1-x2/56) MAR *AR2+ RETD ADD *AR4,16,B ;B=-x2/2(1-x2/12(1-x2/30(1-x2/56) STH B,*AR2 ;cos(theta) RET .endFFT变换:.c#include math.h#define sample_1 256#define sig
10、nal_1_f 60#define signal_2_f 200#define signal_sample_f 512#define pi 3.1415926int inputsample_1;float fwaversample_1,fwaveisample_1,wsample_1;float sin_tabsample_1;float cos_tabsample_1;void init_fft_tab();void input_data();void fft(float datarsample_1,float dataisample_1);void main() int i; init_f
11、ft_tab(); input_data(); for (i=0;isample_1;i+) fwaveri=inputi; fwaveii=0.0f; wi=0.0f; fft(fwaver,fwavei); while(1); void init_fft_tab() float wt1; float wt2; int i; for (i=0;isample_1;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; inputi=(cos(wt1)
12、+cos(wt2)/2*32768; void input_data() int i; for(i=0;isample_1;i+) sin_tabi=sin(2*pi*i/sample_1); cos_tabi=cos(2*pi*i/sample_1); void fft(float datarsample_1,float dataisample_1) int x0,x1,x2,x3,x4,x5,x6,x7,xx; int i,j,k,b,p,L; float TR,TI,temp; for(i=0;isample_1;i+) x0=x1=x2=x3=x4=x5=x6=0; x0=i&0x01
13、;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; dataixx=datari; for(i=0;isample_1;i+) datari=dataii;dataii=0; for(L=1;L0) b=b*2;i-; for(j=0;j0) p=p*2;i-; p=p*j; for(k=j;k256;k=k+2*b) TR=datark;T
14、I=dataik;temp=datark+b; datark=datark+datark+b*cos_tabp+dataik+b*sin_tabp; dataik=dataik-datark+b*sin_tabp+dataik+b*cos_tabp; datark+b=TR-datark+b*cos_tabp-dataik+b*sin_tabp; dataik+b=TI+temp*sin_tabp-dataik+b*cos_tabp; for(i=0;i=bufer_L)k=0;void inputwave()float wt1;float wt2;int i;for(i=0;i=bufer_
15、L)k=0;void inputwave()float wt1;float wt2;int i;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_ini=(cos(wt1)+cos(wt2)/2*32768;.asm .global _iir,_init,_outdata_iir bset frct sub #1,t0 mov t0,mmap(csr) add t0,ar0 mov xar2,xdp mov a
16、r2,cdp mov #0,ac0 rpt csr macmz *ar0-,*cdp+,ac0 add t0,ar1 mov xar3,xdp mov ar3,cdp rpt csr macmz *ar1-,*cdp+,ac0 mar *ar1+ mov hi(ac0),*ar1 mov hi(ac0),t0 bclr frct ret_init sub #1,t0 mov t0,mmap(csr) mov #0,ac0 rpt csr mov ac0,*ar0+ rpt csr mov ac0,*ar1+ ret_outdata mov t1,ac0 sub #2,ac0 mov ac0,mmap(csr) add ac0,ar0 rpt csr delay *ar0- mar *ar0+ mov t0,*ar0 ret
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1