-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ejercicio1.m~
93 lines (71 loc) · 4 KB
/
Ejercicio1.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
% Considerar sistema formado por: CODER + INTERLEAVER + MAPPER
% Maximo bit rate que se puede conseguir considerando:
% - Desactivar multipath
% - Ancho de banda de transmision: 3 KHz
% - SNR maxima esperada: 3dB
% - BER maximo admisible: 1e-3 (simulated)
% INDICAR
% Codificador convolucional: tipo
% Interleaver convolucional: tipo
% Mapper: tipo
% Prestaciones: nDataBits, EbNo, SNR, Achieved bit rate, BER (teorico), BER
% conseguido (simulated).
systemParam.nDataBits = 1e6; % Number of tansmitted bits
systemParam.coding.type = 'slowStrong'; % Coding type {'fast','slowWeak','slowStrong','none'}
systemParam.interleaving.type = 'shallow'; % Interleaving type {'deep','shallow','none'}
systemParam.mapping.type = 'qpsk'; % Mapping type {'bpsk','qpsk','qam16','qam64','none'}
systemParam.ofdm.type = 'generic'; % OFDM type {'generic','static-1','static-2','none'}
systemParam.awgn.EbNoVec = (-6:2:10); % Eb/No vector in dB {(-10:15),'none'}
systemParam.awgn.EbNo = 10;
systemParam.results.enabled = true; % Results enabled {true,false}
systemParam = initCoding(systemParam);
systemParam = initInterleaving(systemParam);
systemParam = initMapping(systemParam);
systemParam = initOfdm(systemParam);
disp('-- Link simulation --------------------------------------------------');
disp('Transmitter ...');
txBits = sourceTx(systemParam); % Data generator
txBitsEncoded = encoder(systemParam,txBits); % Encoder
txBitsEncodedInterleaved = interleaver(systemParam,txBitsEncoded); % Interleaver
txSymbols = mapper(systemParam,txBitsEncodedInterleaved); % Symbol mapper
disp('-- Link simulation --------------------------------------------------');
disp('Receiver ...');
rxBitsEncodedInterleaved = demapper(systemParam,txSymbols); % Symbol demapper
rxBitsEncodedDeinterleaved = deinterleaver(systemParam,rxBitsEncodedInterleaved);
rxBits = decoder(systemParam,rxBitsEncodedDeinterleaved);
%% AWGN CHANNEL + RECEIVER
for EbNoIndex = 1:length(systemParam.awgn.EbNoVec)
% AWGN channel
systemParam.awgn.EbNo = systemParam.awgn.EbNoVec(EbNoIndex);
% Get Eb/No
systemParam = initAwgn(systemParam);
disp('AWGN channel ...');
% rxOfdmSymbols = awgnChannel(systemParam,txOfdmSymbols); % AWGN channel
rxOfdmSymbols = awgnChannel(systemParam,txSymbols); % AWGN channel
rxBitsEncodedInterleaved = demapper(systemParam,rxOfdmSymbols); % Symbol demapper
rxBitsEncodedDeinterleaved = deinterleaver(systemParam,rxBitsEncodedInterleaved);
rxBits = decoder(systemParam,rxBitsEncodedDeinterleaved);
% % Receiver
% disp('Receiver ...');
% rxBitsEncodedInterleaved = demapper(systemParam,rxOfdmSymbols); % Symbol demapper
% %Realizamos el de interleaving
% rxBitsEncoded = deinterleaver(systemParam,rxBitsEncodedInterleaved);
% %Realizamos el decoding
% rxBits= decoder(systemParam,rxBitsEncoded);
%% BER computation
systemParam.results.berSimulated(EbNoIndex) = sum(xor(txBits,rxBitsEncodedInterleaved')) / length(txBits);
%disp(sum(xor(txBits,rxBitsEncodedInterleaved')) / length(txBits));
% BER teorico
if strcmp(systemParam.mapping.type,'bpsk')
systemParam.results.berTeorico(EbNoIndex) = berawgn(systemParam.awgn.EbNoVec(EbNoIndex),'psk',2,'nondiff');
elseif strcmp(systemParam.mapping.type,'qpsk')
systemParam.results.berTeorico(EbNoIndex) = berawgn(systemParam.awgn.EbNoVec(EbNoIndex),'psk',2^systemParam.mapping.k,'diff');
elseif strcmp(systemParam.mapping.type,'qam16') || strcmp(systemParam.mapping.type,'qam64')
systemParam.results.berTeorico(EbNoIndex) = berawgn(systemParam.awgn.EbNoVec(EbNoIndex),'qam',2^systemParam.mapping.k,'nondiff');
else
disp('Error en el tipo de modulación.');
end
simbolos_recibidos=rxSymbols;
end
%% SYSTEM RESULTS
showResults();