%数字通信QAM仿真
clear
%产生基带符号流
M=16; %进制 16QAM
N=40; %信源比特流长度,为保证对齐,选择是log2(M)的整倍数
bitstream=zeros(1,N);
symbolstream=zeros(1,N/log2(M));
for n1=1:N
bitstream(n1)=binornd(1,0.5,1,1);%%二项分布
end
%格雷码编码
for n1=1:length(symbolstream)
pack=[bitstream(4*(n1-1)+1) bitstream(4*(n1-1)+2) bitstream(4*(n1-1)+3) bitstream(4*(n1-1)+4)];
if pack==[0 0 0 0]
symbolstream(n1)=1+j;
elseif pack==[0 0 1 0]
symbolstream(n1)=2+j;
elseif pack==[0 0 1 1]
symbolstream(n1)=2+2j;
elseif pack==[0 0 0 1]
symbolstream(n1)=1+2j;
elseif pack==[0 1 0 1]
symbolstream(n1)=-1+2j;
elseif pack==[0 1 0 0]
symbolstream(n1)=-1+j;
elseif pack==[0 1 1 1]
symbolstream(n1)=-2+2j;
elseif pack==[0 1 1 0]
symbolstream(n1)=-2+j;
elseif pack==[1 1 1 0]
symbolstream(n1)=-2-j;
elseif pack==[1 1 1 1]
symbolstream(n1)=-2-2j;
elseif pack==[1 1 0 1]
symbolstream(n1)=-1-2j;
elseif pack==[1 1 0 0]
symbolstream(n1)=-1-j;
elseif pack==[1 0 0 0]
symbolstream(n1)=1-j;
elseif pack==[1 0 1 0]
symbolstream(n1)=2-j;
elseif pack==[1 0 0 1]
symbolstream(n1)=1-2j;
else symbolstream(n1)=2-2j;
end
end
figure(1)
hold on
for n1=-2:2
for n2=-2:2
if ~((n1==0)|(n2==0))
scatter(n1,n2);
end
end
end
axis([-3 3 -3 3]);
hold off
title('16QAM星座图');
xlabel('同相支路')
ylabel('正交支路')
%产生载波
fc=10; %载波频率
fs=150; %采样频率
ts=1/fs;
df=0.3;
T=1; %每符号持续时间
N_samples=T*fs; %每符号内的采样点数
t=0:T/N_samples:(T-T/N_samples);
carrier=exp(j*2*pi*fc*t);
%产生信号脉冲g(t):升余弦脉冲g(t)
gt=1-cos(2*pi*(1/T)*t);
%生成调制信号S(t)
St_complex=zeros(1,length(carrier)*length(symbolstream));
for n1=1:length(symbolstream)
St_complex((N_samples*(n1-1)+1):(N_samples*(n1-1)+N_samples))=(symbolstream(n1)*carrier).*gt;
end
figure(2)
St_real=real(St_complex);
plot(St_real)
title('QAM仿真波形图 g(t)为升余弦脉冲');
xlabel('采样点')
ylabel('幅度')
r=St_real;
result=r*2^15;
%求频谱
[R,r,df1]=fftseq(r,ts,df);
R=R/fs;
f=[0:df1:df1*(length(r)-1)]-fs/2;
figure(3);
plot(f,abs(fftshift(R)/N))
% 备注:
% St_real是QAM16信号的幅度,它已经是两个支路幅度的和即St_real=I+Q;
- 1
- 2
前往页