基于MATLAB的数字频带通信系统的仿真 - 图文

发布时间 : 星期六 文章基于MATLAB的数字频带通信系统的仿真 - 图文更新完毕开始阅读

北京邮电大学世纪学院毕业设计(论文)

% 抽样判决的过程,与0作比较,data>=0,则置1,否则置0 % for n=1:nb/2

% if Ray_sum(Ray_idata2((n-1)/delta_T+1:n/delta_T))>=0 % Ray_idata3(n)=1;

% else Ray_idata3(n)=0; % end

% if Ray_sum(Ray_qdata2((n-1)/delta_T+1:n/delta_T))>=0 % Ray_qdata3(n)=1; % else Ray_qdata3(n)=0; % end % end

% 为了显示星座图,将信号进行处理 Ray_idata4=zeros(1,nb/2); Ray_qdata4=zeros(1,nb/2); for n=1:nb/2

Ray_ichsum(n)=sum(idata2((n-1)/delta_T+1:n/delta_T))*delta_T; if Ray_ichsum(n)>=0 Ray_idata4(n)=1; else Ray_idata4(n)=0; end

Ray_qchsum(n)=sum(qdata2((n-1)/delta_T+1:n/delta_T))*delta_T; if Ray_qchsum(n)>=0 Ray_qdata4(n)=1; else Ray_qdata4(n)=0; end end

% 将判决之后的数据存放进数组 Ray_demodata=zeros(1,nb);

Ray_demodata(1:ml:(nb-1))=Ray_idata4; % 存放奇数位 Ray_demodata(2:ml:nb)=Ray_qdata4; % 存放偶数位

%为了显示,将它变成波形信号(即传输一个1代表单位宽度的高电平) Ray_demodata1=zeros(1,nb/delta_T); % 创建一个1*nb/delta_T的零矩阵 for q=1:nb

Ray_demodata1((q-1)/delta_T+1:q/delta_T)=Ray_demodata(q); % 将极性码变成对应的波形信号 end

% 累计误码数

% abs(demodata-data)求接收端和发射端

% 数据差的绝对值,累计之后就是误码个数 Ray_num_BER=sum(abs(Ray_demodata-data))

34

北京邮电大学世纪学院毕业设计(论文)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% 误码率计算

%% 调用了cm_sm32();和cm_sm33()函数 %%声明: 函数声明在另外俩个M文件中

%%作用: cm_sm32()用于瑞利信道误码率的计算 %% cm_sm33()用于高斯信道误码率的计算 %% ecoh on/off 作用在于决定是否显示指令内容

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SNRindB1=0:1:8; SNRindB2=0:0.1:8; % 瑞利衰落信道

for i=1:length(SNRindB1),

[pb,ps]=cm_sm32(SNRindB1(i)); % 比特误码率 smld_bit_ray_err_prb(i)=pb; smld_symbol_ray_err_prb(i)=ps; disp([ps,pb]); echo off; end;

% 高斯信道 echo on;

for i=1:length(SNRindB1),

[pb1,ps1]=cm_sm33(SNRindB1(i)); smld_bit_awgn_err_prb(i)=pb1; smld_symbol_awgn_err_prb(i)=ps1; disp([ps1,pb1]); echo off; end;

% 理论曲线 echo on;

for i=1:length(SNRindB2),

SNR=exp(SNRindB2(i)*log(10)/10); % 信噪比

theo_err_awgn_prb(i)=0.5*erfc(sqrt(SNR)); % 高斯噪声理论误码率 theo_err_ray_prb(i)=0.5*(1-1/sqrt(1+1/SNR)); % 瑞利衰落信道理论误码率 echo off; end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

h = spectrum.welch; % 类似于C语言的宏定义,方便以下的调用 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 第一部分(理想)

35

北京邮电大学世纪学院毕业设计(论文)

figure(1) subplot(212);

psd(h,data0,'fs',fs),title('基带信号功率谱密度'); subplot(211);

plot(data0),title('基带信号'); axis([0 20000 -2 2]);

figure(2) subplot(212);

psd(h,s,'fs',fs),title('调制信号功率谱密度'); subplot(211);

plot(s),title('调制信号'); axis([0 500 -3 3]);

figure(3) subplot(212);

psd(h,demodata1,'fs',fs),title('解调输出功率谱密度'); subplot(211);

plot(demodata1),title('解调输出'); axis([0 20000 -2 2]);

