1、matlab实验报告作业实验程序及图形1、 编写MATLAB函数文件仿真实现模拟信号的抽样过程1) 单频正弦波模拟信号的抽样实现;程序:function s1(A,F,P);Fs1=F;Fs2=2*F;Fs3=20*F;t11=0:1/Fs1:2/F;t12=0:1/Fs2:2/F;t13=0:1/Fs3:2/F;samp11=A*sin(2*pi*F*t11+P);samp12=A*sin(2*pi*F*t12+P);samp13=A*sin(2*pi*F*t13+P);subplot(311);plot(t11,samp11,b);xlabel(t);ylabel(samp11);subp
2、lot(312);plot(t12,samp12,y);xlabel(t);ylabel(samp12);subplot(313);plot(t13,samp13,g);xlabel(t);ylabel(samp13);波形图:2)多频正弦波合成模拟信号的抽样实现程序:function s2(A1,A2,F1,F2,P1,P2);Fs1=max(F1,F2);Fs2=2*max(F1,F2);Fs3=20*max(F1,F2);t21=0:1/Fs1:2/min(F1,F2);t22=0:1/Fs2:2/min(F1,F2);t23=0:1/Fs3:2/min(F1,F2);samp21=A1
3、*sin(2*pi*F1*t21+P1)+A2*sin(2*pi*F2*t21+P2);samp22=A1*sin(2*pi*F1*t22+P1)+A2*sin(2*pi*F2*t22+P2);samp23=A1*sin(2*pi*F1*t23+P1)+A2*sin(2*pi*F2*t23+P2);subplot(311);plot(t21,samp21,b);xlabel(t);ylabel(samp21);subplot(312);plot(t22,samp22,y);xlabel(t);ylabel(samp22);subplot(313);plot(t23,samp23,g);xlab
4、el(t);ylabel(samp23);波形图:2、 编写MATLAB程序仿真实现模拟信号的量化过程;1) 单频正弦波模拟信号均匀量化的实现程序:function c1(D,A,F,P)Fs=20*F;t=0:1/Fs:2/F;samp13=A*sin(2*pi*F*t+P);subplot(211);plot(t,samp13,b);xlabel(t);ylabel(samp13);hold onx=samp13./max(samp13);partition=-1:2/D:0.9;codebook=-1-1/D:2/D:1;indx,quant1=quantiz(x,partition,c
5、odebook);disp(indx1=,num2str(indx),.);hold onsubplot(212);plot(t,quant1,y); xlabel(t);ylabel(quant1);波形图:2)改变量化电平数,分析它和量化误差的关系,给出仿真图程序:function lianghua(A,F,P)D=0;Fs=20*F;t=0:1/Fs:2/F;samp13=A*sin(2*pi*F*t+P);x=samp13./max(samp13);subplot(3,4,1);plot(t,x,b);xlabel(t);ylabel(samp13);hold onpartition=
6、-1:2/D:0.9;codebook=(-1-1/D):2/D:1;indx,quant1=quantiz(x,partition,codebook);subplot(3,4,2)plot(t,quant1,g);xlabel(D=0);hold onD=1;partition=-1:2/D:0.9;codebook=(-1-1/D):2/D:1;indx,quant1=quantiz(x,partition,codebook);subplot(3,4,3)plot(t,quant1,g);xlabel(D=1);hold onD=3;partition=-1:2/D:0.9;codeboo
7、k=(-1-1/D):2/D:1;indx,quant1=quantiz(x,partition,codebook);subplot(3,4,4)plot(t,quant1,g);xlabel(D=3);hold onD=5;partition=-1:2/D:0.9;codebook=(-1-1/D):2/D:1;indx,quant1=quantiz(x,partition,codebook);subplot(3,4,5)plot(t,quant1,g);xlabel(D=5);hold onD=7;partition=-1:2/D:0.9;codebook=(-1-1/D):2/D:1;i
8、ndx,quant1=quantiz(x,partition,codebook);subplot(3,4,6)plot(t,quant1,g);xlabel(D=7);hold onD=9;partition=-1:2/D:0.9;codebook=(-1-1/D):2/D:1;indx,quant1=quantiz(x,partition,codebook);subplot(3,4,7)plot(t,quant1,g);xlabel(D=9);hold onD=11;partition=-1:2/D:0.9;codebook=(-1-1/D):2/D:1;indx,quant1=quanti
9、z(x,partition,codebook);subplot(3,4,8)plot(t,quant1,g);xlabel(D=11);hold onD=13;partition=-1:2/D:0.9;codebook=(-1-1/D):2/D:1;indx,quant1=quantiz(x,partition,codebook);subplot(3,4,9)plot(t,quant1,g);xlabel(D=13);hold onD=15;partition=-1:2/D:0.9;codebook=(-1-1/D):2/D:1;indx,quant1=quantiz(x,partition,
10、codebook);subplot(3,4,10)plot(t,quant1,g);xlabel(D=15);hold onD=17;partition=-1:2/D:0.9;codebook=(-1-1/D):2/D:1;indx,quant1=quantiz(x,partition,codebook);subplot(3,4,11)plot(t,quant1,g);xlabel(D=17);hold onD=19;partition=-1:2/D:0.9;codebook=(-1-1/D):2/D:1;indx,quant1=quantiz(x,partition,codebook);su
11、bplot(3,4,12)plot(t,quant1,g);xlabel(D=19);hold on图形:3)多频正弦波合成模拟信号均匀量化的实现程序:function c2(D,A1,A2,F1,F2,P1,P2)Fs=20*max(F1,F2);t3=0:1/Fs:2/min(F1,F2);samp23=A1*sin(2*pi*F*t3+P1)+A2*sin(2*pi*F*t3+P2);subplot(211);plot(t3,samp23,g);xlabel(t3);ylabel(samp23);hold onx=samp23./max(samp23);axis(0,0.01,-1,1,
12、1,1);partition=-1:2/D:0.9;codebook=-1-1/D:2/D:1;indx2,quant2=quantiz(x,partition,codebook);disp(indx2=,num2str(indx2),.);subplot(212);plot(t3,quant2,g);xlabel(t3);ylabel(quant2);图形:4)对抽样信号samp13归一化后进行满足A律和u律压缩的非均匀量化程序:function c3(D,A,F,P,a,u)Fs=20*F;t3=0:1/Fs:2/F;samp13=A*sin(2*pi*F*t3+P);subplot(41
13、1);plot(t3,samp13,g);xlabel(t);ylabel(samp13);x=samp13./max(samp13);subplot(412);plot(t3,x,g);xlabel(t);ylabel(samp13*);quant11=compand(x,a,1,A/compressor);quant12=compand(x,u,1,mu/compressor);partition=-1:2/D:0.9; codebook=-1-1/D:2/D:1;indx1,quant1=quantiz(x,partition,codebook);subplot(413);plot(t3
14、,quant11,k);xlabel(t);ylabel(quant11);subplot(414);plot(t3,quant12,b);xlabel(t);ylabel(quant12);end图形:3、 编写MATLAB程序仿真实现模拟喜好的编码过程;1) 单频正弦波模拟信号PCM二进制自然编码的实现程序:function p1(D,A,F,P)Fs=20*F;t13=0:1/Fs:2/F;samp13=A*sin(2*pi*F*t13+P);subplot(211);plot(t13,samp13,g);xlabel(t);ylabel(samp13);hold onx=samp13.
15、/max(samp13);partition=-1:2/D:0.9;codebook=-1-1/D:2/D:1;indx1,quant1=quantiz(x,partition,codebook);%量化电平数为D的均匀量化subplot(212);plot(t13,quant1,b);xlabel(t);ylabel(quant1);ind=dec2bin(indx1,4);ind=str2num(ind); indindx1end图形:自然编码:ind = 100010111101 1111 1000010000100001111110110111001110100101 0110100
16、110100010111101 1111100001000010000111111011011100111010010 101101001101000indx1 = Columns 1 through 17 8 11 13 15 16 16 16 15 13 11 9 6 4 2 1 0 1 Columns 18 through 34 2 4 6 8 11 13 15 16 16 16 15 13 11 9 6 4 2 Columns 35 through 41 1 0 1 2 4 6 82) 多频正弦波合成模拟信号PCM二进制自然编码的实现程序:function p2(D,A1,A2,F1,
17、F2,P1,P2)Fs=20*max(F1,F2);t23=0:1/Fs:2/min(F1,F2);samp23=A1*sin(2*pi*F1*t23+P1)+A2*sin(2*pi*F2*t23+P2);subplot(211);plot(t23,samp23,g);xlabel(t23);ylabel(samp23);hold onx=samp23./max(samp23);partition=-1:2/D:0.9;codebook=-1-1/D:2/D:1;indx2,quant2=quantiz(x,partition,codebook);subplot(212);plot(t23,q
18、uant2,b);xlabel(t3);ylabel(quant2);ind=dec2bin(indx2,4);ind=str2num(ind); indindx2end图形:自然编码:ind =1000101111011111100001000010000100001111110110111010100011010110110110111011110001010101111001100110011001011100111111010010101110100110100010111101111110000100001000010000111111011011101010001101011011
19、0110111011110001010101111001100110011001011100111111010010111110100110 1000 indx2 = Columns 1 through 17 8 11 13 15 16 16 16 16 15 13 11 10 8 6 5 5 5 Columns 18 through 34 5 6 7 8 10 11 12 12 12 12 11 9 7 6 4 2 1 Columns 35 through 51 0 1 1 2 4 6 8 11 13 15 16 16 16 16 15 13 11 Columns 52 through 68 10 8 6 5 5 5 5 6 7 8 10 11 12 12 12 12 11 Columns 69 through 81 9 7 6 4 2 1 1 1 1 2 4 6 8
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1