-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBERTool_MPSK.m
140 lines (102 loc) · 3.96 KB
/
BERTool_MPSK.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
function [BER, numBits] = BERTool_MPSK(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 = 1e3;
% Number of Symbols per Frame
numSymbols = 1e4;
%%%%% M-PSK Modulation %%%%%
% Modulation Order
M = 2;
% Number of Bits in Symbol
k = log2(M);
% M-PSK Modulator Object
MPSKModulator = comm.PSKModulator( ...
'ModulationOrder', M, ...
'BitInput', true, ...
'PhaseOffset', 0, ...
'SymbolMapping', 'Gray' ...
);
% M-PSK Demodulator Object
MPSKDemodulator = comm.PSKDemodulator( ...
'ModulationOrder', MPSKModulator.ModulationOrder, ...
'BitOutput', MPSKModulator.BitInput, ...
'PhaseOffset', MPSKModulator.PhaseOffset, ...
'SymbolMapping', MPSKModulator.SymbolMapping, ...
'DecisionMethod', 'Hard decision' ...
);
%%%%% HF Communication Channel with Multipath and Signal Fading %%%%%
% Rayleigh Channel Object
RayleighChannel = stdchan( ...
'iturHFMD', ...
Rs, ...
1 ...
);
RayleighChannel.PathGainsOutputPort = true;
% Delay in Channel Object
chanDelay = info(RayleighChannel).ChannelFilterDelay;
% AWGN Channel Object
AWGNChannel = comm.AWGNChannel( ...
'NoiseMethod', 'Signal to noise ratio (Eb/No)', ...
'EbNo', EbNo, ...
'SignalPower', 1, ...
'BitsPerSymbol', 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
DataTx = randi([0 1], k*numSymbols, 1);
% M-PSK modulation
SignalTx = MPSKModulator(DataTx);
% >>> HF Communication Channel with Multipath and Signal Fading >>>
% Rayleigh Channel
[SignalChan1, PathGains] = RayleighChannel(SignalTx);
% AWGN Channel
SignalChan2 = AWGNChannel(SignalChan1);
% >>> Receiver >>>
% Least squares solution
SignalRx = SignalChan2 ./ PathGains(:,1);
% M-PSK Demodulation
DataRx = MPSKDemodulator([SignalRx(chanDelay+1:end); zeros(chanDelay,1)]);
% BER Calculation
BERIm = BERCalculater(DataTx, DataRx);
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
Performance = BERIm(3) / etime(tLoop2, tLoop1);
disp(['Performance = ', num2str(Performance), ' 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