Week 10 || MAP and ML Rule for AWGN || NPTEL || Simulation of Communication Systems Using MATLAB

Поділитися
Вставка
  • Опубліковано 12 лис 2024

КОМЕНТАРІ • 4

  • @shivanidhok3831
    @shivanidhok3831  Місяць тому +1

    Hi everyone. Due to some technical glitch, the MATLAB screen was not recorded. Following are the MATLAB codes for last three questions.
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Q8. MPAM (Simulation)
    clc;clear;close all;
    % Plot Symbol error probability/Probability of error for M-ary pulse
    % amplitude modulation (PAM).
    %% Setup simulation parameters
    N = 1e+6; % Number of realizations of noise and symbols
    M = 2; % Number of constellation points
    No = 1; % Noise variance
    E_avg = linspace(0,10,21); % Average energy
    %% Get Constellation points (Not normalized by E_avg)
    A = -(M-1):2:(M-1);
    %% Get the simulation for all the values of average energy
    for ii = 1:length(E_avg)
    % Get normalized constellation points
    dmin = sqrt(12.*E_avg(ii)./(M.^2-1));
    A_const = A.*0.5.*dmin;
    % Get N random constellation points for transmission
    idx = randi(M,[N,1]); % N random indices between 1 to M
    sm = transpose(A_const(idx)); % Get random symbols to be transmitted
    % Add noise to the transmitted symbol
    n = sqrt(No).*randn(N,1); % AWGN noise with 0 mean and variance No
    y = sm+n; % Recieved signal

    % ML decoding, min-distance decoding
    d_all = abs(y-A_const);
    [val idx_dec] = min(transpose(d_all));
    sm_dec = transpose(A_const(idx_dec));
    % Get probability of error = Number of errors/N
    num_errors = sum(idx~=idx_dec');
    Pe(ii) = num_errors./N;
    end
    %% Plot the Probability of error
    semilogy(E_avg,Pe);
    xlabel('Average energy');
    ylabel('Probability of error');
    grid on;
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Q9. Binary PAM (Analysis+Simulation)
    clc;clear;close all;
    % Plot Symbol error probability/Probability of error for binary pulse
    % amplitude modulation (PAM) and match with analytical expression
    %% Setup simulation parameters
    N = 1e+6; % Number of realizations of noise and symbols
    M = 2; % Number of constellation points
    No = 1; % Noise variance
    E_avg = linspace(0,10,21); % Average energy
    %% Get Constellation points (Not normalized by E_avg)
    A = -(M-1):2:(M-1);
    %% Get the simulation for all the values of average energy
    for ii = 1:length(E_avg)
    % Get normalized constellation points
    dmin = sqrt(12.*E_avg(ii)./(M.^2-1));
    A_const = A.*0.5.*dmin;
    % Get N random constellation points for transmission
    idx = randi(M,[N,1]); % N random indices between 1 to M
    sm = transpose(A_const(idx)); % Get random symbols to be transmitted
    % Add noise to the transmitted symbol
    n = sqrt(No).*randn(N,1); % AWGN noise with 0 mean and variance No
    y = sm+n; % Recieved signal

    % ML decoding, min-distance decoding
    d_all = abs(y-A_const);
    [val idx_dec] = min(transpose(d_all));
    sm_dec = transpose(A_const(idx_dec));
    % Get probability of error = Number of errors/N
    num_errors = sum(idx~=idx_dec');
    Pe(ii) = num_errors./N;
    Pe_ana(ii) = qfunc(sqrt(E_avg(ii)./No));
    end
    %% Plot the Probability of error
    semilogy(E_avg,Pe_ana,'LineWidth',2);
    hold on;
    semilogy(E_avg,Pe,'o','LineWidth',2);
    hold off;
    xlabel('Average energy');
    ylabel('Probability of error');
    grid on;
    legend('Analytical','Simulation');
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Q10. MPSK (Simulation)
    clc;clear;close all;
    % Plot Symbol error probability/Probability of error for M-ary phase
    % shift keying.
    %% Setup simulation parameters
    N = 1e+6; % Number of realizations of noise and symbols
    M = 4; % Number of constellation points
    No = 1; % Noise variance
    E_avg = linspace(0,10,21); % Average energy
    %% Get Constellation points (Not normalized by E_avg)
    A = exp(-j.*2.*pi.*(0:M-1)./M);
    %% Get the simulation for all the values of average energy
    for ii = 1:length(E_avg)
    % Get normalized constellation points
    A_const = A.*sqrt(E_avg(ii));
    % Get N random constellation points for transmission
    idx = randi(M,[N,1]); % N random indices between 1 to M
    sm = transpose(A_const(idx)); % Get random symbols to be transmitted
    % Add noise to the transmitted symbol
    n = sqrt(No./2).*(randn(N,1)+1i.*randn(N,1)); % AWGN noise with 0 mean and variance No
    y = sm+n; % Recieved signal

    % ML decoding, min-distance decoding
    d_all = abs(y-A_const);
    [val idx_dec] = min(transpose(d_all));
    sm_dec = transpose(A_const(idx_dec));
    % Get probability of error = Number of errors/N
    num_errors = sum(idx~=idx_dec');
    Pe(ii) = num_errors./N;
    end
    %% Plot the Probability of error
    semilogy(E_avg,Pe);
    xlabel('Average energy');
    ylabel('Probability of error');
    grid on;

  • @lokeshraybarman7007
    @lokeshraybarman7007 Місяць тому

    Highly helpful session ❤❤❤

  • @Ankitvermacp3
    @Ankitvermacp3 Місяць тому

    Mam I think the MATLAB simulation part didn’t get shared in the Google Meet. Could you provide the code snippet for it?