📄 rayleigh.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Property of Freescale
% Freescale Confidential Proprietary
% Freescale Copyright (C) 2005 All rights reserved
% ------------------------------------------------------------------------
% $RCSfile: rayleigh.m.rca $
% $Date: Tue Oct 31 16:35:09 2006 $
% Target: Matlab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 802.16-2004 OFDMA PHY - Rayleigh Fading Waveform Generator
%
% Description: Z=rayleigh(Ts,fd,OutLen,ChanNum,samp_index,M) generates
% samples of a rayleigh fading channel according to the
% modified Jakes model described in "Improved Models for the
% Generation of Multiple Uncorrelated Rayleigh Fading Waveforms",
% IEEE Comm Letters, Vol. 6, No. 6, June 2002. The channel is
% generated at a sample rate which is at least 40X the maximum
% doppler frequency, then interpolated to the desired sample rate
% using a 2nd order curve fit.
%
% Output: Z => Each column of Z contains OutLen complex samples of a
% complex fading channel. The output channels are mutually
% uncorrelated. The adjacent columns cannot be made to be
% continuous.
%
% Inputs:
% Ts => Sample period in seconds.
% fd => Doppler frequency in Hz.
% OutLen => Number of output samples in each channel.
% ChanNum => Number of channels to output (one per column).
% This argument is optional. Default is 1.
% samp_index => sample index. Useful for simulating non-
% contiguous bursts of data (i.e. GSM). This
% argument is optional. Default is 0;
% M => Number of sinusiods to mix together in the Jakes model.
% This argument is optional and defaults to 8.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Zout=rayleigh(TsIn,fd,OutLenIn,ChanNum,samp_index,M)
if nargin==3
samp_index=0;
ChanNum=1;
M=8;
end
if nargin==4
samp_index=0;
M=8;
end
if nargin==5
M=8;
end
% The following variables only need to be recalculated on the first
% function call in a simulation. They are retained in memory within the
% scope of the function.
persistent theta cos_alpha sin_alpha psi phi IntRate Ts h OutLen Z0
% Initialize the persistent variables if they have not been initialized or
% if the sample index is set to zero.
if samp_index==0 | (fd~=0 & isempty(theta)) | (fd==0 & isempty(Z0)) ,
if fd==0
for k=1:ChanNum,
Z0(1:OutLenIn,k)=(1/sqrt(2))*(randn+sqrt(-1)*randn)*ones(OutLenIn,1);
end
else
% Internal sample rate is normally chosen to be 40X the doppler frequency.
% A higher sampling rate is chosen in some cases to ensure at least 20 fading
% samples are calculated.
IntRate=min([floor(1/(40*TsIn*fd)) floor(OutLenIn/min([OutLenIn 20]))]);
Ts=TsIn*IntRate;
OutLen=ceil(OutLenIn/IntRate)+6;
% A 2nd order curve fit is implemented by using a polyphase filter with a parabolic
% impulse response.
h=conv(conv(boxcar(IntRate),boxcar(IntRate)),boxcar(IntRate));
h=IntRate*h/sum(h);
% Three phase matrices from IEEE paper.
for k=1:ChanNum
theta=2*pi*(rand-0.5);
cos_alpha(k,:)=cos(0.25*(2*pi*(1:M)-pi+theta)/M);
sin_alpha(k,:)=sin(0.25*(2*pi*(1:M)-pi+theta)/M);
psi(k,:)=2*pi*(rand(1,M)-0.5);
phi(k,:)=2*pi*(rand(1,M)-0.5);
end
end
end
if fd==0
Zout=Z0;
else
% Convert the first sample index to the proper sampling rate. Start a few samples early to
% eliminate transient on the begining.
samp_index=round(samp_index/IntRate)-3;
% Model from IEEE paper.
wdt=2*pi*fd*Ts*(samp_index:1:samp_index+OutLen-1)';
Z=zeros(OutLen,ChanNum);
for k=1:ChanNum,
Z(:,k)=sum(cos(wdt*cos_alpha(k,:)+ones(OutLen,1)*phi(k,:)),2)+sqrt(-1)*sum(cos(wdt*sin_alpha(k,:)+ones(OutLen,1)*psi(k,:)),2);
end
% Interpolate to the desired sample rate using a polyphase filter.
% for k=1:ChanNum
% temp = zeros(OutLen*IntRate,1);
% temp(1:IntRate:end) = sqrt(1/M)*Z(:,k);
% temp = [temp;zeros(ceil(length(h)/2),1)];
% Zout(:,k) = filter(h,1,temp);
% end
Zout=upfirdn(sqrt(1/M)*Z,h,IntRate,1);
% Remove transients from the begining and end of the waveform.
[Zlen c]=size(Zout);
StartTail=floor((Zlen-OutLenIn)/2);
Zout=Zout(StartTail+1:StartTail+OutLenIn,:);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -