フィルターのクリア

how to mix the result of 3 programs (3 curves) in a single figure contains all of these curves?

1 回表示 (過去 30 日間)
the first program :
l=100000; %L length of si the input one dimension array
nni=randn(1,l);%generate L by L array of random scalare
si=randsrc(1,l,[+1,-1;.5,.5]);%generate 1 by L array of -1&+1
snr=[0:15];
for i=1:16
errorcounter=0;
stdn=sqrt(10^(-snr(i)/10))
ni=nni*stdn;% ni is 1 by L dimension
for m=1:l
ri(m)=ni(m)+si(m);
if ri(m)>0
sdi(m)=1;
elseif ri(m)<=0
sdi(m)=-1;
end
if sdi(m)~=si(m)
errorcounter=errorcounter+1;
end
end
ber(i)=errorcounter/l
end
semilogy(snr,ber,'r') xlabel('snr db');ylabel('ber');grid;
the second program :
L=100000;
n=3;
input=rand(1,L)>0.5; %generate a 1 by L matrix of 0,1
out=reshape(repmat(input,n,1),1,[]); %repeat each bit 3 times in row and 1 bit in col ENCODING
for i=1:(n*L)
if out(i)==1
si(i)=1;
else si(i)=-1;
end
end %******* mapping to -1 , +1 Si is 1 BY 3L
nni=randn(1,n*L); %generate 1 by 3L random psn matrix
snr=[0:15]
for b=1:16
errorcounter=0;
stdn=sqrt(10^(-snr(b)/10));
ni=nni*stdn;
for m=1:(n*L)
ri(m)=ni(m)+si(m);
if ri(m)>0
sdi(m)=1;
output(m)=1;
else sdi(m)=-1;
output(m)=0;
end
end
for hh=1:n:n*L
z=0;o=0;
for h=hh:hh+n-1
if output(h)==0
z=z+1;
else o=o+1;
end
end
if z>o output(hh)=0;
else output(hh)=1;
end
end
a=reshape(output,n,L);
bb=a(1,:);
for w=1:L
if bb(w)~=input(w)
errorcounter=errorcounter+1;
end
end
ber(b)=errorcounter/L;
end
semilogy(snr,ber)
xlabel('snr');ylabel('ber');grid;
the 3rd program is:
%% TCM PROGRAM
a=1/(2^(1/2));
arr=[0 0 0 0 0 0 0 0 0 1 0;0 1 0 0 1 0 0 1 0 0 1;1 0 0 0 0 0 1 0 0 -1 0;1 1 0 0 1 0 1 1 0 0 -1;0 0 0 1 0 0 0 1 0 0 1;0 1 0 1 1 0 0 0 0 1 0;1 0 0 1 0 0 1 1 0 0 -1;1 1 0 1 1 0 1 0 0 -1 0;0 0 1 0 0 1 0 0 1 a a;0 1 1 0 1 1 0 1 1 -a a;1 0 1 0 0 1 1 0 1 -a -a;1 1 1 0 1 1 1 1 1 a -a;0 0 1 1 0 1 0 1 1 -a a;0 1 1 1 1 1 0 0 1 a a;1 0 1 1 0 1 1 1 1 a -a;1 1 1 1 1 1 1 0 1 -a -a];
costs=[1 1 2 2 3 3 4 4 1 1 2 2 3 3 4 4];
newdata=[0 2 0 2 0 2 0 2 1 3 1 3 1 3 1 3];
ARR=[0 0 1 0 0;1 0 0 1 2;2 0 -1 0 0;3 0 0 -1 2;0 1 0 1 0;1 1 1 0 2;2 1 0 -1 0;3 1 -1 0 2;0 2 a a 1;1 2 -a a 3;2 2 -a -a 1;3 2 a -a 3;0 3 -a a 1;1 3 a a 3;2 3 a -a 1;3 3 -a -a 3];
L=100000;
snr=[0:15];
for SNR =1:16
stdn=sqrt((1/4)*10^(-snr(SNR)/10));
transmitted=[];
nstate1=0;
nstate2=0;
REAL=[];
IMAGINARY=[];
for i=1:L
input=randi(2,1,2)-1; % 2 is max num , 1 row , 2 col. will generate array 1x2 with numbers from 1 to 2, to make it from 0 to 1
transmitted=[transmitted,input];
pstate1=nstate1;
pstate2=nstate2;
for i=1:16
if (arr(i,1)==input(1,1)) && (arr(i,2)==input(1,2)) && (arr(i,3)==pstate1) && (arr(i,4)==pstate2)
ii = i;
end
end
nstate1=arr(ii,5);
nstate2=arr(ii,6);
sireal=arr(ii,10);
siimag=arr(ii,11);
REAL=[REAL,sireal];
IMAGINARY=[IMAGINARY,siimag];
end
si=complex(REAL,IMAGINARY);
nni=complex(randn(1,L),randn(1,L));
ni=nni*stdn;
ri = ni + si;
decoded=[]; % decoding
vec=zeros(4,8);
vecc=zeros(16,8);
prstate=zeros(4,1); % true present state of next state
cost(1)=0;
cost(2:4)=20;
for m = 1:L
for states = 1:4
for curstate = 1:4 %%expanding from 4 to 16 vectors
k =(states-1)*4 + curstate ;
vecost=costs(k);
vecc(k,1:7)=vec(vecost,1:7);
vecc(k,8)=newdata(k);
initcost(k)=cost(costs(k));
prstate(k)=costs(k) - 1;
for z = 1:16
if ARR(z,1) == vecc(k,8) && ARR(z,2) == prstate(k)
rreal=ARR(z,3);
iimaginary=ARR(z,4);
end
end
ed = sqrt((real(ri(m))-rreal)^2 + (imag(ri(m))-iimaginary)^2);
mycost(k)=initcost(k)+ ed; %%16 costs
end
end
for n=1:4 %%from 16 vectors to 4 vectors
nn=(n-1)*4+1:(n-1)*4+4;
[costt,iindex]=min(mycost(nn));
TrueVector = iindex +(n-1)*4 ;
vec(n,1:7)=vecc(TrueVector,2:8);
cost(n)=mycost(TrueVector);
end
if m>6
[final_mincost,indexx]=min(cost); %%choosing the vector of the minimum cost
decimal=vec(indexx,1);
decoded=[decoded,decimal];
for i=1:4
cost(i)=cost(i)-final_mincost; %%this will make my chosen vector's cost=0
end
end
end
DATA=[];
for kk=1:length(decoded)
binary=de2bi(decoded(kk),2,'left-msb');
DATA=[DATA,binary];
end
errorcounter=0;
for o=1:(length(transmitted)-2*6)
if transmitted(o)~=DATA(o);
errorcounter=errorcounter+1;
end
end
ber(SNR)=errorcounter/(2*(L-6));
end
semilogy(snr,ber) grid;xlabel('SNR');ylabel('BER');

採用された回答

Image Analyst
Image Analyst 2013 年 2 月 24 日
Put them all in the same program and call "hold on" after you plot the first set of data. Then all subsequent plots should go on the same plot, as long as you didn't tell it to use some other axes.
  3 件のコメント
Image Analyst
Image Analyst 2013 年 2 月 24 日
Try issuing the "grid on" command after the last graph has been plotted.
mary
mary 2013 年 2 月 24 日
okay it worked thanx indeed

サインインしてコメントする。

その他の回答 (1 件)

pradeep
pradeep 2014 年 5 月 7 日
Hi, can u send me the TCM code.MailID-pradms36@gmail.com

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by