Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
初级会员
注册日期: 2009-04-25
年龄: 38
帖子: 3
声望力: 0 ![]() |
![]()
一道MATLAB题 请问这个少了什么
设输入信号为 x(t)=Acsin2Лt,对x(t)信号进行抽样、量化和A律PCM编码,经过传输后,接收端进行PCM译码。 画出经过PCM编码、译码后的波形与未编码波形; 设信道没有误码,画出不同Ac情况下,PCM译码后的量化信噪比。 解:仿真的系统框图如图所示。 图为A律PCM量化器的动态范围仿真框图 %show the pcm encode and decode clear all; close all; t = 0:0.01:10; vm1 = -70:1:0; %输入的正弦信号幅度不同 vm = 10.^(vm1/20); figure(1) for k = 1:length(vm) for m = 1:2 x = vm (k)*sin(2*pi*t+2*pi*rand(1)); v = 1; xx = x/v;%normalize sxx = floor(xx*4096); y = pcm_encode(sxx); yy = pcm_decode(y,v); nq(m) = sum((x-yy).*(x-yy))/length(x); sq(m) = mean(yy.^2); snr(m) = (sq(m)/nq(m)); drawnow subplot(211) plot(t,x); title('sample sequence'); subplot(212) plot(t,yy) title('pcm decode sequence'); end snrq(k)=10*log10(mean(snr)); end figure(2) plot(vm1,snrq); grid; function [out]=pcm_encode(x) %x encode to pcm code n=length(x); %-4096<x<4096 for i = 1:n if x(i)>0 out(i,1)=1; else out(i,1)=0; end if abs (x(i))> = 0 & abs(x(i))<32 out(i,2)=0;out(i,3)=0;out(i,4)=0;step=2;st=0; elseif32<=abs(x(i))&abs(x(i))<64 out(i,2)=0;out(i,3)=0;out(i,4)=1;step=2;st=32; elseif64<=abs(x(i))&abs(x(i))<128 out(i,2)=0;out(i,3)=1;out(i,4)=0;step=4;st=64; elseif128<=abs(x(i))&abs(x(i))<256 out(i,2)=0;out(i,3)=1;out(i,4)=1;step=8;st=128 elseif256<=abs(x(i))&abs(x(i))<512 out(i,2)=1;out(i,3)=0;out(i,4)=0;step=16;st=256; elseif512<=abs(x(i))&abs(x(i))<1024 out(i,2)=1;out(i,3)=0;out(i,4)=1;step=32;st=512; elseif1024<=abs(x(i))&abs(x(i))<2048 out(i,2)=1;out(i,3)=1;out(i,4)=0;step=64;st=1024; elseif2048<=abs(x(i))&abs(x(i))<4096 out(i,2)=1;out(i,3)=1;out(i,4)=1;step=128;st=2048; else out(i,2)=1;out(i,3)=1;out(i,4)=1;step=128;st=2048; end if(abs(x(i))&abs(x(i)))<4096 out(I,2:8)=[1 1 1 1 1 1 1]; else tmp=floor((abs(x(i))-st)/step); t=dec2bin(tmp,4)-48;%函数dec2bin输出的是ASCII字符串,48对应0 out(i,5:8)=t(1:4); end end out=reshape(out',1,8*n); function[out]= pcm_decode(in,v) %decode the input pcm code %in : input the pcm code 8 bits sample %v:quantized level n=length(in); in=reshape(in',8,n/8)'; slot(1)=0; slot(2)=32; slot(3)=64; slot(4)=128; slot(5)=256; slot(6)=512; slot(7)=1024; slot(8)=2048; step(1)=2; step(2)=2; step(3)=4; step(4)=8; step(5)=16; step(6)=32; step(7)=64; step(8)=128; for i=1:n/8 ss=2*in(i,1)-1; tmp = in(i,2)*4+in(i,3)*2+in(i,4)+1; st = slot(tmp); dt = (in(i,5)*8+in(i,6)*4+in(i,7)*2+in(i,8))*step(tmp)+0.5*step(tmp); out(i)=ss*(st+dt)/4096*v; end |
![]() |
![]() |
![]() |
#2 |
高级会员
注册日期: 2008-11-01
年龄: 39
帖子: 406
声望力: 26 ![]() |
![]()
lz 没有理解你的意思? 你指的是什么? 代码少了? 还是操作少了?
能否说的清楚一些 大家一起讨论一下 |
![]() |
![]() |
![]() |
#3 |
初级会员
注册日期: 2009-04-25
年龄: 38
帖子: 3
声望力: 0 ![]() |
![]()
我问过老师 他说还少个程序,但我看不出来少什么,那里少,请各位高手帮我看看
|
![]() |
![]() |
![]() |
#4 |
初级会员
注册日期: 2009-04-20
帖子: 2
声望力: 0 ![]() |
![]()
不好意思 我也是提问 的!
a=[1 2 3] for i=1:3 b=abs(a(i)) end 这段程序为什么保存在m文件中不能运行啊! |
![]() |
![]() |
![]() |
#5 |
初级会员
注册日期: 2009-04-20
帖子: 2
声望力: 0 ![]() |
![]()
请问在那里发表新帖?
thanks |
![]() |
![]() |
![]() |
#6 |
高级会员
注册日期: 2008-11-01
年龄: 39
帖子: 406
声望力: 26 ![]() |
![]()
2楼及3楼 根据问题的性质 在各区页面的左下角有“发表新主题” 点击后 完成你发的主题
Thx for reading. PS:若还算满意,直接点击“Thanks”,再次登陆时亦便于查看回答是否真的帮到你了。 个人观点 仅供参考 多多交流 相互学习 |
![]() |
![]() |
![]() |
#7 |
高级会员
注册日期: 2008-11-01
年龄: 39
帖子: 406
声望力: 26 ![]() |
![]()
lz 请把你的框图贴出来可以么?
我再看一下 谢谢 |
![]() |
![]() |