📄 fade.m
字号:
% fade.m
% Generate Rayleigh fading
function [theta, ramp, xc, xs] = fade( nsamp, tstp, fm, N1, counter, flat)
%******************* variables *******************************
% nsamp Number of samples to be simulated
% tstp Minimum time resolution
% fm Maximum doppler frequency (Hz)
% N1 Number of waves in order to generate fading
% counter fading counter
% flat flat fading or not
% theta phase of fading channel impulse response (rad)
% ramp Amplitude contaminated by fading
% xc Cosine value contaminated by fading
% xs Sine value contaminated by fading
%***************************************************************
ac0 = sqrt(1.0./(2.0.*(N1+1))); % power nomalized constant(ich)
as0 = sqrt(1.0./(2.0.*N1)); % power nomalized constant(qch)
% some parameters
wm = 2.0.*pi.*fm;
N = 4.*N1+2;
ts = tstp;
wmts = wm.*ts;
paino = pi./N1;
xc=zeros(1,nsamp);
xs=zeros(1,nsamp);
ic=[1:nsamp]+counter;
for nn = 1:N1
cwn = cos(cos(2.0.*pi.*nn./N).*ic.*wmts);
xc = xc+cos(paino.*nn).*cwn;
xs = xs+sin(paino.*nn).*cwn;
end
cwmt = sqrt(2.0).*cos(ic.*wmts);
xc = (2.0.*xc + cwmt).*ac0;
xs = 2.0.*xs.*as0;
ramp=sqrt(xc.^2+xs.^2); % amplitude contaminated by fading
% calculate theta
for i=1:nsamp
if xc(i)>0 & xs(i)>0 % the 1st quadrant
theta(i) = atan(xs(i)/xc(i));
elseif xc(i)<0 & xs(i)<0 % the 3st quadrant
theta(i) = atan(xs(i)/xc(i)) + pi;
elseif xc(i)<0 & xs(i)>0 % the 2nd quadrant
theta(i) = atan(xs(i)/xc(i)) + pi;
else % the 4nd quadrant
theta(i) = atan(xs(i)/xc(i)) + 2*pi;
end
end
end
%******************* end of file **********************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -