%% 442.104 Fundamentals of Digital Communications - Problem Classes
% 
% Problem: 4.1 
% Term: WS2013
% Intructor: Erik Leitinger <erik.leitinger@tugraz.at>
%
% Signal Processing and Speech Communication Laboratory
% Graz University of Technology
% Inffeldgasse 16c
% 8010 Graz
% Austria

clear all;
close all;
clc;

Eb = 1;     % Bit Energy [J]
k = 1:8;    % 2^k Bits/Symbol [1]

disp('Fundamentals of Digital Communications - Problem Classes')
disp('Problem 4.1');
disp(' ');


%% f) M-PAM (M-ary Pulse Amplitude Modulation)

dmin_MPAM = 2*sqrt(3.*k./(2.^(2.*k)-1)).*sqrt(Eb);

close(figure(1));
figure(1);
hold on;
stem(k,dmin_MPAM,'bo','LineWidth',3);
hold off;
grid on;
title('Minimum Distance of M-ary Modulation Schemes','FontSize',16);
xlabel('Bits/Symbol k; M = 2^k','FontSize',16);
ylabel('d_{min} /  (E_b)^{1/2}','FontSize',16);
legend('M-PAM','Location','NorthWest');
axis([min(k), max(k), 0, floor(sqrt(2.*max(k).*Eb))]);


%% g) M-PSK (M-ary Phase Shift Modulation)

dmin_MPSK = 2*sqrt(k.*Eb).*sin(pi./(2.^k));

close(figure(1));
figure(1);
hold on;
stem(k,dmin_MPSK.','r+','LineWidth',3);
stem(k,dmin_MPAM,'bo','LineWidth',3);
hold off;
grid on;
title('Minimum Distance of M-ary Modulation Schemes','FontSize',16);
xlabel('Bits/Symbol k; M = 2^k','FontSize',16);
ylabel('d_{min} /  (E_b)^{1/2}','FontSize',16);
legend('M-PSK','M-PAM','Location','NorthWest');
axis([min(k), max(k), 0, floor(sqrt(2.*max(k).*Eb))]);


%% h) M-ary Orthogonal

dmin_Morth = sqrt(2.*k.*Eb);

close(figure(1));
figure(1);
hold on;
stem(k,dmin_Morth,'ko','LineWidth',2,'MarkerSize',10);
stem(k,dmin_MPSK,'r+','LineWidth',2,'MarkerSize',10);
stem(k,dmin_MPAM,'bs','LineWidth',2,'MarkerSize',10);
hold off;
grid on;
title('Minimum Distance of M-ary Modulation Schemes','FontSize',16);
xlabel('Bits/Symbol k; M = 2^k','FontSize',16);
ylabel('d_{min} /  (E_b)^{1/2}','FontSize',16);
legend('M-orth','M-PSK','M-PAM','Location','NorthWest');
axis([min(k), max(k), 0, floor(sqrt(2.*max(k).*Eb))]);

% EOF
