📄 channel.m
字号:
function [y,h]=channel(input,fc,sample_times,duration)
N=3; %Number of multipath
ns=1e-9;%nano-
M=1e6;%Mega-
% fc Central freq.
a=1;%Amplitude set unit here
% [x,mn,mx,fs]=Gaussian_trend(0.025*ns,fc,length(input));% carrier pulse trend with chiprate=fc/3
% % segma=0.025ns,
% % fs is sample frquency
sg=10^(3/10);% the attenuation factor alpha's std.
% d=p_shaping(input,sample_times);
% m=d.*x;
t=duration;%sample time duration is the full length of trend
n=sg*randn;% Normal distribution with segma equal to sg.
X=10^(n/20);%log-normal shadowing factor
h=zeros(1,length(t));
num=0;
while num<N
mag_alpha=10^(sg*randn/10);%magnitude of alpha with log-normal distribution
ang_alpha=pi*rand;%angle of alpha with uniform distribution
alpha=mag_alpha*exp(ang_alpha);
T=pi*rand*10^-9;%Delay T
if (T<=5e-9)&&(alpha*X>=10)
pos=max(find(T>=t))+1;%find the smallest time point which greater than T
h(pos)=h(pos)+alpha*X;
num=num+1;
end
end
figure;
subplot(2,1,1)
stem(t(1:200),h(1:200));
% H=fft(h,1024);
% Ph=H.*conj(H)/1024;
% fh=fs*(0:512)/1024;
% subplot(2,1,2)
% semilogy(fh,Ph(1:513));
% %% convolove the data with channal impulse response
y=zeros(1,2*length(input));
position=find(h);
for i=1:N
y(position(i):position(i)+length(input)-1)=y(position(i):position(i)+length(input)-1)+h(position(i))*input;
end
% figure;
% t2=0:1/fs:(length(y)-1)/fs;
% plot(t2,y);
% figure;
% subplot(2,1,1)
% stem(t,d);
% subplot(2,1,2)
% plot(t,m);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -