📄 qpskrun.m
字号:
% file c10_MCQPSKrun.m
% Software given here is to accompany the textbook: W.H. Tranter,
% K.S. Shanmugan, T.S. Rappaport, and K.S. Kosbar, Principles of
% Communication Systems Simulation with Wireless Applications,
% Prentice Hall PTR, 2004.
%
function [BER_MC,Errors]=QPSKrun(N,Eb,No,ChanAtt,...
TimingBias,TimingJitter,PhaseBias,PhaseJitter)
fs = 1e+6; % sampling Rate (samples/second)
SymRate = 1e+5; % symbol rate (symbols/second)
Ts = 1/fs; % sampling period
TSym = 1/SymRate; % symbol period
ChanBW = 4.99e+5; % bandwidth of channel (Hz)
MeanCarrierPhaseError = PhaseBias; % mean of carrier phase
StdCarrierPhaseError = PhaseJitter; % stdev of phese error
MeanSymbolSyncError = TimingBias; % mean of symbol sync error
StdSymbolSyncError = TimingJitter; % stdev of symbol sync error
ChanGain = 10^(-ChanAtt/20); % channel gain (linear units)
TxBitClock = Ts/2; % transmitter bit clock
RxBitClock = Ts/2; % reciever bit clock
BlockSize = 1000;
SamplesPerSymbol = 10;
RxBitsI = zeros(1,BlockSize);
RxBitsQ = zeros(1,BlockSize);
Errors = 0;
SampPerSym = fs/SymRate;
NumberOfBlocks = floor(N/BlockSize);
RxNoiseStd = sqrt((10^((No-30)/10))*fs/2); % stdev of noise
TxSigAmp = sqrt(10^((Eb-30)/10)*SymRate);
h = sqrc(1,10,4,0.5);
for Block=1:NumberOfBlocks
[TxI,SourceBitsI] = random_binary(BlockSize,1);
[TxQ,SourceBitsQ] = random_binary(BlockSize,1);
% Make a complex data stream of the I and Q bits.
%
% TxBits_temp = ((TxBitsI*2)-1)+(sqrt(-1)*((TxBitsQ*2)-1));
TxBits_temp = TxI + (sqrt(-1)*TxQ);
TxBits = upsamp(TxBits_temp,SamplesPerSymbol);
% for count =1:SamplesPerSymbol
% TxBits_temp2(count,:) = TxBits_temp;
% end
%
% TxBits = reshape(TxBits_temp2,1,BlockSize*SamplesPerSymbol);
TxOutput = TxBits*TxSigAmp;
Rx = conv(TxOutput,h);
% t = 0:1:length(Rx)-1; % time vector for plot
% subplot(2,1,1);
% stem(t,real(Rx),'.'); % plot h[n-10]
% grid;
% xlabel('Time');
% ylabel('h[n-1]');
Rx=(ChanGain*Rx)+(RxNoiseStd*(randn(1,length(Rx))+sqrt(-1)*randn(1,length(Rx))));
PhaseRotation = exp(sqrt(-1)*2*pi*...
(MeanCarrierPhaseError+(randn(1,1)*StdCarrierPhaseError))/360);
Rx=Rx*PhaseRotation;
IntegratorOutput = conv (Rx,h);
% subplot(2,1,2);
% t = 0:1:length(IntegratorOutput)-1; % time vector for plot
% stem(t,real(IntegratorOutput),'.'); % plot conv of h[n-10] and h[n]
% grid;
% xlabel('Time');
% ylabel('conv(h[n-1],h[n])');
%
for k=1:BlockSize
m = 1+round(SamplesPerSymbol*(k+MeanSymbolSyncError+StdSymbolSyncError*randn(1,1)));
if (m < length(IntegratorOutput))
RxBitsI(k) = (1-sign(real(IntegratorOutput(m))))/2;
RxBitsQ(k) = (1-sign(imag(IntegratorOutput(m))))/2;
end
end
[C,Lags] = vxcorr(SourceBitsI(10:990),RxBitsI(10:990));
[MaxC,LocMaxC] = max(C);
BestLag = Lags(LocMaxC);
if BestLag > 0
SourceBitsI = SourceBitsI(BestLag+1:length(SourceBitsI));
SourceBitsQ = SourceBitsQ(BestLag+1:length(SourceBitsQ));
elseif BestLag < 0
RxBitsI = RxBitsI(-BestLag+1:length(RxBitsI));
RxBitsQ = RxBitsQ(-BestLag+1:length(RxBitsQ));
end
TotalBits = min(length(SourceBitsI),length(RxBitsI));
TotalBits = TotalBits-20;
SourceBitsI = SourceBitsI(10:TotalBits);
SourceBitsQ = SourceBitsQ(10:TotalBits);
RxBitsI = RxBitsI(10:TotalBits);
RxBitsQ = RxBitsQ(10:TotalBits);
%
% Find the number of errors and the BER.
%
Errors = Errors + sum(SourceBitsI ~= RxBitsI) + sum(SourceBitsQ ~= RxBitsQ);
end
%
% Find the number of errors and the BER.
%
BER_MC = Errors/(2*(NumberOfBlocks*length(SourceBitsQ)));
% End of function file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -