|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
我在仿真RS码时用8PSK来进行调制,想对比分析一下,就换做QPSK调制。可是程序写出来,总不对,麻烦大家帮忙看一下,运行的时候提示这样的错误:
??? Attempted to access dsource1(21433); index out of bounds because numel(dsource1)=21432.
Error in ==> qpsk at 28
if((dsource1(i)==0)&(dsource2(i)==0))
程序如下:
function [channelout]=qpsk(input,No)
u=input.x;
sgma=sqrt(No);
%信号映射成qpsk
s00=[1 0];
s01=[0 1];
s11=[-1 0];
s10=[0 -1];
for i=1:length(u)
switch u(i)
case 0
dsource1(i)=0;
dsource2(i)=0;
case 1
dsource1(i)=0;
dsource2(i)=1;
case 2
dsource1(i)=1;
dsource2(i)=0;
case 3
dsource1(i)=1;
dsource2(i)=1;
end;
end;
%经过高斯信道
for i=1:length(u)
n=gngauss(sgma);
if((dsource1(i)==0)&(dsource2(i)==0))
r=s00+n;
elseif((dsource1(i)==0)&(dsource2(i)==1))
r=s01+n;
elseif((dsource1(i)==1)&(dsource2(i)==0))
r=s10+n;
else
r=s11+n;
end;
%计算互相关度
c00=dot(r,s00);
c01=dot(r,s01);
c10=dot(r,s10);
c11=dot(r,s11);
%对第i个符号进行判决
c_max=max([c00 c01 c10 c11 ]);
if(c00==c_max)
decis1(i)=0;
decis2(i)=0;
elseif(c01==c_max)
decis1(i)=0;
decis2(i)=1;
elseif(c10==c_max)
decis1(i)=1;
decis2(i)=0;
else
decis1(i)=1;
decis2(i)=1;
end;
end;
%映射成多进制信号
for i=1:length(u)
if((decis1(i)==0)&(decis2(i)==0))
channelout(i)=0;
elseif((decis1(i)==0)&(decis2(i)==1))
channelout(i)=1;
elseif((decis1(i)==1)&(decis2(i)==0))
channelout(i)=2;
else
channelout(i)=3;
end
end
[ 本帖最后由 eight 于 2007-5-14 15:02 编辑 ] |
|