资源描述:
《ASK调制与解调代码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、ASK调制与解调代码2ASK代码closeall;clearall;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);%生成消息信号(二进制数字序列)fori=1:Nm2(i)=f
2、ix(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])t
3、itle('调制信号');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,
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
5、_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
6、,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([-00.001])xlabel('频率');title('已调信号频谱');gridon;%}%抽样判决k=1;fori=50:100:(N*100-5
7、0)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(