-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChaineDeReference.m
120 lines (95 loc) · 2.49 KB
/
ChaineDeReference.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
%% Nettoyage
close all;
clear;
%% Variables initiales
nb_bits = 100000;
info_binaire = randi([0,1], 1,nb_bits);
Fe = 24000;
Rb = 3000;
N = 101;
Tb = 1/Rb;
%% Modulateur
% Variables
Ns = Fe/Rb;
a_1 = 1;
a_0 = -1;
h = ones(1,Ns);
M = 2;
% Calculs
mapping = info_binaire.*(a_1 - a_0) + a_0;
Suite_diracs = kron(mapping, [1 zeros(1, Ns-1)]);
x = filter(h, 1, Suite_diracs);
%DSP
mod_DSP = fftshift(abs(fft(xcorr(x,'unbiased'))));
plage_module=(-Fe/2:Fe/(length(mod_DSP)-1):Fe/2);
%Affichage
%figure('Name',"Modulateur");
%Bit = [0;1];
%Mapping = [a_0;a_1];
%T = table(Bit,Mapping);
%uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,'FontUnits','normalized','FontSize',0.2,'Units','normalized','Position',[0 0.5 0.5 0.5]);
%subplot(2,2,2);
%plot((0:1/Fe:(Ns-1)/Fe), h);
%title('Filtre de mise en forme rectangulaire');
%xlabel('Temps (s)');
%ylabel('Hauteur');
%subplot(2,2,3)
%plot((0:1/Fe:(Ns*nb_bits-1)/Fe), x);
%title('Filtrage du modulateur 1');
%xlabel('Temps (s)');
%ylabel('Amplitude');
%subplot(2,2,4);
%plage_module=(-Fe/2:Fe/(length(mod_DSP)-1):Fe/2);
%semilogy(plage_module,mod_DSP);
%title("DSP du modulateur");
%xlabel('Hz');
%ylabel('Module TFD');
%% Canal de Transmission
%Bruit
N0 = 0.001;
P_x = mean(abs(x).^2);
%E_b = P_x*Tb;
%E_bN0Db = 10*log10(E_b./N0);
%Calcul TEB simulé
Eb_Db = 0:0.01:8;
TEB = [];
for i = Eb_Db
Sigma_n = sqrt((P_x*Ns)/(2*log2(M)*10.^(i/10)));
bruit = Sigma_n*randn(1, length(x));
x_bruite = x + bruit;
hr = ones(1,Ns);
z = filter(hr, 1, x_bruite);
n0 = Ns;
z_echant = z(n0:Ns:end);
info_bin_rec = z_echant > 0;
TEB = [TEB sum(abs(info_bin_rec-info_binaire))/length(info_binaire)];
end;
figure;
semilogy(Eb_Db, TEB);
title('TEB simulé');
%% Demodulateur
%Filtrage de réception
hr = ones(1,Ns);
z = filter(hr, 1, x_bruite);
figure('Name','Signal filtré');
plot((0:1/Fe:(Ns*nb_bits-1)/Fe),z);
title("Signal en sortie de filtre de réception");
xlabel("Temps")
ylabel("Amplitude");
%Echantillonage
z_echant = z(1:Ns:end);
%Décision
info_bin_rec = z_echant > 0;
difference = sum(info_binaire - info_bin_rec);
%Réponse impulsionnelle
g = conv(h,hr);
figure('Name','Convolution');
plot((0:1/Fe:2*(Ns-1)/Fe),g);
oeil = reshape(z, 2*Ns, length(z)/(2*Ns));
figure('Name','Oeil de chai plu tro ki');
plot(oeil);
n0 = Ns;
z_echant_1 = z(n0:Ns:end);
info_bin_rec_1 = z_echant_1 > 0;
taux_erreur_binaire_1 = sum(abs(info_bin_rec_1-info_binaire))/length(info_binaire);
fprintf("Taux d'erreur pour n0 = %.1f $%f.\n", n0, taux_erreur_binaire_1);