ME End Sem Programs

Embed Size (px)

Citation preview

  • 8/2/2019 ME End Sem Programs

    1/8

    Expt. No. 1

    Date:

    Single parity: Encoding and Decoding

    Aim:

    To write a MATLAB program to en code and decode single parity codes.

    Apparatus required:

    MATLAB 7 Software, Computer, Printer , Word processing software.

    Basic Theory:

    Program

    Program 1: Generation of parity%this program will generate single parity bitclc;clear all;%Data to be encoded in even parityx=[1 0 1 0 1 1 0 1 1];disp('data to be encoded is')xy=length(x);z=zeros(1,y+1);%the following will be again data but with last bit as zeroz(1:y)=x;a=sum(x);if rem(a,2)==1z(y+1)=1;elsez(y+1)=0;enddisp('encoded data is')zProgram 2:Checkingofparity

    %this program will check parityclc; clear all;x=[1 0 1 0 1 1 0 1 1];y=sum(x);if rem(y,2)==1disp('odd')elsedisp('even')end

  • 8/2/2019 ME End Sem Programs

    2/8

    Observation:

    Program 1

    data to be encoded is

    x = 1 0 1 0 1 1 0 1 1

    encoded data is

    z = 1 0 1 0 1 1 0 1 1 0

    Program 2:

    even

    Result:

    A program to encode and decode using single parity code is demonstrated

  • 8/2/2019 ME End Sem Programs

    3/8

    Expt. No. 2

    Date:

    Hamming code: Encoding and Decoding

    Aim:

    To write a MATLAB program to en code and decode Hamming codes given the parity Matrix.

    Apparatus required:

    MATLAB 7 Software, Computer, Printer , Word processing software.

    Basic Theory:

    Data = [1 0 1 1]

    Code = Data * G = [1 0 0 1 0 1 1]

    Decode = code * HT

    = [ 0 0 0] if no error in transmission

    Program

  • 8/2/2019 ME End Sem Programs

    4/8

    % Encodingclc;% Parity matrix givenp=[1 1 0;0 1 1;1 1 1;1 0 1]% I matrix constructedi=[1 0 0 0;0 1 0 0;0 0 1 0;0 0 0 1]% G matrix constructedg=[p i]% Data to be encodedx=[1 1 0 1]% Multiplication with generation matrixfor j=1:7y=x*g(:,j);z=sum(y);s=rem(z,2);if s==1d(j)=0;elsed(j)=1;end

    enddisp('the encoded message is')d

    %decodingi1=eye(3,3)p1=p'h=[i1 p1]% H transposeh1 = h'% Multiplicationfor j1=1:3y1=d*h1(:,j1);

    z1=sum(y1);s1=rem(z1,2);if s1==1d1(j1)=1;elsed1(j1)=0;endenddisp('the decoded message is')d1

    Observation:

    p =

    1 1 0

    0 1 1

    1 1 1

    1 0 1

    i =

  • 8/2/2019 ME End Sem Programs

    5/8

    1 0 0 0

    0 1 0 0

    0 0 1 0

    0 0 0 1

    g =

    1 1 0 1 0 0 0

    0 1 1 0 1 0 0

    1 1 1 0 0 1 0

    1 0 1 0 0 0 1

    x =

    1 1 0 1

    The encoded message is

    d = 1 1 1 0 0 1 0

    i1 = 1 0 0

    0 1 0

    0 0 1

    p1 = 1 0 1 1

    1 1 1 0

    0 1 1 1

    h = 1 0 0 1 0 1 1

    0 1 0 1 1 1 0

    0 0 1 0 1 1 1

    h1 = 1 0 0

    0 1 0

    0 0 1

    1 1 0

    0 1 1

    1 1 1

    1 0 1

    The decoded message is

    d1 = 0 0 0

    Result:

    A program to encode and decode using Hamming code is demonstrated

  • 8/2/2019 ME End Sem Programs

    6/8

    Expt. No. 3

    Date:

    Equalization

    Aim:

    To write a MATLAB program to demonstrate Linear and MLSE equalizers

    Apparatus required:

    MATLAB 7 Software, Computer, Printer , Word processing software.

    %This program is written by SPK.Babu for the M.E. Students.%This program demonstrates the equalization by Linear adaptive equalizer%using LMS algorithm and MLSE equalizer. The BER of the above is compared%with AWGN channel. The modulation used is BPSK%Since AWGN is used don't go for without equalization!!!!%DFE with RLS algorithm is yet to be developed in this program.clc; clear all; close all;% Set up parameters and signals.M = 2; % Alphabet size for modulationd = 1; d1 =1;for snr = 5:1:15msg = randint(100000,1,M); % Random messagemodmsg = pskmod(msg,M); % Modulate using QPSK.trainlen = 500; % Length of training sequencechan = [.986; .845; .237; .123+.31i];% Channel coefficients

    filtmsg1 = filter(chan,1,modmsg); % Introduce channel distortion.filtmsg = awgn(filtmsg1, snr, 'measured');% Equalize the received signal.eq1 = lineareq(8, lms(0.01)); % Create an equalizer object.[symbolest,yd] = equalize(eq1,filtmsg,modmsg(1:trainlen));% Equalize.% Compute error rates with and without equalization.demodmsg = pskdemod(yd,M); % Demodulate detected signal from equalizer.[neq,req(d)] = biterr(demodmsg(trainlen+1:end),msg(trainlen+1:end));dd = d+1;endberlinear = req;const = pskmod([0:M-1],M)for SNR = 5:1:15%Generation of data bitsx = randint(1000000,1,M);

    msg = pskmod(x,M); % Modulated messagechcoeffs = [.986; .845; .237; .12345+.31i];% Channel coefficientsfiltmsg1 = filter(chcoeffs,1,msg);% Introduce channel distortion.filtmsg = awgn(filtmsg1,SNR, 'measured'); % Introduce Noisetblen = 10; % Traceback depth for equalizerchanest = chcoeffs; % Assume the channel is known exactly (No channel

    estimation performed).

  • 8/2/2019 ME End Sem Programs

    7/8

    msgEq = mlseeq(filtmsg,chanest,const,tblen,'rst'); % Equalize.msgeq1 = pskdemod(msgEq, M); % Demodulation into bits[a b(d1)]= biterr(x,msgeq1); % Calculate BER for each SNRd1d1 = d1+1;endbermlse = b;%---------Plotting the BER values----------semilogy(5:1:15, berlinear, 'r-o')hold onsemilogy(5:1:15, bermlse, 'g-*')bertheory = berawgn(5:1:15, 'psk', M, 'nondiff');semilogy(5:1:15, bertheory, 'b-^')axis([5 15 1E-6 1]); grid on;xlabel('SNR in dB'); ylabel('BER');legend('BER of Linear Equalizer', ' BER of MLSE Equalizer', 'BER of

    theoritical BER under AWGN')

    5 6 7 8 9 10 11 12 13 14 1510

    -6

    10-5

    10-4

    10

    -3

    10-2

    10-1

    100

    SNR in dB

    BER

    BER of Linear Equalizer

    BER of MLSE Equalizer

    BER of theoritical BER under AWGN

  • 8/2/2019 ME End Sem Programs

    8/8

    Mini project titles

    1. Simulate the Channel Model B: IEEE P802.11n Wireless LANs, "TGn Channel Models", IEEE802.11-03/940r4, 2004-05-10.

    2. Simulation of Eye Diagram3. SC-FDMA physical layer SISO4. Simulink: FSK VS MSK Vs GMSK BER5. Simulink: BPSK Vs QPSK BER6. Simulate the following channel

    7. Demonstrate any one of the error correcting coding performance on BER of QPSK with AWGNand Rayleigh channel.

    8. Write a simple program to demonstrate precoding used along with equalizers to attain goodBER