16qam星形和矩形星座图调制解调matlab代码.docx
- 文档编号:26144028
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:10
- 大小:16.96KB
16qam星形和矩形星座图调制解调matlab代码.docx
《16qam星形和矩形星座图调制解调matlab代码.docx》由会员分享,可在线阅读,更多相关《16qam星形和矩形星座图调制解调matlab代码.docx(10页珍藏版)》请在冰豆网上搜索。
16qam星形和矩形星座图调制解调matlab代码
16qam_星形和矩形星座图调制解调matlab代码
%%------------------------------------------------------------
%软件无线电课程设计
%
%方形、星形16QAM调制解调仿真
%
%%------------------------------------------------------------
%%主程序
clc
clear
%%定义参数
fd=250*10^6;%码元速率250M
fs=2500*10^6;%滤波器采样率
fc=2500*10^6;%载波频率2.5G
f=10000*10^6;%对载波采样
data_len=200000;%数据长度
sym_len=data_len/4;%码元序列长度
M_QAM=16;%QAM数
k=log2(M_QAM);
SNR=1:
12;%白噪声信噪比,
%%------------------------------------------------------------
bit_tx=randint(1,data_len);%产生随机序列
echooff;
rec_qam16=QamMod(bit_tx,16);%方形16QAM调制star_qam16=SrarQamMod(bit_tx);%星形16QAM调制
base_rec=base_shape(fd,fs,f,rec_qam16);%基带成型滤波base_star=base_shape(fd,fs,f,star_qam16);%基带成型滤波
fori=1:
length(SNR)%信噪比从1dB到12dB计算误码率
SNR_=i
%方形映射16QAM
rf_rec_qam16=CarrierMod(fc,f,base_rec);%载波调制
rf_rec_qam16_n=awgn(rf_rec_qam16,SNR(i),'measured');%加噪声
[rec_qam16_rxbase_rec_rx]=CarrierDemod(fd,fs,fc,f,rf_rec_qam16_n);%载波解调
bit_rec_rx=QamDemod(rec_qam16_rx,16);%MQAM解调
[num_qam16,perr_qam16_rec(i)]=biterr(bit_tx,bit_rec_rx);%误码率
qam16_data_rec(i,:
)=rec_qam16_rx;
%scatterplot(rec_qam16_rx);
%星形映射16QAM
rf_star_qam16=CarrierMod(fc,f,base_star);%载波调制
rf_star_qam16_n=awgn(rf_star_qam16,SNR(i),'measured');%加噪声
[star_qam16_rxbase_star_rx]=CarrierDemod(fd,fs,fc,f,rf_star_qam16_n);%载波解调
bit_star_rx=StarQamDemod(star_qam16_rx);%MQAM解调
[num_qam16,perr_qam16_star(i)]=biterr(bit_tx,bit_star_rx);%误码率
qam16_data_star(i,:
)=star_qam16_rx;
%scatterplot(star_qam16_rx);
end
%%理论误码率计算
SNRtheo=0:
0.1:
length(SNR);fori=1:
length(SNRtheo)
SNRdec=10.^(SNRtheo(i)/10);
theo_perr_qam16(i)=(3/8)*erfc(sqrt(SNRdec*2/5));
end
%%基带波形
N=200;
n=1:
N;
t=1:
N*10;
%发送端波形
figure;
stem(n,bit_tx(n));title('发送序列');%发送序列
figure('Name','发送端基带信号');
subplot(411);
plot(t,real(base_rec(t)));title('方形映射-Q路');
subplot(412);
plot(t,imag(base_rec(t)));title('方形映射-I路');
subplot(413);
plot(t,real(base_star(t)));title('星形映射-Q路');
subplot(414);
plot(t,imag(base_star(t)));title('星形映射-I路');
%接收端波形
figure;
subplot(211);
stem(n,bit_rec_rx(n));title('方形接收序列');
subplot(212);
stem(n,bit_star_rx(n));title('星形接收序列');
figure('Name','接收端基带信号');
subplot(411);
plot(t,real(base_rec_rx(t)));title('方形映射-Q路');
subplot(412);
plot(t,imag(base_rec_rx(t)));title('方形映射-I路');
subplot(413);
plot(t,real(base_star_rx(t)));title('星形映射-Q路');
subplot(414);
plot(t,imag(base_star_rx(t)));title('星形映射-I路');
%基带眼图
N1=20000;
Tn=f/fd;
eye_rex=base_rec(1:
N1);
eyediagram(eye_rex,Tn*4,Tn);title('方形基带眼图');
eye_star=base_star(1:
N1);
eyediagram(eye_star,Tn*4,Tn);title('星形基带眼图');
%%接收端星座图
%scatterplot(qam16_data_rec(12,:
));figure('Name','方形16QAM接收端星座图');
fori=3:
3:
12
subplot(2,2,i/3);
plot(real(qam16_data_rec(i,:
)),imag(qam16_data_rec(i,:
)),'.');
xmax=5;axis([-xmaxxmax-xmaxxmax])
title(['Snr=',num2str(SNR(i)),'dB']);
end
figure('Name','星形16QAM接收端星座图');
fori=3:
3:
12
subplot(2,2,i/3);
plot(real(qam16_data_star(i,:
)),imag(qam16_data_star(i,:
)),'.');
xmax=3;axis([-xmaxxmax-xmaxxmax])
gridon;title(['Snr=',num2str(SNR(i)),'dB']);
end
%%功率谱密度
f_plot;
%%误码率分析
%16QAM误码率曲线
figure('Name','16QAM误码性能对比');
%semilogy(SNRtheo,theo_perr_qam16);%holdon;
semilogy(SNR,perr_qam16_rec,'*');holdon;
semilogy(SNR,perr_qam16_star,'o');xlabel('SNRindB');
ylabel('PrbofErr');
legend('方形16QAM','星形16QAM');
title('16QAM误码性能对比');
%-------------------------------------------------------------------------------
%%基带成型
functionbase_info=base_shape(fd,fs,f,seq_16QAM)%平方根升余弦滤波器,滚降系数0.5,延迟3个采样点
flt=rcosine(fd,fs,'sqrt',0.5);
%I路和Q路
seq_Q=real(seq_16QAM);
seq_I=imag(seq_16QAM);
%增采样
R=fs/fd;
up_seq_Q=upsample(seq_Q,R);
up_seq_I=upsample(seq_I,R);
%升余弦调制
rcos_Q=conv(up_seq_Q,flt);
rcos_I=conv(up_seq_I,flt);
%提升
rcos_Q_up=interp(rcos_Q,f/fs);
rcos_I_up=interp(rcos_I,f/fs);
base_info=rcos_Q_up+j*rcos_I_up;
%--------------------------------------------------------------------
%%载波解调
function[data_rxbase_rx]=CarrierDemod(fd,fs,fc,f,receive)
%%分两路乘正交高频载波
rc_length=length(receive);
flt=rcosine(fd,fs,'sqrt',0.5);
t=0:
rc_length-1;
rc_Q=receive.*sin(2*pi*fc*t/f);rc_I=receive.*cos(2*pi*fc*t/f);
%减采样后根升余弦匹配滤波,注意对齐采样点
down_Q=downsample([0rc_Q],f/fs);
down_I=downsample(rc_I,f/fs);
low_Q_rcos=conv(down_Q,flt);
low_I_rcos=conv(down_I,flt);
base_rx=low_Q_rcos(1:
length(low_I_rcos))+j*low_I_rcos;
%两次根升余弦滤波延迟,定位初始信号位置
%delay+1:
end-delay-1
R=fs/fd;
delay=3*R*2;
rc_Q_seq=(downsample(low_Q_rcos(delay+1:
end-delay-1),R));rc_I_seq=(downsample(low_I_rcos(delay+1:
end-delay-1),R));%类型转换
data_rx=rc_Q_seq+j*rc_I_seq;
%--------------------------------------------------------------------------
%%载波调制
functiontransmit=CarrierMod(fc,f,base)
%载波调制
t=0:
length(base)-1;
high_freq_Q=real(base).*sin(2*pi*fc*t/f);
high_freq_I=imag(base).*cos(2*pi*fc*t/f);
transmit=high_freq_Q+high_freq_I;
%------------------------------------------------------------------------------
%
%QAM解调程序,将MQAM码元还原为二进制数据
%入口参数:
data_QAM:
QAM码元数据
%M_QAM:
MQAM中M的大小
%出口参数:
二进制数据比特流
%------------------------------------------------------------------------
functiondata_out=QamDemod(data_QAM,M_QAM)
k=log2(M_QAM);%每个M进制码元的bit数
data_len=length(data_QAM);%码元长度
%-------------------------------------------------------------------
%QAM信号放缩至与发送端相同比例
data_temp=data_QAM(find(real(data_QAM>0)));
aver=mean(real(data_temp));
data_Qam_temp=data_QAM/aver*(2^(k/2-1));
%------------------------------------------------------------------------
%平移到第一象限
data_Qam_temp2=(data_Qam_temp+(2^(k/2)-1)*(1+j))/2;%----------------------------------------------------------------------
%将实部虚部分别映射为二进制数据
%实部
data_real=round(real(data_Qam_temp2));%实部判决
data_real(find(data_real>(2^(k/2)-1)))=2^(k/2)-1;%大于2^(k/2)-1的数据判定为2^(k/2)-1data_real(find(data_real<0))=0;%小于0的数据判为0
bit_real=abs(dec2bin(data_real))-'0';%虚部
data_imag=round(imag(data_Qam_temp2));%虚部判决
data_imag(find(data_imag>(2^(k/2)-1)))=2^(k/2)-1;%大于2^(k/2)-1的数据判定为2^(k/2)-1data_imag(find(data_imag<0))=0;%小于0的数据判为0
bit_imag=abs(dec2bin(data_imag))-'0';%------------------------------------------------------------------------
%还原为二进制比特流
bit_rec=[bit_real,bit_imag]';
data_out=reshape(bit_rec,1,data_len*k);
%-------------------------------------------------------------------------------------------------------------
%
%QAM调制程序,实现二进制到MQam调制
%入口参数:
binary:
二进制数据
%M_QAM:
MQAM中M的大小
%返回参数:
MQAM码元
%------------------------------------------------------------------------
functiondata_M=QamMod(binary,M_QAM)
k=log2(M_QAM);%每个M进制码元的bit数
data_len=length(binary);%比特长度
binary_rec=reshape(binary,k,data_len/k)';%转化为data_len/k行,k列,的矩阵,以便转化为16进制M进制
%计算实部
data_str1=num2str(binary_rec(:
1:
k/2));data_m_real=bin2dec(data_str1);
%计算虚部
data_str2=num2str(binary_rec(:
k/2+1:
k));data_m_imag=bin2dec(data_str2);
%实部虚部映射到MQam
data_M=((data_m_real*2-2^(k/2)+1)+j*(data_m_imag*2-2^(k/2)+1)).';
%---------------------------------------------------------------------------------
%%星形16QAM映射
functiondata_m16=SrarQamMod(binary)%binary=randint(1,100);%产生随机序列
data_len=length(binary);%比特长度
binary_rec=reshape(binary,4,data_len/4)';%转化为data_len/4行,4列,的矩阵,以便转化为16进制
data_str=num2str(binary_rec);
data_dec=bin2dec(data_str);
data_mm16=(floor(data_dec/8)+1).*exp(j*45/180*pi*mod(data_dec,8));
data_m16=reshape(data_mm16,1,data_len/4);
%------------------------------------------------------------------------------
%%星形16QAM解调
functiondata_bit=StarQamDemod(qam_rev)%qam_rev=xing_qam16_noise(1:
10);
am=abs(qam_rev);%幅度判定
am(find(am>2))=2;%幅度大于2的判定为2
am(find(am<1.5))=1;%幅度大于2的判定为2
%相位判定
ang=angle(qam_rev)/pi*180;%将-180度到0度变为180度到360度
ang(find(ang<0))=ang(find(ang<0))+360;ang_n=round(ang/45);
ang_n(find(ang_n>7))=0;
data_dec=8*(round(am)-1)+ang_n;
%data_dec(find(data_dec>15))=15;%大于15的判定为15
%data_dec(find(data_dec<0))=0;%小于0的判定为0
data_bit_rec=dec2bin(data_dec);
data_bit=reshape(data_bit_rec',1,length(qam_rev)*4)-'0';
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 16 qam 星形 矩形 星座图 调制 解调 matlab 代码