?? cdmasim.m
字號:
CDMA例子的matlab代碼
主程序:
%file: c18_cdmasim.m
function [BER,ErrorRun]c18_cdmasim(N,SF,EbNo,...
NumInterferers,MPathDelay,Kfactor_dB)
rand('state',sum(100*clock));randn('state',sum(100*clock));
NIterate = 1e3;
NumberOfIterations = ceil(N/NIterate);
ErrorState = 0;ErrorRun = []; RunCount = 1;
Kfactor = 10^(Kfactor_dB/10);
EbNolinear = 10^(EbNo/10);
MPathComponents = length(MPathDelay);
MPathAmp(2:MPathComponents) = rand(MPathComponents-1,1);
ScatPower = MPathAmp*MPathAmp.';
MPathAmp(1) = sqrt(ScatPower*Kfactor);
[fee MaxComponent] = max(MPathAmp);MPathAmp = MPathAmp/fee;
FilterOrder = 4; Ripple = 0.5; BW = 0.01;
[b,a] = cheby1(FilterOrder,Ripple,BW);
if NumInterference > (SF-1)
error(['NumInterferers must not exceed ',int2st(SF-1),'.'])
end
if length(MPathDelay) ~= length(MPathAmp)
error('MPathDelay and MPathAmp must have the same length.')
end
if min(MPathDelay) < 0
error('MPathDelay must not have negative components.')
end
fee = diff(MPathDelay);
if min(fee) <= 0
error('MPathDelay must be monotonically increasing.')
end
clear fee
DesiredSequence = MSequence(SF+1);
offset = fix(length(DesireSequence)/(NumInterferers+1));
M = length(DesiredSequence);
for k=1:NumInterferers
InterfererSequence(k,:) = [DesiredSequence(M-(k-1)*offset:M) ...
DesiredSequence(1:M-1-(k-1)*offset)];
end
zf = zeros(FilterOrder,MPathComponents);
for cnt=1:NumberOfIterations
DesiredSymbols = sign(rand(1,NIterate)-0.5);
InterferingSymbols = sign(rand(NumInterferers,NIterate)-0.5);
DesiredChips = reshape(DesiredSequence.'*DesiredSymbols,1,...
M*NIterate);
for k=1:NumInterferers
InterferingChips(k,:) = reshape(InterfererSequence(k,:).'*...
InterferingSymbols (k,:),1,M*NIterate);
end
NoiseAmplitude = sqrt(SF/(2*EbNolinear));
MaxDelay = max(MPathDelay);
DesiredNoise = NoiseAmplitude*randn(1,M*NIterate+MaxDelay);
MPathLinAmp = MPathAmp;
MPathComponents = length(MPathDelay);
DesiredMPathSignal = zeros(1,M*NIterate+MaxDelay);
if NumInterferers > 0,
InterferingMPathSignal = ...
zeros(NumInterferers,M*NIterate+MaxDelay);
for k=1:MPathComponents
index = 1+MPathDelay(k):NIterate*M+MPathDelay(k);
InterferingMPathSignal(:,index) = ...
InterferingMPathSignal(:,index) + ...
MPathLinAmp(k)*InterferingChips;
end
end
for k=1:MPathComponents
if k==1, fading = ones(1,M*NIterate);
else
fading = randn(size(DesiredSymbols))+...
j*randn(size(DesiredSymbols));
[fading zf(:,k)] = filter(b,a,fading,zf(:,k));
fading = interp(fading,SF);
fading = abs(fading/sqrt(mean(fading.*conj(fading))));
end
if k == MaxComponent
fadesign = sign(fading);
end
faa(k,:) = MPathLinAmp(k)*fading;
index = 1+MPathDelay(k):NIterate*M+MPathDelay(k);
DesiredMPathSignal(index) = ...
DesiredMPathSignal(index)+...
(MPathLinAmp(k)*fading).*DesiredChips;
end
if NumInterferers > 0
IncomingSignal = DesiredMPathSignal+...
sum(InterferingMPathSignal,1)+DesiredNois;
else
IncomingSignal = DesiredMPathSignal+DesiredNoise;
end
index = 1+MPathDelay(MaxComponent):M*NIterate+...
MPathDelay(MaxComponent);
IncomingChips = reshape(fadesign.*...
IncomingSignal(index),M,NIterate);
DespreadSymbols = DesiredSequence*IncomingChips;
DetectedSymbols = sign(DespreadSymbols);
ErrorVevtor = 0.5*abs(DetectedSymbols-DesiredSymbols);
ErrorsIterate(cnt) = sum(ErrorVector);
BERIterate(cnt) = ErrorsIterate(cnt)/NIterate;
for k=1:NIterate
if (ErrorVector(k) == 0) & (ErrorState == 0)
RunCount = RunCount+1;
elseif (ErrorVector(k) == 0) & (ErrorState == 1)
ErrorRun = [ErrorRun RunCount];
RunCount = 1; ErrorState = 0;
elseif (ErrorVector(k) == 1) & (ErrorState == 0)
ErrorRun = [ErrorRun RunCount];
RunCount = 1; ErrorState = 1;
elseif (ErrorVector(k) == 1) & (ErrorState == 1)
RunCount = RunCount+1;
else
s1 = sprintf('ErrorVector(%d)=%d, ...
ErrorState=%d! Unexpected Condition!');
error(s1);
end
end
end
Errors = sum(ErrorsIterate); BER = mean(BERIterate);
ErrorRun = [ErrorRun RunCount];
% End of function file.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -