📄 uplinksimulator.m
字号:
function CorrectErrorRun = UplinkSimulator(SimConfig)
%******************************************************************************************************
%function CorrectErrorRun = UplinkSimulator(SimConfig)
%
%Copyright 2002 The Mobile and Portable Radio Research Group
%
%The uplink simulator emulates the operation of a WCDMA mobile station in a frequency selective,
%multipath fading channel. The simulation makes every attempt to model the behavior of a mobile
%station as specified in the WCDMA standards, specifically ETSI TS 125 211 and ETSI TS 125.213.
%Accordingly, the simulator emulates up to six Dedicated Physical Data Channels (DPDCHs) and the
%Dedicated Physical Control Channel (DPCCH). A Mutual Access Interference (MAI) environment is generated
%by generating signals from "interfering mobiles," which are assumed to operate in the same cell.
%A form of power control is assumed in this simulation. The average received power from each of
%the interfering mobile is equal to the average received power from mobile of interest. Each transmitted
%signal (desired or interfering) passes through a specular multipath fading channel.
%The parameters used to define this channel include number of multipath components, relative delay of
%each multipath component, average amplitude of each multipath component, and Doppler frequency.
%
%Parameters
% Input
% SimConfig Structure with the following fileds
% MaxInteration The number of Radio Frames to be processed
% PulseLength The length of the pulse shape filter used by the
% transmitter and receiver
% SamplesPerChip Oversampling rate
% EbNo_db Bit energy to noise density ratio in decibels
% Velocity Velocity of mobile in km/hr
% NumPilot Number of Pilot symbols per frame in the DPCCH
% MaxOffset Maximum frame offset for each of the interfering mobile stations
% NumInterferer Number of Interfering mobile stations
% NumDPDCH Number of DPDCHs used by the mobile station (can range from 1 to 6)
% SF Spreading Factor
% Delay (array) Multipath delay profile (delays expressed in units of seconds)
% Amp (array) Multipath amplitude profile (amplitude expressed in decibels)
% BetaC Weight gain for the DPCCH
% BetaD Weight gain for the DPDCH(s)
% MPathFlag 1: MAI signals go through multipath fading channel
% 0: MAI signals do not go through multipath fading channel
% (AWGN channel only)
%
% Output
% CorrectErrorRun sequence is a collection of positive integers that denote the
% number of consecutive correct decisions made, followed by the number
% of consecutive errors made, followed by the number of consecutive
% correct decisions made, and so forth.
%******************************************************************************************************
%Extract Values from structure
MaxIteration=SimConfig.NumIterations;
PulseLength=SimConfig.PulseLength;
SamplesPerChip=SimConfig.SamplesPerChip;
EbNo_db=SimConfig.EbNo_db;
Velocity=SimConfig.Velocity;
N_pilot=SimConfig.NumPilot;
MaxOffset=SimConfig.MaxOffset;
NumInterferers=SimConfig.NumInterferer;
NumDPDCH=SimConfig.NumDPDCH;
SF=SimConfig.SF;
MpathDelayTaps=SimConfig.Delay;
MpathDelayRelAmpdB=SimConfig.Amp;
ControlBeta=SimConfig.BetaC+1;
DataBeta=SimConfig.BetaD+1;
MAI_MPATH_FLAG=SimConfig.MPathFlag;
%Set up Status Bar
WaitBarHandle=waitbar(0,'Simulation in Progress');
waitbar(1e-4,WaitBarHandle);
%Pulse Shape Paramters
UBound = PulseLength/2;
LBound = -UBound;
rand('state',sum(100*clock)); %Initialize random number generator
clear RcvdDataBits
MpathDelayRelAmp=10.^(MpathDelayRelAmpdB/20);
SpeedOfLight=3e8;
ROLLOFF=0.22;
%Weights associated with channel gain codes
beta_code=[0 0.0667 0.1333 0.2 0.2667 0.333 0.4 0.4667 0.5333 0.6 0.6667 0.7333 0.8 0.8666 0.9333 1.0];
beta_c=beta_code(ControlBeta);
beta_d=beta_code(DataBeta);
%Radio Frame Parameters
ChipsPerFrame= 38400;
ChipPeriod=1;
FrameDuration=10e-3;
fSample=SamplesPerChip*ChipsPerFrame/FrameDuration; %Sample Rate
%EbNo and noise variaince parameters
EbNo=10^(EbNo_db/10);
variance=SF/(EbNo);
STDV=sqrt(variance);
%Fading and multipath parameters
ChipsPerFadeSample=400; %Each fade sample corresponds to 400 chips
frequency=1980; %Carrier Frequency in MHz--Assumed frequency of operation for this simulation
fadeCoefficients=[];
fDoppler=(Velocity*5/18)/(SpeedOfLight/(frequency*1e6));
MpathDelaySamples=round(MpathDelayTaps*fSample);
%Generate Pulse Shape
[PulseShape,t]=GenRootRaisedCosine(LBound,UBound,SamplesPerChip,ROLLOFF,ChipPeriod);
PulseShape=PulseShape/(PulseShape.'*PulseShape);
%generate scramble code
code_number=round((2^24-1)*rand(1));
scramble_code=scramble_long(code_number);
%generate channel code
chan_code=ovsf_code(SF);
%******************************************************
%Generate initial Signals for MAI
for k=1:NumInterferers
%Random Generation of Control Bits
%The specific sequence should not be that important
ControlBits=sign(rand(1,150)-0.5);
%Generate Scramble Sequence
ScrambleCode=scramble_long(round((2^24-1)*rand(1)));
%Generate uplink Frame for interferer
UplinkFrame=gen_uplink_wcdma_frame(1,ScrambleCode.',chan_code,ControlBits,1,1);
CurrentMAISignals(k,:)=GenWCDMAUplinkSignal(UplinkFrame,UplinkFrame,UplinkFrame,PulseShape,SamplesPerChip);
%Random Generation of Control Bits
%The specific sequence should not be that important
ControlBits=sign(rand(1,150)-0.5);
%Generate Scramble Sequence
ScrambleCode=scramble_long(round((2^24-1)*rand(1)));
%Generate uplink Frame for interferer
UplinkFrame=gen_uplink_wcdma_frame(1,ScrambleCode.',chan_code,ControlBits,1,1);
PriorMAISignals(k,:)=GenWCDMAUplinkSignal(UplinkFrame,UplinkFrame,UplinkFrame,PulseShape,SamplesPerChip);
end
%******************************************************
%generage control channel data
DPCCH_code=gen_DPCCH_code(N_pilot);
%generage complex symbols for uplink frame
[uplink_frame0,DataBits0]=gen_uplink_WCDMA_frame(NumDPDCH,scramble_code.',chan_code,DPCCH_code,beta_c,beta_d);
[uplink_frame1,DataBits1]=gen_uplink_WCDMA_frame(NumDPDCH,scramble_code.',chan_code,DPCCH_code,beta_c,beta_d);
[uplink_frame2,DataBits2]=gen_uplink_WCDMA_frame(NumDPDCH,scramble_code.',chan_code,DPCCH_code,beta_c,beta_d);
%generate uplink signals
uplink_signal0=GenWCDMAUplinkSignal(uplink_frame0,uplink_frame2,uplink_frame1,PulseShape,SamplesPerChip);
uplink_signal1=GenWCDMAUplinkSignal(uplink_frame1,uplink_frame0,uplink_frame2,PulseShape,SamplesPerChip);
CurrentErrorState='c';
counter=1;
CorrectErrorRun=[];
for iterate=1:MaxIteration
[uplink_frame3,DataBits3]=gen_uplink_WCDMA_frame(NumDPDCH,scramble_code.',chan_code,DPCCH_code,beta_c,beta_d);
uplink_signal2=GenWCDMAUplinkSignal(uplink_frame2,uplink_frame1,uplink_frame3,PulseShape,SamplesPerChip);
%We will also assume that the channel is a specular multipath fading channel
%***************************************************************************
%We need to see if computing fading coefficients are necessary
%The computation of fading coefficients is determined by the Doppler frequency,
%fDoppler. If the fDoppler is less than 25, then we generate one fading
%coefficient per WCDMA frame. Otherwise, we generate one fading coeffcient
%per time slot (i.e., 15 coeffcients per frame).
%
%We generate a series of fading coefficients. We then run the simulation,
%incorporating those coefficients as the simulation progresses. When, we have
%exhausted the current set of coefficients, we then generate another set of
%fading coefficients. This approach (1) ensures that the fading coefficients
%have the correct spectrum and (2) maximizes simulation speed. With the exception
%of some very long simulations, only one set should be sufficient.
%***************************************************************************
if (length(MpathDelaySamples)==1)&(fDoppler==0)
RvcVectorSignal=uplink_signal1;
else
FadeBufferLength=2^12;
fDopplerSampleRate = ChipsPerFrame/(FrameDuration*ChipsPerFadeSample);
if isempty(fadeCoefficients)
for k=1:length(MpathDelaySamples)
fadeCoefficients(:,k)=MpathDelayRelAmp(k)*Rayleigh(fDoppler,fDopplerSampleRate,FadeBufferLength);
end
elseif length(fadeCoefficients(:,1))<(3*ChipsPerFrame/ChipsPerFadeSample)
fadeCoefficients=[];
for k=1:length(MpathDelaySamples)
fadeCoefficients(:,k)= MpathDelayRelAmp(k)*Rayleigh(fDoppler,fDopplerSampleRate,FadeBufferLength);
end
end
%Process the signal through the specular multipath channel.
RvcVectorSignal=WCDMAMPathChannel(uplink_signal0,...
uplink_signal1,...
uplink_signal2,...
MpathDelaySamples,...
fadeCoefficients(1:3*ChipsPerFrame/ChipsPerFadeSample,:),...
length(PulseShape),...
SamplesPerChip);
fadeCoefficients(1:ChipsPerFrame/ChipsPerFadeSample,:)=[]; %Deystroy Matrix Just Used
end
if NumInterferers >0
if MAI_MPATH_FLAG == 1 %Incorporate multipath in MAI
[y,NextMAISignals]=MAI_Processor(CurrentMAISignals,PriorMAISignals,chan_code,SamplesPerChip,PulseShape,MaxOffset,MpathDelaySamples,MpathDelayRelAmp,fDoppler);
else %Do not incorporate multipath in MAI
[y,NextMAISignals]=MAI_Processor(CurrentMAISignals,PriorMAISignals,chan_code,SamplesPerChip,PulseShape,MaxOffset,MpathDelaySamples);
end
else
y=zeros(size(RvcVectorSignal));
end
%Generate Noise
NoiseVectorSignal=STDV*(randn(size(RvcVectorSignal))+j*randn(size(RvcVectorSignal)));
RvcVectorSignal=RvcVectorSignal+NoiseVectorSignal+y;
%CurrentMAISignals already used. Shift Signals over
if NumInterferers >0
PriorMAISignals=CurrentMAISignals;
CurrentMAISignals=NextMAISignals;
end
%RAKE receiver goes here
%This is intended for scalar channels
[RcvdDataBits,RcvdControlBits]=ThePerfectRake(RvcVectorSignal,MpathDelaySamples,length(uplink_signal1),PulseShape,SamplesPerChip,chan_code,NumDPDCH,DPCCH_code,N_pilot,scramble_code);
%Prepare for error count
[nrow,ncol]=size(RcvdDataBits);
for k=1:NumDPDCH
for m=1:ncol
if (CurrentErrorState == 'c') & (RcvdDataBits(k,m) == DataBits1(k,m))
counter=counter+1;
elseif (CurrentErrorState == 'c') & (RcvdDataBits(k,m) ~= DataBits1(k,m))
CorrectErrorRun=[CorrectErrorRun counter];
counter=1;
CurrentErrorState = 'e';
elseif (CurrentErrorState == 'e') & (RcvdDataBits(k,m) ~= DataBits1(k,m))
counter=counter+1;
elseif (CurrentErrorState == 'e') & (RcvdDataBits(k,m) == DataBits1(k,m))
CorrectErrorRun=[CorrectErrorRun counter];
counter=1;
CurrentErrorState = 'c';
end
end
end
%Prepare for next iteration
uplink_signal0=uplink_signal1;
uplink_signal1=uplink_signal2;
uplink_frame0=uplink_frame1; DataBits0=DataBits1;
uplink_frame1=uplink_frame2; DataBits1=DataBits2;
uplink_frame2=uplink_frame3; DataBits2=DataBits3;
% disp(iterate)
waitbar(iterate/MaxIteration,WaitBarHandle);
end
CorrectErrorRun=[CorrectErrorRun counter];
close(WaitBarHandle);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -