📄 cleanshjian.m
字号:
%TH-PPM信号产生和接收仿真(AGWN信道),所有数字默认单位:ns%
tf=7;%帧长%
ns=1;%每符号内的脉冲个数
symbolnum=10;%符号数
framenum=ns*symbolnum;%帧数
tc=round(tf/2)/symbolnum;%跳时时延%
n=randint(1,framenum,symbolnum);%跳时随机数%
d=[0:1:framenum-1].*tf;%帧位置时延%
d1=d+tc*n;%跳时延时%
deta=0.156;%ppm延时%
%tr=randerr(1,symbolnum,round(symbolnum/2));%信号序列%
%tr=randerr(1,10,5);%信号序列%
tr=[1 1 0 1 0 1 1 0 0 1];
%plot(tr);
%bar (tr,0.1);
tmp=repmat(tr,ns,1);
tm=[];
for i=1:length(tr)
tm=[tm tmp(:,i)'];
end
d2=d1+deta*tm;%加入序列调制延时的总时延%
t=framenum*tf;%信号持续时间%
%t=[-0.2:0.01:t1];
pw1=0.75;
pw=0.2877;%脉宽%
%yd =(1-4*pi*((t-pw1/2)./pw).^2).*exp(-2*pi*((t-pw1/2)./pw).^2);
%figure(1);plot(t,yd);
tt=0:0.01:t;
yp=pulstran(tt,d2,'y');%发送脉冲信号序列%
figure(1);
subplot(2,1,1)
plot(tt,yp);
xlabel('单位:ns')
title('TH-PPM调制脉冲序列');grid on
yp=pulstran(tt,d2'+0.2,'y');%接收脉冲序列,接收时延为0.2
%通过四径信道
%a1=-0.9;tao1=0.8;a2=1.5;tao2=0.2;a3=-0.3;tao3=0.156;
%ypdj=yp+a1*yp(t-round(tao1))+a2*yp(t-round(tao2))+a3*yp(t-round(tao3));
%=======================================================================
%通过UWB-CM1信道
no_output_files = 0; % non-zero: avoids writing output files of continuous-time responses
ts = 0.167; % sampling time (nsec)
num_channels = 20; % number of channel impulse responses to generate
randn('state',12); % initialize state of function for repeatability
rand('state',12); % initialize state of function for repeatability
cm_num =1; % channel model number from 1 to 4
% get channel model params based on this channel model number
[Lam,lambda,Gam,gamma,std_ln_1,std_ln_2,nlos,std_shdw] = uwb_sv_params( cm_num );
fprintf(1,['Model Parameters\n' ...
' Lam = %.4f, lambda = %.4f, Gam = %.4f, gamma = %.4f\n' ...
' std_ln_1 = %.4f, std_ln_2 = %.4f, NLOS flag = %d, std_shdw = %.4f\n'], ...
Lam, lambda, Gam, gamma, std_ln_1, std_ln_2, nlos, std_shdw);
% get a bunch of realizations (impulse responses)
[h_ct,t_ct,t0,np] = uwb_sv_model_ct( Lam, lambda, Gam, gamma, std_ln_1, std_ln_2, nlos, ...
std_shdw, num_channels );
% now reduce continuous-time result to a discrete-time result
[hN,N] = uwb_sv_cnvrt_ct( h_ct, t_ct, np, num_channels, ts );
% if we wanted complex baseband model or to impose some filtering function,
% this would be a good place to do it
if N > 1,
h = resample(hN, 1, N); % decimate the columns of hN by factor N
else
h = hN;
end
% correct for 1/N scaling imposed by decimation
h = h * N;
%ypdj=filter(y,1,h)*ts;
ypdj1=filter(yp,1,h)*ts;
%=======================================================================
%ypw=ypdj+wgn(1,length(ypdj),0);%加入高斯白噪声
%ypw=ypdj;
ypw1=ypdj1;
subplot(2,1,2);grid on
plot(tt,ypw1(1:length(tt)));
xlabel('单位:ns')
title('通过CM1信道输出');
grid on
%采用clean求信道
p=yp;
figure(2);
subplot(2,1,1),plot((tt+1).*100,p),title('数据P(K)');
%subplot(2,1,1),plot((t+1).*100,p),title('一种高斯脉冲P(K)');
rss=double(xcorr(p,p));%求模板信号的自相关
[X,J]=max(abs(rss));
subplot(2,1,2),plot(0:length(rss)-1,rss),title('P(K)的自相关函数');
%
%产生接收信号y
%
%hk=zeros(1,551);
%hk(1)=sqrt(0.4);hk(201)=-sqrt(0.3);hk(501)=sqrt(0.2);hk(551)=sqrt(0.1);
y=conv(p,ypw1(1:length(tt)));
%figure;
%subplot(2,1,1),stem(0:550,ypw1(1:length(tt))),axis([0 550 -1 1]);grid on;title('信道冲击响应H(K)');
%subplot(2,1,2),plot(0:length(y)-1,y),axis([0 750 -1 1]);title('脉冲响应P(K)*H(K)');
rsy=double(xcorr(p,y));%求模板信号与接收信号的互相关
figure(3);
subplot(2,1,1),plot(0:length(rsy)-1,rsy);title('模板信号yp和接收信号ypw1的互相关函数');
c=zeros(1,length(p)+length(y)-1);%初始化c(t)
[Y,I]=max(abs(rsy));
Y1=Y;
if (rsy(1,I)>0&X>0)|(rsy(1,I)<0&X<0)
a=Y/X;
elseif Y==0
a=0;
else
a=-Y/X;
end
i=0;
while abs(Y/Y1)>0.001%对rsy的峰值进行迭代运算
c(1,I)=a;
l=zeros(1,length(rsy));
if (I-J)>0
for n=(I-J):(length(rss)+I-J-1)
l(n)=a*rss(n-I+J+1);
end
elseif (J-I)>0
for n=(J-I):(length(rss)+I-J-1)
l(n-J+I+1)=a*rss(n);
end
else
for n=1:length(rss)
l(1,n)=a*rss(1,n);
end
end
rsy=rsy-l;
[Y,I]=max(abs(rsy));
if (rsy(1,I)>0&X>0)|(rsy(1,I)<0&X<0)
a=Y/X;
elseif Y==0
a=0;
else
a=-Y/X;
end
i=i+1;%求迭代次数
end
disp('迭代次数:'),i%显示总的迭代次数
%
%用CLEAN算法求出的信道冲击响应
%
subplot(2,1,2),plot(1:length(p)+length(y)-1,c),axis([0 length(p)+length(y)-1 -2 2]);
title('用CLEAN算法求出的信道冲击响应')
%
%重新设置起始时间
%h1=zeros(1,length(c));
%for k=length(c):-1:1
% if c(k)~=0
h1(length(c)-k+1)=c(k);
end
end
h=zeros(1,length(c));
for i=1:length(h)
if h1(i)~=0
h(i-200)=h1(i);
end
end
figure;
subplot(1,1,1),stem(1:length(p)+length(y)-1,h),axis([0 750 -0.8 0.8]);
title('重新设置起始时间后的信道冲击响应');grid on;
disp('仿真结果可比较figure(4)和figure(2)中的第一个图')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -