Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2009-05-09, 14:47   #1
fangfang0l
初级会员
 
注册日期: 2009-04-25
年龄: 38
帖子: 3
声望力: 0
fangfang0l 正向着好的方向发展
默认 求助

请问有谁懂这个程序我的程序水平是初级的,想一点点学着看,可是老师总体问我有关程序的算法的问题,还让我讲解这个程序,可我现在一点都不会怎么讲呀头都快四个大了,愁死我了。希望大家帮帮忙吧,帮我把每句话都详细解释一下好吗?讲一点也行,我看不懂,拜托各位了。
代码1clear all;
close all;
t = 0:0.01:10;
vm1 = -60: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));
endfigure(2)
plot(vm1,snrq);
axis([-60 0 0 60]);
grid;
代码2function 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;
elseif 32<=abs(x(i))&abs(x(i))<64
out(i,2)=0;out(i,3)=0;out(i,4)=1;step=2;st=32;
elseif 64<=abs(x(i))&abs(x(i))<128
out(i,2)=0;out(i,3)=1;out(i,4)=0;step=4;st=64;
elseif 128<=abs(x(i))&abs(x(i))<256
out(i,2)=0;out(i,3)=1;out(i,4)=1;step=8;st=128
elseif 256<=abs(x(i))&abs(x(i))<512
out(i,2)=1;out(i,3)=0;out(i,4)=0;step=16;st=256;
elseif 512<=abs(x(i))&abs(x(i))<1024
out(i,2)=1;out(i,3)=0;out(i,4)=1;step=32;st=512;
elseif 1024<=abs(x(i))&abs(x(i))<2048
out(i,2)=1;out(i,3)=1;out(i,4)=0;step=64;st=1024;
elseif 2048<=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);
代码3
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
fangfang0l 当前离线   回复时引用此帖
旧 2009-05-10, 12:00   #2
anbcjys
高级会员
 
注册日期: 2008-09-14
年龄: 43
帖子: 351
声望力: 24
anbcjys 正向着好的方向发展
默认 回复: 求助

这要根据你的问题来看 什么方面的?
__________________
qq604443022
anbcjys 当前离线   回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 19:36


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.