figure(4) subplot(313);

psd(h,s1,'fs',fs),title('调制信号功率谱密度(Awgn)'); subplot(312);

plot(s1),title('调制信号(Awgn)'); axis([0 500 -5 5]); subplot(311);

plot(s111),title('高斯噪声曲线'); axis([0 2000 -5 5]);

figure(5) for i=1:nb/2

plot(idata(i),qdata(i),'r+'),title('QPSK信号星座图(Awgn)');hold on; legend('理论值(发射端)','实际值(接收端)'); axis([-2 2 -2 2]);

plot(Awgn_ichsum(i),Awgn_qchsum(i),'*');hold on; end

figure(6) subplot(111)

36

北京邮电大学世纪学院毕业设计(论文)

semilogy(SNRindB2,theo_err_awgn_prb,'r'),title('误码率曲线');hold on; semilogy(SNRindB1,smld_bit_awgn_err_prb,'r*');hold on; semilogy(SNRindB2,theo_err_ray_prb);hold on; semilogy(SNRindB1,smld_bit_ray_err_prb,'*'); xlabel('Eb/No');ylabel('BER');

legend('理论AWGN','仿真AWGN','理论Rayleigh','仿真Rayleigh');

二.QPAK和OQPSK对比仿真程序:

%QPSK & OQPSK clear all; close all;

M=4; Ts=1; fc=10;

N_sample=16; N_num=100;

dt=1/fc/N_sample; t=0:dt:N_num*Ts-dt; T=dt*length(t);

py1f=zeros(1,length(t)); %功率谱密度1 py2f=zeros(1,length(t)); %功率谱密度2

for PL=1:100 %输入100段N_num个码字的波形,为了使功率谱密度看起来更加平滑,

%可以取这100段信号功率谱密度的平均 d1=sign(randn(1,N_num)); d2=sign(randn(1,N_num)); gt=ones(1,fc*N_sample);

%QPSK调制

s1=sigexpand(d1,fc*N_sample); s2=sigexpand(d2,fc*N_sample); b1=conv(s1,gt); b2=conv(s2,gt); s1=b1(1:length(s1)); s2=b2(1:length(s2));

st_qpsk=s1.*cos(2*pi*fc*t)-s2.*sin(2*pi*fc*t);

37

北京邮电大学世纪学院毕业设计(论文)

s2_delay=[-ones(1,N_sample*fc/2) s2(1:end-N_sample*fc/2)]; st_oqpsk=s1.*cos(2*pi*fc*t)-s2_delay.*sin(2*pi*fc*t);

%经过带通后,在经过非线性电路 [f y1f]=T2F(t,st_qpsk); [f y2f]=T2F(t,st_oqpsk);

[t y1]=bpf(f,y1f,fc-1/Ts,fc+1/Ts); [t y2]=bpf(f,y2f,fc-1/Ts,fc+1/Ts); subplot(221);

plot(t,y1);xlabel('t');ylabel('QPSK波形');

axis([5 15 -1.6 1.6]);title('经过带通后的波形');

subplot(222);

plot(t,y2);xlabel('t');ylabel('OQPSK波形'); axis([5 15 -1.6 1.6]);title('经过带通后的波形');

%经过非线性电路 y1=1.5*tanh(2*y1); y2=1.5*tanh(2*y2); [f y1f]=T2F(t,y1); [f y2f]=T2F(t,y2);

py1f=py1f+abs(y1f).^2/T; %QPSK不同段信号功率谱密度相加 py2f=py2f+abs(y2f).^2/T; %OQPSK不同段信号功率谱密度相加 end

py1f=py1f/100 %QPSK100段功率谱密度平均 py2f=py2f/100 %OQPSK100段功率谱密度平均

subplot(223);

plot(f,10*log10(py1f));xlabel('f');ylabel('QPSK功率谱密度(dB/Hz)'); title('经过非线性电路后的功率谱密度');axis([-15 15 -30 10]);

subplot(224);

plot(f,10*log10(py2f));xlabel('f');ylabel('OQPSK功率谱密度(dB/Hz)'); title('经过非线性电路后的功率谱密度');axis([-15 15 -30 10]);

figure(2) x=-2:0.1:2;

y=1.5*tanh(2*x);

plot(x,y);title('非线性电路的输入输入函数')

38

联系合同范文客服:xxxxx#qq.com(#替换为@)