⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdmasim.m

📁 一个多径/衰落环境下的CDMA系统
💻 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 + -