Repository navigation
Expand file tree
/
Copy pathsimulation_OFDM_BER.m
More file actions
124 lines (96 loc) · 3.99 KB
/
Copy pathsimulation_OFDM_BER.m
File metadata and controls
124 lines (96 loc) · 3.99 KB
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% BER vs SNR curve with AWGN channel
%
% Copyright (C) 2022 Shiyue He (hsy1995313@gmail.com)
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
close all;
%% Variables
global MCS_TAB MCS_MAX
global N_CP N_LTF N_FFT N_LTFN N_TAIL
global SCREAMBLE_POLYNOMIAL SCREAMBLE_INIT
global MIN_BITS
MHz = 1e6; % 1MHz
Hz = 1;
Nbits = 1024;
SNR_TAB = 1: 3: 30;
BW = 20 * MHz;
BER = zeros(length(SNR_TAB), MCS_MAX);
%% Modules
OFDM_Scrambler = comm.Scrambler( ...
'CalculationBase', 2, ...
'Polynomial', SCREAMBLE_POLYNOMIAL, ...
'InitialConditions', SCREAMBLE_INIT ...
);
OFDM_Descrambler = comm.Descrambler( ...
'CalculationBase', 2, ...
'Polynomial', SCREAMBLE_POLYNOMIAL, ...
'InitialConditions', SCREAMBLE_INIT ...
);
%% Transmisstion
for SNR = SNR_TAB
for MCSi = 1: MCS_MAX
% Transmitter
BitsTX = randi(2, [Nbits, 1]) -1;
Npad = MIN_BITS - mod(size(BitsTX, 1) + N_TAIL, MIN_BITS);
PadedBitsTX = [BitsTX; zeros(Npad + N_TAIL, 1)];
ScrambledBits = OFDM_Scrambler(PadedBitsTX);
EncodedBits = IEEE80211ac_ConvolutionalEncoder(ScrambledBits, MCS_TAB.rate(MCSi));
ModDataTX = qammod(EncodedBits, MCS_TAB.mod(MCSi), 'InputType', 'bit', 'UnitAveragePower',true);
Payload_t = OFDM_Modulator(ModDataTX);
[STF, LTF, DLTF] = OFDM_PreambleGenerator(1);
FrameTX = [STF; LTF; DLTF; Payload_t];
% Channel model: awgn channel
FrameRX = awgn(FrameTX, SNR, 'measured');
% Receiver
[sync_results, LTF_index] = OFDM_SymbolSync(FrameRX, LTF(2*N_CP +1: end, 1));
if LTF_index == N_LTF * 2 % If sync is correct
LTF_RX = FrameRX(LTF_index - N_LTF +1: LTF_index);
DLTF_RX = FrameRX(LTF_index +1: LTF_index + (N_CP + N_FFT) * N_LTFN);
Payload_RX_t = FrameRX(LTF_index + (N_CP + N_FFT) * N_LTFN +1: end);
CSI = OFDM_ChannelEstimator(DLTF_RX, 1, 1);
Payload_RX_f = OFDM_Demodulator(Payload_RX_t, CSI);
DecodedBits = qamdemod(Payload_RX_f, MCS_TAB.mod(MCSi), 'OutputType', 'bit', 'UnitAveragePower',true);
DescrambledBits = IEEE80211ac_ConvolutionalDecoder(DecodedBits, MCS_TAB.rate(MCSi));
TailBitsRX = OFDM_Descrambler(DescrambledBits);
BitsRX = TailBitsRX(1: end - N_TAIL - Npad);
% Transmission result
error_bits = xor(BitsRX, BitsTX);
BER(SNR, MCSi) = sum(error_bits) / Nbits;
clc;
disp(['*********Frame Configuration********']);
disp([' MCS: ' num2str(MCSi)]);
disp(['*********AWGN Channel Model********']);
disp([' SNR: ' num2str(SNR) ' dB']);
disp(['*********Transmission Result*********']);
disp([' Packet length: ' num2str(length(FrameRX) / BW) ' us']);
disp([' Time synchronization successful!']);
disp([' BER: ' num2str(BER(SNR, MCSi))]);
else
BER(SNR, MCSi) = 1;
clc;
disp(['*************************************']);
disp([' Time synchronization error !']);
end
disp(['*************************************']);
end % End of MCS
end % End of SNR
figure;
plot(SNR_TAB, BER);
xlabel('SNR'); ylabel('BER');
title('BER at different SNRs');