clear; F0 = 1180; F1 = 980; Fe = 48000; Te = 1/Fe; Ts = 1/300; Ns = floor(Ts/Te); % Question 3.1.1.1 bits = randi([0, 1], 1, 300); NRZ = repelem(bits, Ns); T = 0:Te:1-Te; % Question 3.1.1.2 %plot(T, NRZ); %xlabel("temps (s)"); %ylabel("NRZ(t)"); % Question 3.1.1.3 %N_fft = 48000; %F = 0:1/N_fft:Fe; %perio = abs(fft(NRZ, N_fft)).^2/N_fft; %semilogy(perio); %periodogram(NRZ); % Question 3.1.2.1 phi = 2*pi*rand(2, 1); X = (1-NRZ).*cos(2*pi*F0*T + phi(1)) + NRZ.*cos(2*pi*F1*T + phi(2)); %plot(T, X); %xlabel("temps (s)"); %ylabel("X(t)"); % Question 3.1.2.4 %periodogram(X); % Question 3.2 N = 48000; Px = mean(abs(X).^2); Pb = Px / 10^(10/10); sigma = sqrt(Pb); bruit = sigma*randn(1, N); Xb = X + bruit; %periodogram(Xb); %plot(Xb); %semilogy([0:N-1]/N*Fe, abs(fft(Xb, N))); %hold; % Question 3.3.1 : Passe-bas fc_tild = 1080/Fe; A = 1; ordre = 100; B = 2*fc_tild*sinc(2*fc_tild*[-ordre/2:1:ordre/2]); Xf = filter(B, A, Xb); %plot(Xf); %plot([0:N-1]/N*Fe, abs(fft(B, N))); %legend("fft(B)"); %title("Filtre passe bas d'ordre 100"); %xlabel("Fréquence (Hz)"); %ylabel("Gain (dB)"); %plot([-ordre/2:1:ordre/2], B); %plot(B) %title("Coefficients de B pour un passe bas d'ordre 100"); %ylabel("B"); %semilogy([0:N-1]/N*Fe, abs(fft(Xb, N))); %hold; %semilogy([0:N-1]/N*Fe, abs(fft(Xf, N))); %legend("Xb", "Xf\_bas"); %title("fft du signal avant et après filtrage"); %xlabel("Fréquence (Hz)"); %ylabel("Amplitude (dB)"); %periodogram(Xb); %hold; %periodogram(Xf); %legend("Xb", "Xf\_bas"); %h = get(gca, 'Children'); %set(h(1), 'Color', [0.8500, 0.3250, 0.0980]); %title("périodogramme avant et après filtrage"); % Question 3.3.2 : Passe-haut fc_tild = 1080/Fe; ordre = 100; B = -2*fc_tild*sinc(2*fc_tild*[-ordre/2:1:ordre/2]); A = 1; B(ordre/2+1) = 1 - 2*fc_tild; Xf = filter(B, A, [Xb zeros(1, ordre/2)]); Xf = Xf(ordre/2:length(Xf)); % Le filtre est une version tronquée de la réponse idéale %plot(Xf); %plot([0:N-1]/N*Fe, abs(fft(B, N))); %legend("fft(B)"); %title("Filtre passe haut d'ordre 100"); %xlabel("Fréquence (Hz)"); %ylabel("Gain (dB)"); %plot([-ordre/2:1:ordre/2], B); %plot(B) %title("Coefficients de B pour un passe haut d'ordre 100"); %ylabel("B"); %semilogy([0:N-1]/N*Fe, abs(fft(Xb, N))); %hold; %semilogy([0:N-1]/N*Fe, abs(fft(Xf, N))); %legend("Xb", "Xf\_haut"); %title("fft du signal avant et après filtrage"); %xlabel("Fréquence (Hz)"); %ylabel("Amplitude (dB)"); periodogram(Xb); hold; periodogram(Xf); legend("Xb", "Xf\_haut"); h = get(gca, 'Children'); set(h(1), 'Color', [0.8500, 0.3250, 0.0980]); title("périodogramme avant et après filtrage"); % Question 3.3.5 K = 30; % 70 avant, trouver comment le trouver de manière programmatique recup = []; bits_recup = []; for i = 0:N/Ns-1 somme = sum( Xf( i*Ns+1 : (i+1)*Ns ).^2 ); recup = [recup, somme]; if somme >= K bits_recup = [bits_recup, 0]; else bits_recup = [bits_recup, 1]; end end bits - bits_recup; erreur = sum((bits - bits_recup).^2)/N*Ns % 3.4 fait, à rédiger au propre pour le rapport % Question 4.1 branche_haut = X.*cos(2*pi*F0*T + phi(1)); branche_haut_integral = sum(reshape(branche_haut, [Ns, length(branche_haut)/Ns])); branche_bas = X.*cos(2*pi*F1*T + phi(2)); branche_bas_integral = sum(reshape(branche_bas, [Ns, length(branche_bas)/Ns])); somme = branche_bas_integral - branche_haut_integral; result = double(somme > 0); %erreur = sum((bits - result).^2)/N*Ns % Question 4.2 branche_1 = X.*cos(2*pi*F0*T); branche_1_integral = sum(reshape(branche_1, [Ns, length(branche_1)/Ns])).^2; branche_2 = X.*sin(2*pi*F0*T); branche_2_integral = sum(reshape(branche_2, [Ns, length(branche_2)/Ns])).^2; branche_3 = X.*cos(2*pi*F1*T); branche_3_integral = sum(reshape(branche_3, [Ns, length(branche_3)/Ns])).^2; branche_4 = X.*sin(2*pi*F1*T); branche_4_integral = sum(reshape(branche_4, [Ns, length(branche_4)/Ns])).^2; somme = branche_4_integral + branche_3_integral - branche_2_integral - branche_1_integral; result = double(somme > 0); erreur = sum((bits - result).^2)/N*Ns