matlab实验报告作业.docx
《matlab实验报告作业.docx》由会员分享,可在线阅读,更多相关《matlab实验报告作业.docx(15页珍藏版)》请在冰豆网上搜索。
![matlab实验报告作业.docx](https://file1.bdocx.com/fileroot1/2023-3/30/1e24fd12-6c29-4c9e-b2f3-7dabdb6feb50/1e24fd12-6c29-4c9e-b2f3-7dabdb6feb501.gif)
matlab实验报告作业
实验程序及图形
1、编写MATLAB函数文件仿真实现模拟信号的抽样过程
1)单频正弦波模拟信号的抽样实现;
程序:
functions1(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');
subplot(312);plot(t12,samp12,'y');xlabel('t');ylabel('samp12');
subplot(313);plot(t13,samp13,'g');xlabel('t');ylabel('samp13');
波形图:
2)多频正弦波合成模拟信号的抽样实现
程序:
functions2(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*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');xlabel('t');ylabel('samp23');
波形图:
2、编写MATLAB程序仿真实现模拟信号的量化过程;
1)单频正弦波模拟信号均匀量化的实现
程序:
functionc1(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');
holdon
x=samp13./max(samp13);
partition=[-1:
2/D:
0.9];
codebook=[-1-1/D:
2/D:
1];
[indx,quant1]=quantiz(x,partition,codebook);
disp(['indx1=',num2str(indx),'.']);
holdon
subplot(212);
plot(t,quant1,'y');
xlabel('t');ylabel('quant1');
波形图:
2)改变量化电平数,分析它和量化误差的关系,给出仿真图
程序:
functionlianghua(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');
holdon
partition=[-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');
holdon
D=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');
holdon
D=3;
partition=[-1:
2/D:
0.9];
codebook=[(-1-1/D):
2/D:
1];
[indx,quant1]=quantiz(x,partition,codebook);
subplot(3,4,4)
plot(t,quant1,'g');
xlabel('D=3');
holdon
D=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');
holdon
D=7;
partition=[-1:
2/D:
0.9];
codebook=[(-1-1/D):
2/D:
1];
[indx,quant1]=quantiz(x,partition,codebook);
subplot(3,4,6)
plot(t,quant1,'g');
xlabel('D=7');
holdon
D=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');
holdon
D=11;
partition=[-1:
2/D:
0.9];
codebook=[(-1-1/D):
2/D:
1];
[indx,quant1]=quantiz(x,partition,codebook);
subplot(3,4,8)
plot(t,quant1,'g');
xlabel('D=11');
holdon
D=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');
holdon
D=15;
partition=[-1:
2/D:
0.9];
codebook=[(-1-1/D):
2/D:
1];
[indx,quant1]=quantiz(x,partition,codebook);
subplot(3,4,10)
plot(t,quant1,'g');
xlabel('D=15');
holdon
D=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');
holdon
D=19;
partition=[-1:
2/D:
0.9];
codebook=[(-1-1/D):
2/D:
1];
[indx,quant1]=quantiz(x,partition,codebook);
subplot(3,4,12)
plot(t,quant1,'g');
xlabel('D=19');
holdon
图形:
3)多频正弦波合成模拟信号均匀量化的实现
程序:
functionc2(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');
holdon
x=samp23./max(samp23);
axis([0,0.01,-1,1,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律压缩的非均匀量化
程序:
functionc3(D,A,F,P,a,u)
Fs=20*F;
t3=0:
1/Fs:
2/F;
samp13=A*sin(2*pi*F*t3+P);
subplot(411);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,quant11,'k');xlabel('t');ylabel('quant11');
subplot(414);plot(t3,quant12,'b');xlabel('t');ylabel('quant12');
end
图形:
3、编写MATLAB程序仿真实现模拟喜好的编码过程;
1)单频正弦波模拟信号PCM二进制自然编码的实现
程序:
functionp1(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');
holdon
x=samp13./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);
[ind]
[indx1]
end
图形:
自然编码:
ind=
1000
1011
1101
1111
10000
10000
10000
1111
1101
1011
1001
110
100
10
1
0
1
10
100
110
1000
1011
1101
1111
10000
10000
10000
1111
1101
1011
1001
110
100
10
1
0
1
10
100
110
1000
indx1=
Columns1through17
81113151616161513119642101
Columns18through34
24681113151616161513119642
Columns35through41
1012468
2)多频正弦波合成模拟信号PCM二进制自然编码的实现
程序:
functionp2(D,A1,A2,F1,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');
holdon
x=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,quant2,'b');xlabel('t3');ylabel('quant2');
ind=dec2bin(indx2,4);
ind=str2num(ind);
[ind]
[indx2]
end
图形:
自然编码:
ind=
1000
1011
1101
1111
10000
10000
10000
10000
1111
1101
1011
1010
1000
110
101
101
101
101
110
111
1000
1010
1011
1100
1100
1100
1100
1011
1001
111
110
100
10
1
0
1
1
10
100
110
1000
1011
1101
1111
10000
10000
10000
10000
1111
1101
1011
1010
1000
110
101
101
101
101
110
111
1000
1010
1011
1100
1100
1100
1100
1011
1001
111
110
100
10
1
1
1
1
10
100
110
1000
indx2=
Columns1through17
8111315161616161513111086555
Columns18through34
567810111212121211976421
Columns35through51
011246811131516161616151311
Columns52through68
1086555567810111212121211
Columns69through81
9764211112468