-
Notifications
You must be signed in to change notification settings - Fork 10
/
BERTool_QPSK_RicianChannel.m
165 lines (122 loc) · 4.92 KB
/
BERTool_QPSK_RicianChannel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
function [BER, numBits] = BERTool_QPSK_RicianChannel(EbNo, maxNumErrs, maxNumBits)
persistent FullOperatingTime
% Display Line on the Start of Imitation Modeling
disp('======================================');
% Start Time
tStart = clock;
% Total Duration of Imitation Modeling
% Saving for each trials. To restart need 'clear all' command.
if isempty(FullOperatingTime)
FullOperatingTime = 0;
end
%%%%% Initial Information Source %%%%%
% Symbol Rate
Rs = 100e3;
% Symbol Duration
Ts = 1/Rs;
% Number of Symbols per Frame
numFrameSymbols = 1e4;
%%%%% QPSK Modulation %%%%%
% Number of Bits in QPSK Symbol by definition
k = 2;
% QPSK Modulator Object
QPSKModulator = comm.QPSKModulator( ...
'PhaseOffset', pi/4, ...
'BitInput', true, ...
'SymbolMapping', 'Gray' ...
);
% QPSK Demodulator Object
QPSKDemodulator = comm.QPSKDemodulator( ...
'PhaseOffset', QPSKModulator.PhaseOffset, ...
'BitOutput', QPSKModulator.BitInput, ...
'SymbolMapping', QPSKModulator.SymbolMapping, ...
'DecisionMethod', 'Hard decision' ...
);
%%%%% Transionospheric Communication Channel %%%%%
% Discrete Paths Relative Delays
PathDelays = [0 Ts/5];
% Discrete Paths Average Gains
PathAvGains = [0 -10];
% Discrete Paths K Factors
K = [3 3];
% Max Doppler Frequency Shift
fD = 25;
% Rician Channel Object
RicianChannel = comm.RicianChannel( ...
'SampleRate', Rs, ...
'PathDelays', PathDelays, ...
'AveragePathGains', PathAvGains, ...
'NormalizePathGains', true, ...
'KFactor', K, ...
'MaximumDopplerShift', fD, ...
'DirectPathDopplerShift', zeros(size(K)), ...
'DirectPathInitialPhase', zeros(size(K)), ...
'DopplerSpectrum', doppler('Jakes'), ...
'PathGainsOutputPort', true ...
);
% Delay in Rician Channel Object
ChanDelay = info(RicianChannel).ChannelFilterDelay;
% AWGN Channel Object
AWGNChannel = comm.AWGNChannel( ...
'NoiseMethod', 'Signal to noise ratio (SNR)', ...
'SNR', EbNo + 10*log10(k) ...
);
%%%%% Imitation Modeling %%%%%
% Import Java class for BERTool
import com.mathworks.toolbox.comm.BERTool;
% BER Calculator Object
BERCalculater = comm.ErrorRate;
% BER Intermediate Variable
BERIm = zeros(3,1);
% Imitation Modeling Loop
tLoop1 = clock;
while BERIm(2) < maxNumErrs && BERIm(3) < maxNumBits
% Check of User push Stop
if BERTool.getSimulationStop
break;
end
% >>> Transmitter >>>
% Generation of Data Bits
BitsTx = randi([0 1], k*numFrameSymbols, 1);
% QPSK Modulation
SignalTx = QPSKModulator(BitsTx);
% Power of Transmitted Signal
SignalTxPower = var(SignalTx);
% >>> Transionospheric Communication Channel >>>
% Adding zero samples to the end of Transmitted Signal
% to not lose shifted samples caused by delay after Rician Channel
SignalTx = [SignalTx; zeros(ChanDelay, 1)];
% Rician Channel
[SignalChan1, PathGain] = RicianChannel(SignalTx);
% Removing first ChanDelay samples and
% selection of Channel's Signal related to Transmitted Signal
SignalChan1 = SignalChan1(ChanDelay + 1 : end);
% AWGN Channel
AWGNChannel.SignalPower = SignalTxPower;
SignalChan2 = AWGNChannel(SignalChan1);
% >>> Receiver >>>
% Least Squares Solution to remove Fading effects
% on the first Discrete Path
SignalRx = SignalChan2 ./ PathGain(ChanDelay + 1 : end, 1);
% QPSK Demodulation
BitsRx = QPSKDemodulator(SignalRx);
% BER Calculation
BERIm = BERCalculater(BitsTx, BitsRx);
end
tLoop2 = clock;
% BER Results
BER = BERIm(1);
numBits = BERIm(3);
disp(['BER = ', num2str(BERIm(1), '%.5g'), ' at Eb/No = ', num2str(EbNo), ' dB']);
disp(['Number of bits = ', num2str(BERIm(3))]);
disp(['Number of errors = ', num2str(BERIm(2))]);
% Performance of Imitation Modeling
Perfomance = BERIm(3) / etime(tLoop2, tLoop1);
disp(['Perfomance = ', num2str(Perfomance), ' bit/sec']);
% Duration of this Imitation Modeling
duration = etime(clock, tStart);
disp(['Operating time = ', num2str(duration), ' sec']);
% Total Duration of Imitation Modeling
FullOperatingTime = FullOperatingTime + duration;
assignin('base', 'FullOperatingTime', FullOperatingTime);
end