《2022年ASK调制与解调代码 .pdf》由会员分享,可在线阅读,更多相关《2022年ASK调制与解调代码 .pdf(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、ASK 调制与解调代码2ASK代码close all;clear all;clc;t0=0.049999;%0.004999 50个码元 0.049999 500个码元 0.099999 1000个码元%码元宽度 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;%载波信号生成,频率为fc c=cos(2*pi*fc*t);%本地载波信号c_local=cos(2*pi*fc.*
2、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%绘制二进制数字基带序列(不归零码型)名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 5 页 -plot(t,m2_time)axis(0 0.001-0.5 1.5)grid on;title(二进制数字基带序列)%ask2=m2_ti
3、me.*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
4、(j),measured);%绘制 ASK信号波形(受噪声影响)figure(2)%subplot(4,1,4)plot(t,ask2_noise)axis(0 0.001-2 2)grid on;title(ask信号波形(加噪))%本地载波与接收已调信号相乘,实现相干解调名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 5 页 -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*(l
5、ength(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_
6、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(-150000 150000 0 0.001)xlabel(
7、频率);title(已调信号频谱);grid on;名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 5 页 -%抽样判决k=1;for i=50:100:(N*100-50)if ask2_dem2(i)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;end semilogy(SNRdB,Pe,b*-);legend(理论值,实验值);xlabel(信噪比);ylabel(误码率);名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 5 页 -
限制150内