您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > ASK调制与解调代码
ASK调制与解调代码2ASK代码closeall;clearall;clc;t0=0.049999;%0.00499950个码元0.049999500个码元0.0999991000个码元%码元宽度0.0001s,每个码元100个采样点ts=0.000001;fc=50000;%snr=0:1:20;snr=6;%信噪比,以dB来表示fs=1/ts;df=0.3;%频率分辨率t=[0:ts:t0];%计算仿真的数字序列长度n=size(t);N=n(2)/100;%载波信号生成,频率为fcc=cos(2*pi*fc*t);%本地载波信号c_local=cos(2*pi*fc.*t);%生成消息信号(二进制数字序列)fori=1:Nm2(i)=fix(2*rand(1));end%将二进制数字序列转换为时域信号fork=1:Nfori=(100*k-99):(100*k)m2_time(i)=m2(k);endend%清零处理fori=(100*(N/2)+1):(100*N)m2_time(i)=0;end%{%绘制二进制数字基带序列(不归零码型)plot(t,m2_time)axis([00.001-0.51.5])gridon;title('二进制数字基带序列')%}ask2=m2_time.*c;%figure(1)subplot(3,1,1)plot(t,m2_time)axis([00.001-0.53.5])title('调制信号');gridon;subplot(3,1,2)plot(t,c)axis([00.001-3.53.5])title('载波信号');gridon;subplot(3,1,3)plot(t,ask2)axis([00.001-3.53.5])title('ASK已调信号');gridon;%}ask2_noise=awgn(ask2,snr,'measured');%{forj=1:length(snr)ask2_noise=awgn(ask2,snr(j),'measured');%}%%绘制ASK信号波形(受噪声影响)figure(2)%subplot(4,1,4)plot(t,ask2_noise)axis([00.001-22])gridon;title('ask信号波形(加噪)')%}%本地载波与接收已调信号相乘,实现相干解调ask2_dem1=ask2_noise.*c_local;%将相乘结果转换为频域[ASK2_DEM1,ask2_dem1,df1]=fftseq(ask2_dem1,ts,df);ASK2_DEM1=ASK2_DEM1/fs;f=[0:df1:df1*(length(ask2_dem1)-1)]-fs/2;%%将已调信号转换为频域[ASK2_NOISE,ask2_noise,df1]=fftseq(ask2_noise,ts,df);ASK2_NOISE=ASK2_NOISE/fs;%}%低通滤波器设计f_cutoff=50000;%截止频率n_cutoff=floor(f_cutoff/df1);H=zeros(size(f));H(1:n_cutoff)=2*ones(1,n_cutoff);H(length(f)-n_cutoff+1:length(f))=2*ones(1,n_cutoff);%接收信号通过低通滤波器ASK2_DEM2=H.*ASK2_DEM1;ask2_dem2=real(ifft(ASK2_DEM2))*fs;%{%绘制抽样前信号的频谱subplot(3,1,1)plot(t,m2_time(1:length(t)))axis([00.001-12])title('调制信号');gridon;subplot(3,1,2)plot(t,ask2_dem2(1:length(t)))axis([00.001-12])title('抽样前信号波形');gridon;%}figure(3)%subplot(3,1,3)plot(f,abs(fftshift(ASK2_NOISE)))axis([-15000015000000.001])xlabel('频率');title('已调信号频谱');gridon;%}%抽样判决k=1;fori=50:100:(N*100-50)ifask2_dem2(i)=0.5m2_sample(k)=0;elsem2_sample(k)=1;endk=k+1;end%将抽样结果转换为不归零码型fork=1:(N/2)fori=(100*k-99):(100*k)m2_sampletime(i)=m2_sample(k);endend%清零处理fori=(100*(N/2)+1):(100*N)m2_sampletime(i)=0;end%{ErrorCount=length(find(xor(m2,m2_sample)));Pe(j)=ErrorCount/length(m2);endsemilogy(snr,Pe,'r');gridon;axis([02010^-1210^0]);%}%figure(4)%将调制信号与解调还原的信号作对比subplot(3,1,1)plot(t,m2_time(1:length(t)))axis([00.001-12])title('调制信号')gridon;subplot(3,1,2)plot(t,ask2_dem2(1:length(t)))axis([00.001-12])title('通过LPF后的波形')gridon;subplot(3,1,3)plot(t,m2_sampletime(1:length(t)))axis([00.001-12])title('抽样判决后波形')gridon;%}closeallclcclearall;%defineA=1;%单位幅度NUMBER=100000;%试验总数FC=4;%*10^6;%载波频率RESOLUTION=10;%载波每个周期用RESOLUTION个点表示SNRdB=0:1:18;%理论曲线Pe=1/2*erfc(sqrt(0.25*10.^(SNRdB/10)));semilogy(SNRdB,Pe,'R');holdon;gridon;%createsignaln=1:NUMBER*FC*RESOLUTION;xn=rand(1,NUMBER)0.5;wc=sin(n/RESOLUTION*2*pi);x=wc.*xn(ceil(n/FC/RESOLUTION));Vt=sum(0.5*wc([1:FC*RESOLUTION]).^2);fori=1:length(SNRdB)y=awgn(x,SNRdB(i)-10*log10(FC*RESOLUTION),'measured');y=y.*wc;forj=1:NUMBERyn(j)=sum(y([(j-1)*FC*RESOLUTION+1:j*FC*RESOLUTION]))Vt;endErrorCount=length(find(xor(xn,yn)));Pe(i)=ErrorCount/NUMBER;endsemilogy(SNRdB,Pe,'b*-');legend('理论值','实验值');xlabel('信噪比');ylabel('误码率');
本文标题:ASK调制与解调代码
链接地址:https://www.777doc.com/doc-5008849 .html