ASK调制与解调代码(共5页).doc
精选优质文档-倾情为你奉上ASK调制与解调代码2ASK代码close all;clear all;clc;t0=0.; % 0. 50个码元 0. 500个码元 0. 1000个码元% 码元宽度 0.0001s, 每个码元100个采样点ts=0.;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);%生成消息信号(二进制数字序列)for i=1:N m2(i)=fix(2*rand(1);end%将二进制数字序列转换为时域信号for k=1:N for i=(100*k-99):(100*k) m2_time(i)=m2(k); end end%清零处理for i=(100*(N/2)+1):(100*N) m2_time(i)=0;end%绘制二进制数字基带序列(不归零码型)plot(t,m2_time)axis(0 0.001 -0.5 1.5)grid on;title('二进制数字基带序列')%ask2=m2_time.*c;%figure(1)subplot(3,1,1)plot(t,m2_time)axis(0 0.001 -0.5 3.5)title('调制信号');grid on;subplot(3,1,2)plot(t,c)axis(0 0.001 -3.5 3.5)title('载波信号');grid on;subplot(3,1,3)plot(t,ask2)axis(0 0.001 -3.5 3.5)title('ASK已调信号');grid on;%ask2_noise=awgn(ask2,snr,'measured');%for j=1:length(snr)ask2_noise=awgn(ask2,snr(j),'measured');%绘制ASK信号波形(受噪声影响)figure(2)%subplot(4,1,4)plot(t,ask2_noise)axis(0 0.001 -2 2)grid on;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(0 0.001 -1 2)title('调制信号');grid on;subplot(3,1,2)plot(t,ask2_dem2(1:length(t)axis(0 0.001 -1 2)title('抽样前信号波形');grid on;%figure(3)%subplot(3,1,3)plot(f,abs(fftshift(ASK2_NOISE)axis(- 0 0.001)xlabel('频率');title('已调信号频谱');grid on;%抽样判决k=1;for i=50:100:(N*100-50) if ask2_dem2(i)<=0.5 m2_sample(k)=0; else m2_sample(k)=1; end k=k+1;end%将抽样结果转换为不归零码型for k=1:(N/2) for i=(100*k-99):(100*k) m2_sampletime(i)=m2_sample(k); end end%清零处理for i=(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');grid on;axis(0 20 10-12 100);%figure(4)%将调制信号与解调还原的信号作对比subplot(3,1,1)plot(t,m2_time(1:length(t)axis(0 0.001 -1 2)title('调制信号')grid on;subplot(3,1,2)plot(t,ask2_dem2(1:length(t)axis(0 0.001 -1 2)title('通过LPF后的波形')grid on;subplot(3,1,3)plot(t,m2_sampletime(1:length(t)axis(0 0.001 -1 2)title('抽样判决后波形')grid on;%close allclcclear all;% defineA = 1; % 单位幅度NUMBER = ; % 试验总数FC = 4;%*106; %载波频率RESOLUTION = 10; % 载波每个周期用RESOLUTION个点表示SNRdB = 0:1:18;% 理论曲线Pe = 1/2 * erfc( sqrt( 0.25*10.(SNRdB/10) ) );semilogy(SNRdB, Pe, 'R');hold on;grid on;% create signaln = 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 );for i=1:length(SNRdB) y = awgn(x, SNRdB(i)-10*log10(FC*RESOLUTION), 'measured'); y = y.*wc; for j=1:NUMBER yn(j) = sum( y( (j-1)*FC*RESOLUTION+1 : j*FC*RESOLUTION ) )>Vt; end ErrorCount=length(find(xor(xn,yn); Pe(i) = ErrorCount/NUMBER;endsemilogy(SNRdB, Pe,'b*-');legend('理论值','实验值');xlabel('信噪比');ylabel('误码率');专心-专注-专业