📄 channel.m
字号:
function [rxMsg] = Channel(modMsg,avgSnr,sampsPerSymbol,RAYLEIGH,SLOWFADE)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function [rxMsg] = Channel(modMsg,gammaBar)
% This function models the transmission channel. As such, it will
% take modMsg, apply noise and fading, and return rxMsg.
%
% modMsg = modulated message from the transmitter. Assumed to be
% an integer number of symbols, aligned to first sample.
% avgSnr = average received SNR desired, in dB
% sampsPerSymbol = samples per symbol.
% rxMsg = modulated message with AWGN, Rayleigh fading applied.
% Rayleigh fading is constant over a single symbol, and
% currently independent from symbol to symbol.
% To simplify things at the receiver, the signal power
% shall remain constant, as is the case with AGC. This
% means that instead of fading the signal, the noise
% is scaled by 1/fading.
%
% RAYLEIGH = boolean value for Rayleigh fading. If = nonzero value
% (==1), then Rayleigh fading will be applied. Else, just awgn.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (RAYLEIGH)
% Complex Gaussian noise
noiseVect = randn(size(modMsg)) + j*randn(size(modMsg));
fadeVectLength = (length(modMsg)/sampsPerSymbol);
if (SLOWFADE)
fadeVect(1:fadeVectLength,1) = (1/sqrt(2))*abs(randn + j*randn);
else
% Modelling Rayleigh fading as the envelope of complex noise
% Right now, every symbol has independent fading. May have to consider
% correlation time later.
%fadeVectLength = (length(modMsg)/sampsPerSymbol);
fadeVect = (1/sqrt(2))*abs(randn(1,fadeVectLength) + j*randn(1,fadeVectLength));
%fadeVect = ones(1,fadeVectLength);
end
noiseToSigVoltRatio = 10.^(-avgSnr/20);
for ii = 1:fadeVectLength
symbolSamples = (ii-1)*sampsPerSymbol+(1:sampsPerSymbol);
noiseVect(symbolSamples) = noiseVect(symbolSamples)/fadeVect(ii);
end
rxMsg = modMsg + noiseToSigVoltRatio*noiseVect;
else
rxMsg = awgn(modMsg,avgSnr,10*log10(2));
end
return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -