1、% -% 软件无线电课程设计% 方形、星形 16QAM 调制解调仿真%-%主程序clcclear% 定义参数fd=250*106; %码元速率 250Mfs=2500*106; %滤波器采样率fc=2500*106; %载波频率 2.5Gf=10000*106; %对载波采样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);%产生随机序列echo off;rec_qam16=QamMod(bit_
2、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); %基带成型滤波 for i=1:length(SNR) %信噪比从 1dB 到 12dB 计算误码率SNR_=i%方形映射 16QAMrf_rec_qam16=CarrierMod(fc,f,base_rec); %载波调制rf_rec_qam16_n=awgn(rf_rec_qam16,SN
3、R(i),measured); %加噪声rec_qam16_rx base_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,ba
4、se_star); %载波调制rf_star_qam16_n=awgn(rf_star_qam16,SNR(i),measured); %加噪声star_qam16_rx base_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; %scatte
5、rplot(star_qam16_rx);end% 理论误码率计算SNRtheo=0:0.1:length(SNR);for i=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(
6、方形映射-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,接收
7、端基带信号);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
8、,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 接收端星座图 );for i=3:3:12subplot(2,2,i/3);plot(real(qam16_data_rec(i,:),imag(qam16_data_rec(i,:),.);xmax=5;axis(-xmax xmax -xmax xmax)title(Snr=,nu
9、m2str(SNR(i), dB); endfigure(Name,星形 16QAM 接收端星座图 );for i=3:3:12subplot(2,2,i/3);plot(real(qam16_data_star(i,:),imag(qam16_data_star(i,:),.);xmax=3;axis(-xmax xmax -xmax xmax)grid on; title(Snr=,num2str(SNR(i), dB); end% 功率谱密度f_plot;% 误码率分析%16QAM 误码率曲线figure(Name,16QAM 误码性能对比);% semilogy(SNRtheo,the
10、o_perr_qam16);% hold on;semilogy(SNR,perr_qam16_rec,*);hold on;semilogy(SNR,perr_qam16_star,o);xlabel(SNR in dB);ylabel(Prb of Err);legend(方形 16QAM,星形 16QAM);title(16QAM 误码性能对比);%-% 基带成型function base_info=base_shape(fd,fs,f,seq_16QAM)%平方根升余弦滤波器,滚降系数 0.5,延迟 3 个采样点flt=rcosine(fd,fs,sqrt,0.5); %I 路和 Q
11、路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_rx base_rx=Car
12、rierDemod(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(0 rc_Q,f/fs);down_I=downsample(rc_I,f/fs);low_Q_rcos=conv(down_Q,flt);low_I_rcos=co
13、nv(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;%-% 载波调制function transmit=
14、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 的大小% 出口参数:二进制数据比特流%-function data_out=QamDemod(data_QAM,M_QAM)k=l
15、og2(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);%-%平移到第一象限data_Qam_temp2=(data_Qam_temp+(2(k/2)-1)*(1+j)/2;%-%将实部虚部分别映射为二进制数据%实部data_real=round(real(data_Qam_temp2);
16、%实部判决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(2(k/2)-1)=2(k/2)-1;%大于 2(k/2)-1 的数据判定为 2(k/2)-1data_imag(find(data_imag2)=2;%幅度大于 2 的判定为 2am(find(am7)=0;data_dec=8*(round(am)-1)+ang_n;%data_dec(find(data_dec15)=15;%大于 15 的判定为 15%data_dec(find(data_dec0)=0;%小于 0 的判定为 0data_bit_rec=dec2bin(data_dec);data_bit=reshape(data_bit_rec,1,length(qam_rev)*4)-0;