-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkSimulator.m
72 lines (61 loc) · 3.45 KB
/
linkSimulator.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
%% CLEAN
close all;
clear;
clc;
%% SYSTEM PARAMETERS
systemParam.nDataBits = 1e6; % Number of tansmitted bits
systemParam.coding.type = 'none'; % Coding type {'fast','slowWeak','slowStrong','none'}
systemParam.interleaving.type = 'none'; % 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.equalization.type = 'none'; % Equalization type {'zf','none'}
systemParam.multipath.type = 'static-1'; % Multipath type {'static-1','static-2','none'}
systemParam.awgn.EbNo = 10;
systemParam.awgn.EbNoVec = (-10:2:15);% Eb/No in dB or no noise {-10,...,15,'none'}
systemParam.results.enabled = true; % Results enabled {true,false}
%% SYSTEM INITIALIZATION
systemParam = initGroup(systemParam);
systemParam = initCoding(systemParam);
%systemParam = initInterleaving(systemParam);
systemParam = initMapping(systemParam);
systemParam = initOfdm(systemParam);
systemParam = initEqualization(systemParam);
systemParam = initMultipath(systemParam);
systemParam = initAwgn(systemParam);
%% TRANSMITTER
disp('-- Link simulation --------------------------------------------------');
disp('Transmitter ...');
txBits = sourceTx(systemParam); % Data generator
%txBitsEncoded = encoder(systemParam,txBits); % Encoder
%txBitsEncodedInterleaved = interleaver(systemParam,txBitsEncoded); % Interleaver
txSymbols = mapper(systemParam,txBits); % Momentaneo hasta tener interleaver % Symbol mapper
%txSymbols = mapper(systemParam,txBitsEncodedInterleaved); % Symbol mapper
[txOfdmSymbols,indexPilotSc_f] = ofdmModulator(systemParam,txSymbols); % OFDM modulator
%% MULTIPATH FADING CHANNEL
%disp('Multipath fading channel ...');
rxMultipath = multipathChannel(systemParam,txOfdmSymbols); % Multipath fading channel
%% AWGN CHANNEL
%disp('AWGN channel ...');
rxOfdmSymbols = awgnChannel(systemParam,rxMultipath); % AWGN channel
%% RECEIVER PROVA
disp('Receiver ...');
%[rxSymbols,HEstimated] = ofdmDemodulator(systemParam,txOfdmSymbols); % OFDM demodulator
%rxBitsEncodedInterleaved = demapper(systemParam,rxSymbols); % Symbol demapper
%Aqui probamos el Mapper y Demapper sin pasar por OFDM
%pruebademapper = demapper(systemParam,txSymbols); % Symbol demapper
%rxBitsEncoded = deinterleaver(systemParam,rxBitsEncodedInterleaved); % Deinterleaver
%rxBits = decoder(systemParam,rxBitsEncoded); % Decoder
%% RECEIVER PROJECTE
%disp('Receiver ...');
[rxSymbols,HEstimated] = ofdmDemodulator(systemParam,rxOfdmSymbols,indexPilotSc_f); % OFDM demodulator with channel equalization
rxBitsEncodedInterleaved = demapper(systemParam,rxSymbols); % Symbol demapper
%rxBitsEncoded = deinterleaver(systemParam,rxBitsEncodedInterleaved); % Deinterleaver
%rxBits = decoder(systemParam,rxBitsEncoded); % Decoder
systemParam.results.berSimulated = sum(xor(txBits',rxBitsEncodedInterleaved)) / length(txBits');
disp('BER')
disp(systemParam.results.berSimulated)
% scatterplot(rxOfdmSymbols,1,0,'x');
% grid on
% title(['Received symbols (' systemParam.mapping.type ' type)']);xlabel('I');ylabel('Q');
%% SYSTEM RESULTS
%showResults();