您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 公司方案 > 16QAM-星形和形星座图调制解调MATLAB代码
%%------------------------------------------------------------%软件无线电课程设计%%方形、星形16QAM调制解调仿真%%%------------------------------------------------------------%%主程序clcclear%%定义参数fd=250*10^6;%码元速率250Mfs=2500*10^6;%滤波器采样率fc=2500*10^6;%载波频率2.5Gf=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%方形映射16QAMrf_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);%星形映射16QAMrf_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:12subplot(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']);endfigure('Name','星形16QAM接收端星座图');fori=3:3:12subplot(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-1R=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_QAM0)));aver=mean(real(data_temp));data_Qam_temp=data_QAM/aver*(2^(k/2-1));%------
本文标题:16QAM-星形和形星座图调制解调MATLAB代码
链接地址:https://www.777doc.com/doc-4983189 .html