当前位置:文档之家› 正交幅度调制(QAM)及解调Matlab仿真讲解

正交幅度调制(QAM)及解调Matlab仿真讲解

正交幅度调制(QAM)及解调Matlab仿真实验目的:1.掌握QAM及解调原理与特性;2.了解星座图的原理及用途。

实验内容:1.编写MATLAB程序仿真QAM及相干解调;2.观察I、Q两路基带信号的特征及与输入NRZ码上网关系;3.观察I、Q调制过程中信号的变化;4.观察星座图在不同噪声环境下的变化;5.分析仿真中观察的数据,撰写实验报告。

仿真代码:function project(N,p)%N为待仿真序列的长度%p为产生1的概率%======================%首先产生随机二进制序列N=input('输入二进制序列的长度:N=');p=input('输入产生1的概率:');source=randsrc(1,N,[1,0;p,1-p]);figure(1);stem(source);axis([1 N -1 2]);%对产生的二进制序列进行QAM调制[source1,source2]=Qam_modulation(source);%===============================%画出星座图figure(2);plot_astrology(source1,source2);%==============================%两路信号进行插值(8倍过采样)sig_insert1=insert_value(source1,8);sig_insert2=insert_value(source2,8);%================================%画出两路信号的波形图figure(3);plot_2way(sig_insert1,sig_insert2,length(sig_insert1),0.5);title('两路信号波形');%================================%通过低通滤波器[sig_rcos1,sig_rcos2]=rise_cos(sig_insert1,sig_insert2,0.25,2);%================================%画出两路信号信号波形图figure(4);plot_2way(sig_rcos2,sig_rcos2,length(sig_rcos1)/4,0.5);title('通过低通滤波器后两路信号波形图')hold onstem_2way(sig_insert1,sig_insert2,3,0.25,2,length(sig_rcos1)/4); %================================%将基带信号调制到高频上[t,sig_modulate]=modulate_to_high(sig_rcos1,sig_rcos2,0.25,2.5); figure(5);plot(t(1:500),sig_modulate(1:500));title('载波调制信号图');%================================%将滤波后的信号加入高斯噪声snr=10;[x1,x2]=generate_noise(sig_rcos1,sig_rcos2,snr);sig_noise1=x1';sig_noise2=x2';figure(6);plot_2way(sig_noise1,sig_noise2,length(sig_noise1)/4,0.5);title('加入高斯白噪声后的两路信号波形');%================================%经过匹配滤波器[sig_match1,sig_match2]=rise_cos(sig_noise1,sig_noise2,0.25,2); figure(7);plot_2way(sig_match1,sig_match2,length(sig_match1)/4,0.5); title('经过匹配滤波器后');%================================%采样[x1,x2]=pick_sig(sig_match1,sig_match2,8);sig_pick1=x1;sig_pick2=x2;%画出星座图figure(8)plot_astrology(sig_pick1,sig_pick2);%================================%解调signal=demodulate_sig(sig_pick1,sig_pick2);r=signal;%画出解调后的信号figure(9);stem(r);axis([1 N -1 2]);demodulate_sigfunction y=demodulate_sig(x1,x2)%解调xx1(find(x1>=2))=3;xx1(find((x1<2)&(x1>=0)))=1;xx1(find((x1>=-2)&(x1<0)))=-1;xx1(find(x1<-2))=-3;xx2(find(x2>=2))=3;xx2(find((x2<2)&(x2>=0)))=1;xx2(find((x2>=-2)&(x2<0)))=-1;xx2(find(x2<-2))=-3;temp1=zeros(1,length(xx1)*2);temp1(find(xx1==-1)*2)=1;temp1(find(xx1==1)*2-1)=1;temp1(find(xx1==1)*2)=1;temp1(find(xx1==3)*2-1)=1;temp2=zeros(1,length(xx2)*2);temp2(find(xx2==-1)*2)=1;temp2(find(xx2==1)*2-1)=1;temp2(find(xx2==1)*2)=1;temp2(find(xx2==3)*2-1)=1;n=length(temp1);for i=1:2:2*n-1y(i)=temp1((i+1)/2);y(i+1)=temp2((i+1)/2);endgenerate_noisefunction [y1,y2]=generate_noise(x1,x2,snr)snr1=snr+10*log10(4);ss=var(x1+i*x2,1);y=awgn([x1+j*x2],snr1+10*log10(ss/10),'measured'); y1=real(y);y2=imag(y);insert_valuefunction y=insert_value(x,ratio)%对两路信号进行插值y=zeros(1,ratio*length(x));a=1:ratio:length(y);y(a)=x;modulate_to_highfunction [t,y]=modulate_to_high(x1,x2,f,hf)yo1=zeros(1,length(x1)*hf/f*10);yo2=zeros(1,length(x1)*hf/f*10);n=1:length(yo1);yo1(n)=x1(floor((n-1)/(hf/f*10))+1);yo2(n)=x1(floor((n-1)/(hf/f*10))+1);t=(1:length(yo1))/hf*f/10;y=yo1.*cos(2*pi*hf*t)-yo2.*sin(2*pi*hf*t);pick_sigfunction [y1,y2]=pick_sig(x1,x2,ratio)%采样y1=x1(ratio*3*2+1:ratio:(length(x1)-ratio*3*2)); y2=x2(ratio*3*2+1:ratio:(length(x2)-ratio*3*2));plot_2wayfunction plot_2way(x1,x2,len,t)%绘制正交信号图subplot(2,1,2);plot((1:len)*t,x2(1:len));axis([0 len*t -4 4]);hold on;plot((1:len)*t,x2(1:len),'.','Color','red');hold off;xlabel('虚部信号');subplot(2,1,1);plot((1:len)*t,x1(1:len));axis([0 len*t -4 4]);hold onplot((1:len)*t,x1(1:len),'.','Color','red');xlabel('实部信号');hold offplot_astrologyfunction plot_astrology(a,b)%画出星座图subplot(1,1,1);plot(a,b,'+');axis([-5 5 -5 5]);line([-5,5],[0,0],'LineWidth',3,'Color','red'); line([0,0],[-5,5],'LineWidth',3,'Color','red'); title('QAM星座图');Qam_modulationfunction [yy1, yy2]=Qam_modulation(x) N=length(x);a=1:2:N;y1=x(a);y2=x(a+1);a=1:2:N/2;temp11=y1(a);temp12=y1(a+1);y11=temp11*2+temp12;temp21=y2(a);temp22=y2(a+1);y22=temp21*2+temp22;yy1(find(y11==0))=-3;yy1(find(y11==1))=-1;yy1(find(y11==3))=1;yy1(find(y11==2))=3;yy2(find(y22==0))=-3;yy2(find(y22==1))=-1;yy2(find(y22==3))=1;yy2(find(y22==2))=3;endrise_cosfunction [y1,y2]=rise_cos(x1,x2,fd,fs)%升余弦滤波[yf,tf]=rcosine(fd,fs,'fir/sqrt');[yo1,to1]=rcosflt(x1,fd,fs,'filter/Fs',yf); [yo2,to2]=rcosflt(x2,fd,fs,'filter/Fs',yf);y1=yo1;y2=yo2;stem_2wayfunction stem_2way(x1,x2,delay,fd,fs,len)subplot(2,1,1)hold onstem(((1:len)+fs/fd*3)/fs,x1(1:len)); subplot(2,1,2)hold onstem(((1:len)+fs/fd*3)/fs,x2(1:len));实验结果:>> project输入二进制序列的长度:N=200输入产生1的概率:0.8QAM星座图虚部信号实部信号两路信号波形虚部信号实部信号通过低通滤波器后两路信号波形图载波调制信号图加入高斯白噪声后的两路信号波形实部信号虚部信号经过匹配滤波器后实部信号虚部信号QAM星座图。

相关主题