-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.m
87 lines (71 loc) · 2.94 KB
/
main.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
% RAYLEIGH FADING SIMULATION - Comunicaciones Digitales Avanzadas Otoño 2023
% Agustín González - Diego Torreblanca - Luciano Vidal
% Versión con Channel Coding
% ----------------------------------------------------
% Distancia entre símbolos pilotos
pilotos = [5, 10];
% Escenarios a simular
% Placeholder | Número de paths | Velocidad del movil | frecuencia central de la portadora
Scenes = {};
Scenes{1} = {0, 10, 50, 700e6};
Scenes{2} = {0, 10, 50, 2500e6};
Scenes{3} = {0, 10, 50, 5900e6};
% Modulaciones
modulations = ["QPSK", "16QAM"];
% ** Número de escena a simular (1, 2 ó 3) **
n_scene = 1;
scene = Scenes{n_scene};
folder_name = fullfile(pwd, "DATA");
folder_plots = fullfile(pwd, "PLOTS");
% Crea las carpetas donde se guardarán los datos
if ~isfolder(folder_name)
mkdir(folder_name);
end
if ~isfolder(folder_plots)
mkdir(folder_plots);
end
%% Calcular BER
% Usa procesamiento en paralelo (se necesita más de 1 núcleo en el PC)
parfor modulationum = 1:length(modulations)
modulation = modulations(modulationum);
for encodechnl = [false, true]
for n_pilots = pilotos
filename = modulation + "_PILOT_" + num2str(n_pilots) + "_SCENE_" + num2str(n_scene) + "_ENCODED_" + num2str(encodechnl) +".mat";
fullpath = fullfile(folder_name, filename);
[~, ~, BER_linear, ~, BER_perfect] = scenarioBER(modulation, scene, n_pilots, encodechnl);
parsave(fullpath, BER_perfect, BER_linear);
disp(filename)
end
end
end
%% Gráficar resultados (curvas BER)
SNR_list = -2:1:30;
for modulation = modulations
fig = figure('Visible', 'off', 'Position', [0, 0, 1000, 450]);
for n_pilots = pilotos
data_plot = zeros(33, 4);
subplot(1, 2, n_pilots/5)
for encodechnl = [false, true]
filename = modulation + "_PILOT_" + num2str(n_pilots) + "_SCENE_" + num2str(n_scene) + "_ENCODED_" + num2str(encodechnl);
fullpath = fullfile(folder_name, filename + ".mat");
data = load(fullpath);
BER_linear = data.linear;
BER_perfect = data.perfect;
data_plot(:, (encodechnl*2 + 1):(encodechnl*2 + 2)) =[BER_linear', BER_perfect'];
end
semilogy(SNR_list, data_plot, 'LineWidth', 1.05)
subtitle("Pilot distance: " + num2str(n_pilots), 'FontSize', 17)
xlim([-2, 30]);
grid on
legend(["Linear", "Perfect", "Linear Enc.", "Perfect Enc."])
xlabel("$$\frac{E_b}{N_0}$$ [dB]", "Interpreter","latex")
ylabel("BER")
end
sgtitle("BER Curves for " + modulation + " and scenario " + num2str(n_scene), 'FontSize', 20)
exportgraphics(fig, fullfile(folder_plots, modulation + "_BOTHPILOTS" + "_SCENE_" + num2str(n_scene) + "_WITHENCDN_" + ".png"), 'Resolution', 300)
end
%% Funciones auxiliares
% Guarda los datos obtenidos, se necesita al trabajar con 'parfor'
function parsave(fname, perfect, linear)
save(fname, 'perfect', 'linear')
end