📄 qam prac.m
字号:
clc
clear all
close all
len=1e3;
bit_seq=randint(1,len);
bits=reshape(bit_seq,len/4,4);
N=len/4;
th=zeros(1,N);
c=1/ sqrt(10);
for n=1:N
if((bits(n,1)==0) && ((bits(n,2)==0) && ((bits(n,3)==0) && ((bits(n,4))==0)
th(n)=-3*c+i*3*c;
elseif((bits(n,1)==0) && ((bits(n,2)==0) && ((bits(n,3)==0) && ((bits(n,4))==1)
th(n)=-c+i*3*c;
elseif((bits(n,1)==0) && ((bits(n,2)==1) && ((bits(n,3)==0) && ((bits(n,4))==0)
th(n)=-3*c+i*c;
elseif((bits(n,1)==0) && ((bits(n,2)==1) && ((bits(n,3)==0) && ((bits(n,4))==1)
th(n)=-c+i*c;
elseif((bits(n,1)==0) && ((bits(n,2)==0) && ((bits(n,3)==1) && ((bits(n,4))==1)
th(n)=c+i*3*c;
elseif((bits(n,1)==0) && ((bits(n,2)==1) && ((bits(n,3)==1) && ((bits(n,4))==1)
th(n)=c+i*c;
elseif((bits(n,1)==0) && ((bits(n,2)==1) && ((bits(n,3)==1) && ((bits(n,4))==0)
th(n)=3*c+i*c;
elseif((bits(n,1)==0) && ((bits(n,2)==0) && ((bits(n,3)==1) && ((bits(n,4))==0)
th(n)=3*c+i*3*c;
elseif((bits(n,1)==1) && ((bits(n,2)==1) && ((bits(n,3)==0) && ((bits(n,4))==0)
th(n)=-3*c-i*c;
elseif((bits(n,1)==1) && ((bits(n,2)==1) && ((bits(n,3)==0) && ((bits(n,4))==1)
th(n)=-c-i*c;
elseif((bits(n,11==1) && ((bits(n,2)==1) && ((bits(n,3)==1) && ((bits(n,4))==1)
th(n)=c-i*c;
elseif((bits(n,1)==1) && ((bits(n,2)==1) && ((bits(n,3)==1) && ((bits(n,4))==0)
th(n)=3*c-i*c;
elseif((bits(n,1)==1) && ((bits(n,2)==0) && ((bits(n,3)==0) && ((bits(n,4))==0)
th(n)=-3*c-i*3*c;
elseif((bits(n,1)==1) && ((bits(n,2)==0) && ((bits(n,3)==0) && ((bits(n,4))=1)
th(n)=-c-i*3*c;
elseif((bits(n,1)==1) && ((bits(n,2)==0) && ((bits(n,3)==1) && ((bits(n,4))==1)
th(n)=c-3*i*c;
elseif((bits(n,1)==1) && ((bits(n,2)==0) && ((bits(n,3)==1) && ((bits(n,4))==0)
th(n)=3*c+i*3*c;
end
end
Tc=1e-3;
T=4*Tc;
fc=1/Tc;
t=[0:T/100:T];
x1=zeros(N,length(t));
y1=zeros(N,length(t));
c1=cos(2*pi*fc*t);
c2=sin(2*pi*fc*t);
for j=1:N
x1(j,:)=real(th(j))*c1;
x2(j,:)=imag(th(j))*c2;
end
ss1=x1-y1;
figure(1)
k=reshape(ss1',1,len*length(t)/4);
subplot(211);plot(k(1:500));title('Transmitted Signal');
SNR=[-40 -30 -20 -10];
fo i=1: length(SNR)
sigRx=awgn(ss1,SNR(i));
k=reshape(sigRx',1,len*length(t)/4);
subplot(212);plot(k(1:500));title('Received Signal');
c11=2*cos(20*t);
c22=2*sin(20*t);
for n=1:N
y1(n,:)=sigRx(n,:).*c11;
y2(n,:)=sigRx(n,:).*c22;
yp1(n)=(max(y1(n,:))+min(y1(n,:)))/2;
yp2(n)=(max(y2(n,:))+min(y2(n,:)))/2;
end
bout=zeros(1,N);
for n=1:N
if (yp1(n)>0) & (yp1(n)<.6325)
if (yp2(n)>0) & (yp2(n)<.6325)
bout(n)=7;
elseif (yp2(n)>0) & (yp2(n)>.6325)
bout(n)=3;
elseif (yp2(n)<0) & (yp2(n)>-.6325)
bout(n)=15;
else
bout(n)=11;
end
elseif yp1(n)>.6325
if (yp2(n)>0) & (yp2(n)<.6325)
bout(n)=6;
elseif (yp2(n)>0) & (yp2(n)>.6325)
bout(n)=2
elseif (yp2(n)<0) & (yp2(n)>-.6325)
bout(n)=14;
else
bout(n)=10;
end
elseif (yp1(n)<0) & (yp1(n)>-.6325)
if (yp2(n)>0) & (yp2(n)<.6325)
bout(n)=5;
elseif (yp2(n)>0) & (yp2(n)>.6325)
bout(n)=1;
elseif (yp2(n)<0) & (yp2(n)>-.6325)
bout(n)=13;
else
bout(n)=9;
end
else (yp1(n)<0) & (yp1(n)<-.6325)
if (yp2(n)>0) & (yp2(n)<.6325)
bout(n)=4;
elseif (yp2(n)>0) & (yp2(n)>.6325)
bout(n)=0;
elseif (yp2(n)<0) & (yp2(n)>-.6325)
bout(n)=12;
else
bout(n)=8;
end
end
end
rx=dec2bin(bout',4);
bit_out=str2num(reshape(rx',1,len)')';
bit_in=reshape(bits',1,len);
[ne(i) be(i) ]=biterr(bit_in,bit_out);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -