jkkncet-digital communication laboratory-matlab programs

Upload: julian-savari-antony-s

Post on 02-Jun-2018

233 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    1/23

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    2/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    2

    The input bina r y symbol s ar e r epr esented in pola r f or m with symbol s 1 & 0 r epr esented bycon stant amplitude level s Eb & -Eb. Thi s bina r y wave i s multiplied by a sinusoidal ca rr ier in a

    pr oduct modulato r . The r esult in a B SPK signal.

    BSPK R eceiver :

    PSK signal X dt x c1 (t).

    Decisiondevice Choo se

    1 i f x > 0Choo se 0 if x < 0

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    3/23

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    4/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    4

    elsem(i)=0;m_s=-1*ones(1,length(t));endmessage(i,:)=m_s;%product of carrier and message signal

    bpsk_sig(i,:)=c.*m_s;%Plot the message and BPSK modulated signalsubplot(5,1,2);axis([0 N -2 2]);plot(t,message(i,:),'r');title('message signal(POLAR form)');xlabel('t--->');ylabel('m(t)');grid on; hold on;subplot(5,1,4);plot(t,bpsk_sig(i,:));title('BPSK signal');xlabel('t--->');ylabel('s(t)');grid on; hold on;t1=t1+1.01; t2=t2+1.01;endhold off%plot the input binary data and carrier signal

    subplot(5,1,1);stem(m);title('binary data bits');xlabel('n--->');ylabel('b(n)');grid on;subplot(5,1,3);plot(t,c);title('carrier signal');xlabel('t--->');ylabel('c(t)');grid on;

    % PSK Dem odu la t ion

    t1=0;t2=Tbfor i=1:Nt=[t1:.01:t2]%correlatorx=sum(c.*bpsk_sig(i,:));%decision deviceif x>0demod(i)=1;elsedemod(i)=0;end

    t1=t1+1.01;t2=t2+1.01;end%plot the demodulated data bitssubplot(5,1,5);stem(demod);title('demodulated data');xlabel('n--->');ylabel('b(n)');grid on

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    5/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    5

    Mo dal Gra phs

    R esu lt

    The p r ogr am f or PSK modulation and demodulation ha s been simulated in MATL AB andnece ssar y gr aphs ar e plotted.

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    6/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    6

    Ex peri m ent No.2

    FR EQ UE NCY SH IFT KE YIN G (FSK/BFSK)

    Aim: To gene r ate and demodulate fr equency shif t keyed (FSK) signal u sing MATL AB

    T heory

    Ge n era t ion of FSK

    Fr equency -shif t keying (FSK) is a fr equency modulation scheme in which digital in f or mation i s tr ansmitted th r ough di scr ete fr equency change s o f a ca rr ier wave. The simple st FSK i s bina r y FSK (BFSK) . B FSK uses a pai r o f di scr ete fr equencie s to t r ansmit bina r y (0s and 1 s) in f or mati on. Withthis scheme, the "1" is called the ma r k fr equency and the "0" is called the s pace fr equency.

    In bina r y FSK system, symbol 1 & 0 a r e di stingui shed fr om each othe r by t r ansmitting one o f thetwo sinusoidal waves that di ff er in fr equency by a f ixed amount.

    Si (t) = 2E/T b cos 2f 1 t 0 t T b

    0 el sewher eWhe r e i=1, 2 & E b =Tr ansmitted ene r gy/bitTr ansmitted fr eq= i =(nc+i )/T b , and n = con stant (intege r), T b = bit inte r valSymbol 1 i s r epr esented by S1 (t) Symbol 0 i s r epr esented by S0 (t)

    BF SK Tra nsm itt er

    Bina r y wave(On-Off signaling

    For m)

    X c1 (t) = 2/T b cos 21 t +

    Inve r ter X + FSK signal

    c2 (t) = 2/T b cos 22 t

    The input bina r y sequence i s r epr esented in it s ON-OFF f or m, with symbol 1r epr esented by con stant amplitude o f E b with & symbol 0 r epr esented by ze r o volt s.By u sing inve r ter in the lo wer channel, we in e ff ect make sur e that when symbol 1i s at the input, The t wo fr equency f 1& f 2 a r e cho sen to be equal intege r multiple s of the

    bit r ate 1/T b. By summing the uppe r & lo wer channel output s, we get B FSK signal.

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    7/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    7

    10

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    8/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    8

    T dt

    BF SK R eceiver x1X T b dt

    0 +c1 (t)

    E L

    FSK signal -

    X c2 (t) x2

    x = x1 -x2DecisionDevice

    choo se 1 if x >0

    choo se 0 if x < 0

    The r ecei ver con sists of two co rr elate s with common input s which a r e supplied withlocally gene r ated cohe r ent r ef er ence signal s c 1 (t) and c 2 (t).

    The co rr elato r output s ar e then subt r acted one fr om the othe r , and the r esulting di ff er encex is compa r ed with a th r eshold o f ze r o volt s. If x >0, the r eceive r decide s in f avou r of symbol 1 and i f x 0, choose 1 else choose 0.4. Plot the demodulated binary data.

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    9/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    9

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    10/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    10

    Progra m

    % FSK Mo du la t ion

    clc;clear all;close all;%GENERATE CARRIER SIGNALTb=1; fc1=2;fc2=5;t=0:(Tb/100):Tb;c1=sqrt(2/Tb)*sin(2*pi*fc1*t);c2=sqrt(2/Tb)*sin(2*pi*fc2*t);%generate message signal

    N=8;m=rand(1,N);

    t1=0;t2=Tbfor i=1:Nt=[t1:(Tb/100):t2]if m(i)>0.5m(i)=1;m_s=ones(1,length(t));invm_s=zeros(1,length(t));elsem(i)=0;m_s=zeros(1,length(t));invm_s=ones(1,length(t));endmessage(i,:)=m_s;%Multiplierfsk_sig1(i,:)=c1.*m_s;fsk_sig2(i,:)=c2.*invm_s;fsk=fsk_sig1+fsk_sig2;%plotting the message signal and the modulated signalsubplot(3,2,2);axis([0 N -2 2]);plot(t,message(i,:),'r');title('message signal');xlabel('t---->');ylabel('m(t)');grid on;hold on;subplot(3,2,5);plot(t,fsk(i,:));title('FSK signal');xlabel('t---->');ylabel('s(t)');grid on;hold on;t1=t1+(Tb+.01); t2=t2+(Tb+.01);

    endhold off%Plotting binary data bits and carrier signalsubplot(3,2,1);stem(m);title('binary data');xlabel('n---->'); ylabel('b(n)');grid on;subplot(3,2,3);plot(t,c1);title('carrier signal-1');xlabel('t---->');ylabel('c1(t)');grid on;subplot(3,2,4);plot(t,c2);title('carrier signal-2');xlabel('t---->');ylabel('c2(t)');grid on;

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    11/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    11

    % FSK Dem odu la t ion

    t1=0;t2=Tbfor i=1:Nt=[t1:(Tb/100):t2]%correlatorx1=sum(c1.*fsk_sig1(i,:));x2=sum(c2.*fsk_sig2(i,:));x=x1-x2;%decision deviceif x>0demod(i)=1;elsedemod(i)=0;endt1=t1+(Tb+.01);t2=t2+(Tb+.01);end%Plotting the demodulated data bitssubplot(3,2,6);stem(demod);title(' demodulated data');xlabel('n---->');ylabel('b(n)'); grid on;

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    12/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    12

    Mo dal Gra phs

    R esu lt

    The p r ogr am f or FSK modulation and demodulation ha s been simulated inMATL AB and nece ssar y gr aph s ar e plotted.

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    13/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    13

    Ex peri m ent No.3

    SPREAD SPECTRUM COMMUNICATION

    Aim: To study the spread spectrum communication using MATLAB

    Theory:Spread spectrum is a digital modulation technology and a technique based on principals

    of spreading a signal among many frequencies to prevent interference and signal detection. It is atechnique to spread the transmitted spectrum over a wide range of frequencies.Direct sequence spread spectrum (DSSS) :

    In Direct sequence spread spectrum (DSSS) each bit in the original signal is represented by multiple bits after signal is transmitted into channel. In this technique when the signal istransmitted spreading code spreads the signal in wider frequency band. When PN bits are

    generated the number of bits used to represent each original is directly proportional to Number ofPN sequence generated and used. In the next section you will see how this process works.

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    14/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    14

    DSSS Transmitter Example: Data Input A shown the input original message which is ready to encode or spread by

    using a PN sequence as illustrated in the above section. 2nd diagram shows the locally generated PN sequence. In this diagram each bit of original

    message is represented by 4-bits of PN sequence. Now by Exclusive-Or first and 2nd diagram 3rd signal is obtained simply by Xor between

    1 bit of original data with 4 bits of PN sequence.

    DSSS Receiver Example:

    On receiver side we received signal which was transmitted from transmitter side. Assumethat there is no error or no bit corrupted in the received signals.

    When signal is received same PN sequence is generated on receiver side, the signal whichwas generated on transmitted side.

    Received signal and PN sequence is Xor. By this original Signal is received.

    http://crunchmodo.com/wp-content/uploads/2013/04/dsss-example-receiver.jpghttp://crunchmodo.com/wp-content/uploads/2013/04/dsss-example.jpghttp://crunchmodo.com/wp-content/uploads/2013/04/dsss-example-receiver.jpghttp://crunchmodo.com/wp-content/uploads/2013/04/dsss-example.jpg
  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    15/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    15

    Frequency Hopping spread spectrum:Frequency hopping spread spectrum is a transmission technology used in wireless

    networks and a technique to generate spread spectrum by hopping the carrier frequency. FHSSuses narrow band signal which is less than 1 MHz, In this method data signal is modulated with a

    narrowband carrier signal that "hops" in random and hopping happens in pseudo-random"predictable" sequence in a regular time from frequency to frequency which is synchronized at

    both ends. Using FHSS technology improves privacy, it is a powerful solution to avoidinterference and multi path fading (distortion), it decreases narrowband interference, increasessignal capacity, improve the signal to noise ratio, efficiency of bandwidth is high and difficult tointercept also this transmission can share a frequency band with many types of conventionaltransmissions with minimal interference. For frequency hopping a mechanism must be defined totransmit data in a clear channel and to avoid the congested channels. Frequency hopping is the

    periodic change of transmission frequency and hopping happens over a frequency bandwidthwhich consists of numbers of channels. Channel which is used as a hopped channel is

    instantaneous bandwidth while the hopping spectrum is called total hopping bandwidth.Frequency hopping categorized into slow hopping and fast hopping which by slow hopping morethan one data symbol is transmitted in same channel and by fast hopping frequency changesseveral times during one symbol. Hopping sequence means which next channel to hop; there aretwo types of hopping sequence: random hopping sequence and deterministic hopping sequence.The focus of this work is on slow and deterministic frequency hopping sequence. In a frequencyhopping network, there can be different number of receivers which one sender is designed asBase that is responsible to transmit the synchronization data to the receivers.

    PROGRAMS:

    %PN sequence generation %Maximum-length sequence generator %Program to generate Maximum Length Pseudo Noise Sequence clc;%Assign Initial value for PN generator x0= 1;x1= 0;x2 =0;x3 =0;

    N = input( 'Enter the period of the signal' )for i =1:Nx3 =x2;x2 =x1;x1 = x0;x0 =xor(x1,x3);disp(i, 'The PN sequence at step' )

    x = [x1 x2 x3];

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    16/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    16

    disp(x, 'x=' )end m = [7,8,9,10,11,12,13,17,19];

    N = 2^m-1;disp( 'Table Range of PN Sequence lengths' )

    disp( '_________________________________________________________' )disp( 'Length of shift register (m)' )disp(m)disp( 'PN sequence Length (N)' )disp(N)disp( '_________________________________________________________' )

    Alternate Method:

    GENERATION OF PN-SEQUENCE:

    clearclcG=63; % Code length %Generation of first m-sequence using generator polynomial [45] sd1 =[0 0 0 0 1]; % Initial state of Shift register PN1=[]; % First m-sequence for j=1:G

    PN1=[PN1 sd1(5)];if sd1(1)==sd1(4)

    temp1=0;else temp1=1;end sd1(1)=sd1(2);sd1(2)=sd1(3);sd1(3)=sd1(4);sd1(4)=sd1(5);sd1(5)=temp1;end subplot(3,1,1)stem(PN1)title( 'M-sequence generated by generator polynomial [45]' )

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    17/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    17

    Direct Sequence Spread Spectrum:

    function DSSSclcPNbit_stream = round(rand(1,32));input_signal=[0 1 0 0 1 0 1 1];PNbit_streamfor i=1:1:8for j=1:4:32for k=1:1:4a(j)=xor(PNbit_stream(k+j-1),input_signal(i));a(j);

    end end end figure(1)stem(PNbit_stream)title( 'PNbit_stream' );figure(2)stem(input_signal)title( 'input_signal' );figure(3)stem(a)title( 'DSSS' );

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    18/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    18

    Model graph:

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    19/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    19

    Result,

    The p r ogr am f or spread spectrum communication has been simulated inMATL AB and nece ssar y gr aph s ar e plotted.

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    20/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    20

    Ex peri m ent No.3 ERROR CONTROL CODING USNG MATLAB

    AIM

    To write a mat lab program for the simulation of error detection implementation oflinear block code.

    APPARATUS REQUIRED

    MATLAB 7.0.1 Software

    PROCEDURE

    1. Select MATLAB 7.0.1 from Programs menu.2. Select File-New-M File.

    3. Type the program in the new file.4. Save the file using .m extension.5. Select debug-run.6. Any errors if present can be viewed by selecting windows-0 command window.7. If no error, the signal appears in the screen.8. The output signal thus viewed.

    THEORY

    ERROR DETECTION IMPLEMENTATION OF LINEAR BLOCK CODE

    INFORMATION ON CYCLIC CODE

    Cyclic codes are an important sub-class of linear block codes for error detection, where a newcodeword in the code can be formed by shifting the elements along one place and taking one offthe end and putting it on to the beginning. Instead of being generated by a matrix, a cyclic codeis generated by a polynomial so that the codes are sometimes called polynomial codes.Importantly, cyclic codes have a structure that makes it possible for the encoding and decodingto be performed by simple feedback circuitry. Satellite communications systems commonly usecyclic codes.

    INFORMATION ON CONVOLUTIONAL CODE

    A convolutional code extends the concept of a block code to allow memory from block to block.Each encoded symbol is therefore a linear combination of information symbols in the current

    block and a selected number of preceding blocks.Therefore, for example, if the final output is a 1 followed by a 0, then these two digits

    could only have been arrived at by via a certain sequence of 0s and 1s preceding them. Thelonger the sequence, the easier it becomes for the receiver to detect where the received sequencedeviates from a possible sequence and so correct one or more errors. Decoding of convolutionalcodes is based on the principle of the Viterbi decoding algorithm or sequential decoding.Satellite communications systems commonly use a convolutional code to protect all data carriedon the link.

    http://matlabpgm.blogspot.com/2008/06/information-on-cyclic-code.htmlhttp://matlabpgm.blogspot.com/2008/06/information-on-convolutional-code.htmlhttp://matlabpgm.blogspot.com/2008/06/information-on-convolutional-code.htmlhttp://matlabpgm.blogspot.com/2008/06/information-on-cyclic-code.html
  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    21/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    21

    PROGRAM clf;

    clc;clear all;close all;

    % Input Generator Matrixg=input('Enter The Generator Matrix: ')disp ('G = ')disp ('The Order of Linear block Code for given Generator Matrix is:')[n,k] = size(transpose(g))for i = 1:2^kfor j = k:-1:1if rem(i-1,2^(-j+k+1))>=2^(-j+k)u(i,j)=1;elseu(i,j)=0;

    endendendu;disp('The Possible Codewords are :')c = rem(u*g,2)disp('The Minimum Hamming Distance dmin for given Block Code is= ')d_min = min(sum((c(2:2^k,:))'))

    % Code Wordr = input('Enter the Received Code Word:')

    p = [g(:,n-k+2:n)];h = [transpose(p),eye(n-k)];disp('Hammimg Code')ht = transpose(h)disp('Syndrome of a Given Codeword is :')s = rem(r*ht,2)for i = 1:1:size(ht)if(ht(i,1:3)==s)r(i) = 1-r(i);

    break;end

    enddisp('The Error is in bit:')idisp('The Corrected Codeword is :')r

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    22/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    22

    OUTPUT

    Enter The Generator Matrix: [1 0 0 0 1 0 1;0 1 0 0 1 1 1;0 0 1 0 1 1 0;0 0 0 1 0 1 1]g =1 0 0 0 1 0 1

    0 1 0 0 1 1 10 0 1 0 1 1 00 0 0 1 0 1 1

    G =The Order of Linear block Code for given Generator Matrix is:n =7k =4

    The Possible Codewords are :

    c =0 0 0 0 0 0 00 0 0 1 0 1 10 0 1 0 1 1 00 0 1 1 1 0 10 1 0 0 1 1 10 1 0 1 1 0 00 1 1 0 0 0 10 1 1 1 0 1 0

    1 0 0 0 1 0 11 0 0 1 1 1 01 0 1 0 0 1 11 0 1 1 0 0 01 1 0 0 0 1 01 1 0 1 0 0 11 1 1 0 1 0 01 1 1 1 1 1 1

    The Minimum Hamming Distance dmin for given Block Code is=

    d_min =

    3

    Enter the Received Code Word:[1 0 0 0 1 0 0]

    r =1 0 0 0 1 0 0

  • 8/10/2019 JKKNCET-Digital Communication Laboratory-MATLAB Programs

    23/23

    JKKNCET/Digital Communication laboratory-MATLAB Programs

    23

    Hammimg Codeht =1 0 11 1 1

    1 1 00 1 11 0 00 1 00 0 1

    Syndrome of a Given Codeword is :s =0 0 1

    The Error is in bit:

    i =7

    The Corrected Codeword is :r =1 0 0 0 1 0 1

    RESULT

    Thus the simulation of MATLAB program for error detection implementation of linear blockcode was done and verified.