SERVFORU

LINEAR BLOCKCODES

LINEAR BLOCKCODES
AIM
To detect and correct the error accruing in the transmitted data with the help
of linear block codes.
THEORY
A code is said to be linear if any two code word in the code, can be added in module 2 arithmetic to Produce a third codeword in the code. The (n-k) bits in the remaining portion are computed from the message bits in the accordance with the prescribed encoding rule that determines a mathematical structure of the code, then use frame to get the syndrome calculation.
The hamming weight of the code vector C is defined in the number of non zero elements in the code vector. The minimum distance of the linear block code is defiend in the smallest hamming distance between any pair of code vector in code.
Algorithm

  1. Get the generator matrix value.
  2. Calculate the order of given matrix.
  3. calculate the code word.
  4. calculate the minimum ha
  5. Get the received code word.
  6. Display the hamming code
  7. Display the syndrome of the code word.
  8. Calculate the error in the bit.
  9. Display the correlated code word.

    PROGRAM
    #######################################
    clc;
    clear all;
    close all;
    %input generator matrix
    g=input('enter the generator matrix:')
    disp('G=')
    disp('the order of linear block code for given generator mathrix is:');
    [n,k]=size(transpose(g))
    for i=1:2^k
        for j=k:-1:1
            if rem(i-1,2^(-j+k+1))>=2^(-j+k)
                u(i,j)=1;
            else
                u(i,j)=0;
            end
        end
    end
    u;
    disp('the possible code word 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 word
    r=input('enter the recieved code word:');
    p=[g(:,n-k+2:n)];
    h=[transpose(p),eye(n-k)];
    disp('hamming code');
    ht=transpose(h)
    disp('syndrome of a given code word is:');
    s=rem(r*ht,2)
    for i=1:1:size(ht)
        if(ht(i,1:3)==5)
            r(i)=1-r(i);
            break;
        end
    end
    disp('the error is in bit:');
    i;
    disp('the correct codeword is:');
    r;

    ###########################################################################
    OUTPUT
    Enter the generator matrix:[1000101;0100111;0010110;0001011]
    g =1000101
    0100111
    0010110
    0001011
    G = The order of linear block code for given generator mathrix is:
    n = 7
    k = 4
    The possible code word are:
    0000000
    0001011
    0010110
    0011101
    0000111
    0101100
    0110001
    0111010
    1000100
    1001110
    1010011
    1011000
    1100010
    1101001
    1110100
    1111111
    The minimum hamming distance dmin for given block code is:
    d_min =3
    Enter the received code word:[1000100]
    r=1000100
    Hamming code
    H=
    101
    111
    110
    011
    100
    101
    001

    Syndrome of t given codeword is:
    s=001
    The error is in bit :
    i=7
    The corrected code word is : r=100010.

    Result
    Thus the error is detected and corrected n the transmitted code by using linear block codes.



 

ESTIMATION OF PERIODOGRAM

ESTIMATION OF PERIODOGRAM
AIM
To estimate the power spectral density of a given signal using periodogram
in MATLAB.
THEORY
The power spectral density (PSD) of a WSS process is the Fourier transform of the autocorrelation sequence. Periodogram is a non-parametric method to estimate PSD
() = (k)
For an autocorrelation ergodic process and an unlimited amount of data, the autocorrelation sequence may be detemined by using the time average
(k) = (n+k)x*(n)
If x(n) is only measured over a finite interval, say n=1,2,…N-1, then the autocorrelation sequence must be estimated using with a finite sum
(r) = () (n+k)x*(n)
In order to ensure that the value of x(n) that is fully outside the interval [0,N-1] are excluded and written as follows
(k) = () (n+k)x*(n) k=0,1,2….,N-1.
Taking the discrete Fourier transform of rx^(k) leads to an estimation of the power spectrum known as the periodogram.
() = (k)
The periodogram
() = ()() = ()
Where XN(ejw) is the discrete time Fourirer transform of the N-point data sequence XN(n)
() = (n) =
ALGORITHM
STEP 1: Compute the value of x.
STEP 2: Perform periodogram function for x signal.
STEP 3: Using pwelch function, smoothen the output of periodogram signal.

STEP 4: Plot the graph for input and output signal


PROGRAM
##########################################################
clc;
clear all;
close all;
fs=1000;
t=0.1:1/fs:0.3;
x=cos(2*pi*t*200)+0.1*randn(size(t));
figure(1);
plot(x);
title('input signal');
xlabel('time');
ylabel('amplitude');
figure(2);
periodogram(x,[],'one sided',512,fs);
figure(3);
pwelch(x,30,10,[],fs,'one sided');
#############################################################

RESULT
 Thus the MATLAB program to estimate the power spectral density of given signal using periodogram is executed and output is plotted.


 

SIMULATION OF BLOCK CODES HAMMING AND CYCLIC CODES

SIMULATION OF BLOCK CODES
AIM
To simulate linear block coding techniques for hamming and cyclic code using MATLAB.
THEORY
HAMMING CODES
Consider a family of (n,k) linear block codes that have the following parameters.
Block length,n=2m-1
No.of.message bits k=2m-m-1
No. of parity bits, n-k=m, where m>=3.
These are so called Hamming codes. To illustrate the relations between the minimum distance dmin and the structure of the parity check matrix H. Consider the codeword 0110100,In the matrix multiplication is done, and the non-zero elements of this codeword “shift” out the second, third and fifth column of the matrix if yielding. An important property of hamming codes is that they satisfy the condition. t=1.This means that hamming codes are single error correcting binary perfect codes.
CYCLIC CODES
Cyclic codes form a sub class of linear block codes.A binary code is said to be cyclic code,if it exhibits two fundamental properties.
  1. LINEARITY PROPERTY
The sum of two codeword is also a codeword.
  1. CYCLIC PROPERTY
Any cyclic shift of codeword is also called a codeword.


ALGORITHM
HAMMING CODE
STEP 1: Start the program
STEP 2: Assign the number of parity bits m=4
STEP 3: Calculate the block length n from m=2m-1
STEP 4: Assign the number of message bits k such that n-k=m so k=11
STEP 5: The hamming code is (5,11)
STEP 6: Obtain the input signal message randomly the input message is in binary format
STEP 7: The parity bits are calculated for input message taken.
STEP 8: The parity bits are appended along the message bit to form the codeword.
STEP 9: The codeword formed is transmitted through AWGN channel
STEP10: The received signal is then decoded to retrieve the message
STEP 11: The BER is calculated for the retrieved message
STEP 12: For the various values of the SNR and its corresponding BER,the graph is
Plotted.
CYCLIC CODE
STEP 1: Start the program.
STEP 2: Assign the block length n=7.
STEP 3: Assign the message bits,k=4.
STEP 4: The cyclic code is (7,4)
STEP 5:Generate the polynomial.
STEP 6: Obtain the input message randomly.
STEP 7: The input message is in binary format.
STEP 8: The codeword is formed by appending the parity bits with the message bits.
STEP 9: The parity bits are calculated from the generation polynomial.
STEP10: The codeword formed is transmitted through AWGN channel.
STEP11: The received signal is then decoded with the help of generator polynomial

      Knowledge to retrieve the message.

PROGRAM

HAMMING CODE 
####################################
clc;
clear all;
close all;
m=4;
n=2^m-1;
k=11;
berf=[];
for i=1:10
    b=0;
    for j=1:50
        msg=randint(500,k,[0,1]);
        code=encode(msg,n,k,'hamming/binary');
        t=0:0.1:10;
        snr=0;
        y=awgn(code,i);
        y(find(y>0))=1;
        y(find(y<0))=0;
        msgop=decode(y,n,k,'hamming/binary');
        [number,b1]=biterr(msgop,msg);
        b=b+b1;
    end
    berf(i)=b/50;
end
semilogy(1:10,berf);
title('performance analysis in awgn for hamming codes');
xlabel('snr(db)');
ylabel('BER');

#######################################################################
CYCLIC CODES

clc;
clear all;
close all;
n=7;
k=4;
genpoly=cyclpoly(n,k,'max');
berf=[];
for i=1:10
    b=0;
    for j=1:50
        msg=randint(500,k,[0,1]);
        code=encode(msg,n,k,'cyclic/binary',genpoly);
        t=0:0.1:10;
        snr=0;
        y=awgn(code,i);
        y(find(y>0))=1;
        y(find(y<0))=1;
        msgop=decode(y,n,k,'cyclic/binary',genpoly);
        [number,b1]=biterr(msgop,msg);
        b=b+b1;
    end
    berf(i)=b/50;
end
semilogy(1:10,berf);
title('performance analysis in awgn for cyclic codes');
xlabel ('snr (db)');
ylabel ('BER');

#########################################################

RESULT
Thus the linear block coding technique for hamming code and cyclic code has been simulated using MATLAB.
 

SIMULATION OF QUADRATURE MIRROR FILTER

SIMULATION OF QUADRATURE MIRROR FILTER
AIM:
To simulate the frequency response of quadrature mirror for a two channel filter band.
THEORY:
The QMF filter is used in the sub-band coding. This filter can be used for reducing aliasing. This is a multirate digital filter structure that employes 2 decimeter in signal synthesis section. The low pass and high pass filters in the analysis section have impulse response filters (n) and (n) respectively.
Similarly the low pass filter and high pass filters contained in the synthesis section have impulse response filters (n) and (n) respectively. To reduce aliasing the synthesis section have impulse response (n) and (n) respectively,
(ω)= (ω)
(ω)=- (ω-π)
Since (ω) and (ω)is a mirror image filters
H0(ω)=H(ω)
H1(ω)=H(ω- π)
G0(ω)=2H(ω)
This is due to the above design, aliasing effects cancels.
ALGORITHM:
1. Generate the low pass filter
2. Generate the high pass filter
3. Compute the gain response of two filters
4. Plot the gain response of two filters.













QUADRATURE MIRROR FILTER:






X(ω)








FILTER CHARACTERISTICS FOR SUB-BAND CODING


Gain
H0 (ω) H1 (ω)

PROGRAM
####################################################
clc;
clear all;

%generation of complimentary lpf
b1=fir1(50,0.5);

%generation of complimentary hpf
l=length(b1);
for k=1:l
    b2(k)=((-1)^k)*b1(k)
end

%computation of gain response of two filters
[H1Z,W]=freqZ(b1,1,256);
H1=abs(H1Z);
g1=20*log10(H1);
[H2Z,W]=freqZ(b2,1,256);
H2=abs(H2Z);
g2=20*log10(H2);

%PLOT OF GAIN RESPONSE OF TWO FILTERS
plot((W*180)/pi,g1,'-',(W*180)/pi,g2,'-');
grid on
xlabel('normalized freq');
ylabel('gain');

#############################################################

RESULT:
 Thus the frequency response of quadrature mirror filter for a two channel filter bands was simulated.



 

FREQUENCY HOPPING SPREAD SPECTRUM

FREQUENCY- HOP SPREAD SPECTRUM
AIM
To simulate the frequency-hop spread spectrum modulation techniques using MATLAB program and to calculate the bit error rate.
THEORY
Spread Spectrum is a means of transmission in which the data of interest occupies a bandwidth in excess of the minimum bandwidth is necessary to send the data.
The primary advantage of a spread-spectrum communication system is its ability to reject interference whether it is the unintentional interference of another user simultaneously attempting to transmit through the channel, or the intentional interference of a hostile transmitter attempting to jam transmission. Spread Spectrum modulation was originally developed for military applications where resistance to jamming is of major concern. Another application is in multi access communication in which a number of independent users are required to share a common channel without an external synchronizing mechanism. Principles of spread spectrum modulation emphasis on direct sequence and frequency hopping techniques. In a direct sequence spread spectrum technique two stages of modulations are used. First, the incoming data sequence is used to modulate a wide band code. This code transforms the narrow band data sequence into a noise-like wide band signal. The resulting wide band signal undergoes a second modulation using a phase shift keying technique.
In a frequency-hop spread spectrum technique, the spectrum of a data modulator carrier is widened by changing the carrier frequency in a pseudo random modulator manner. For their operation both of this techniques rely on the ability of a noise like spreading code called a pseudo random or pseudo noise sequence.
PN SEQUENCE
A Pseudo Noise (PN) sequence is defined as a coded sequence of 0’s & 1’s with certain autocorrelation properties. The maximum length sequence, a type of cyclic code is commonly used as a periodic PN sequence.
In case of spread spectrum a Periodic PN sequence is used with a period of N = 2m-1, where m is the length of the shift register. Such sequences have long periods and require simple instrumentation in the form of a linear feedback shift register. PN sequence may also be a periodic. Such sequence is known as Barker sequence.


FREQUENCY HOP SPREAD SPECTRUM
In a frequency-hop spread spectrum technique, the spectrum of a data modulated carrier is widened by changing the carrier frequency in a pseudo random manner. In this the carrier hops randomly from one frequency to another. There are two frequency hopping.
  1. Slow-frequency hopping
In this the symbol rate Rs is an integer multiple of the hop rate Rh. ie. Several
Symbols are transmitted on each frequency hop.
Rs = nRh
  1. Fast-frequency hopping
In this the hop rate Rh is an integer multiple of the symbol rate Rs.ie. Carrier frequency will change or hop several times during the transmission of one symbol.
Rh = nRs

ALGORITHM
  1. Generate the signal which is to be spread.
  2. Generate the PN sequence.
  3. Multiply the PN sequence with message signal.
  4. Display the pseudo sequence and frequency-hop spread sequence.

FREQUENCY HOPPING SPREAD SPECTRUM
clc;
clear all;
close all;

% Generation of bit pattern
s=round(rand(1,25));%generating 20 bits
signal=[];
carrier=[];
t=[0:2*pi/119:2*pi];
for k=1:25
if s(1,k)==0
sig=-ones(1,120);%120 minus ones for bit0
else
        sig=ones(1,120);
    end
    c=cos(t);
    carrier = [carrier c];
    signal = [signal sig];
end
subplot(4,1,1);
plot(signal);
axis([-100 3100 -1.5 1.5]);
title('|bf|it original bit sequence');

% BPSK modulation of the signal
bpsk_sig=signal.*carrier; %modulating the signal
subplot(4,1,2);
plot(bpsk_sig);
axis([-100 3100 -1.5 1.5]);
title('|bf|itbpsk modulated signal');

% Preparation of 6 new carrier frequencies
t1=[0:2*pi/9:2*pi];
t2=[0:2*pi/19:2*pi];
t3=[0:2*pi/29:2*pi];
t4=[0:2*pi/39:2*pi];
t5=[0:2*pi/59:2*pi];
t6=[0:2*pi/119:2*pi];
c1=cos(t1);
c1=[c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1];
c2=cos(t2);
c2=[c2 c2 c2 c2 c2 c2];
c3=cos(t3);
c3=[c3 c3 c3 c3];
c4=cos(t4);
c4=[c4 c4 c4];
c5=cos(t5);
c5=[c5 c5];
c6=cos(t6);
% Random frequency hops to form a spread_signal
spread_signal=[];
for n=1:25
    c=randint(1,1,[1,6]);
switch(c);
case(1)
spread_signal = [spread_signal c1];
case(2)
spread_signal = [spread_signal c2];
case(3)
spread_signal = [spread_signal c3];
case(4)
spread_signal = [spread_signal c4];
case(5)
spread_signal = [spread_signal c5];
case(6)
spread_signal = [spread_signal c6];
end
end
subplot(4,1,3);
plot(spread_signal);
axis([-100 3100 -1.5 1.5]);
title('|bf}if spread signal with 6 frequencies');

% Spreading BPSK signal into wideband with total of 12 frequencies
freq_hopped_sig = bpsk_sig.*spread_signal;
subplot(4,1,4);
plot(freq_hopped_sig);
axis([-100 3100 -1.5 1.5]);
title('|bf|if frequency hopped spread spectrum signal');

% Expressing the FFT's
figure,subplot(2,1,1);
plot([1:3000],freq_hopped_sig);
axis([-100 3100 -1.5 1.5]);
title('|bf|if frequency hopped spread spectrum signal or in fft');
subplot(2,1,2);
plot(abs(fft(freq_hopped_sig)));

################################################################################
RESULT
Thus the MATLAB programs for frequency hopping spread spectrum modulation techniques were executed and the waveforms were obtained.


 

DIRECT SEQUENCE SPREAD SPECTRUM


AIM
To simulate the direct sequence spread spectrum modulation techniques using MATLAB program and to calculate the bit error rate


THEORY
Spread Spectrum is a means of transmission in which the data of interest occupies a bandwidth in excess of the minimum bandwidth is necessary to send the data.
The primary advantage of a spread-spectrum communication system is its ability to reject interference whether it is the unintentional interference of another user simultaneously attempting to transmit through the channel, or the intentional interference of a hostile transmitter attempting to jam transmission.
Spread Spectrum modulation was originally developed for military applications where resistance to jamming is of major concern. Another application is in multi access communication in which a number of independent users are required to share a common channel without an external synchronizing mechanism.
Principles of spread spectrum modulation emphasis on direct sequence and frequency hopping techniques. In a direct sequence spread spectrum technique two stages of modulations are used. First, the incoming data sequence is used to modulate a wide band code. This code transforms the narrow band data sequence into a noise-like wide band signal. The resulting wide band signal undergoes a second modulation using a phase shift keying technique.
In a frequency-hop spread spectrum technique, the spectrum of a data modulator carrier is widened by changing the carrier frequency in a pseudo random modulator manner. For their operation both of this techniques rely on the ability of a noise like spreading code called a pseudo random or pseudo noise sequence.
PN SEQUENCE
A Pseudo Noise (PN) sequence is defined as a coded sequence of 0’s & 1’s with certain autocorrelation properties. The maximum length sequence, a type of cyclic code is commonly used as a periodic PN sequence.
In case of spread spectrum a Periodic PN sequence is used with a period of N = 2m-1, where m is the length of the shift register. Such sequences have long periods and require simple instrumentation in the form of a linear feedback shift register. PN sequence may also be a periodic. Such sequence is known as Barker sequence.
DIRECT SEQUENCE SPREAD SPECTRUM
The data sequence b (t) is a narrow band sequence whereas the PN sequence c(t) is a wideband sequence. The product signal m (t) i.e.b (t)*c (t) will have a spectrum that is nearly same as that of the PN sequence.
In this the PN sequence performs the role of spreading the code by multiplying the information bearing signal b (t) by the spreading code c (t). Each information bit is chopped up into a number of small time increments. This small time increment is called as chip.




ALGORITHM
  1. Generate the signal which is to be spread.
  2. Generate the PN sequence.
  3. Multiply the PN sequence with message signal.
  4. Display the pseudo sequence and frequency-hop spread sequence.



OUTPUTS:
DIRECT SEQUENCE SPREAD SPECTRUM
ORIGINAL SEQUENCE












PSEUDO RANDOM BIT SEQUENCE


DSSS SIGNAL
FFT OF DSSS SIGNAL




RESULT
Thus the MATLAB program for direct sequence spread spectrum technique was executed and the waveforms were obtained.





PROGRAM
clc;
clear all;

s=round(rand(1,20));

Pattern=[];
for i=1:20
    if(s(1,i)==1)
        SS=zeros(1,6);
    else
        SS=ones(1,6);
    end
    Pattern=[Pattern SS];
end

figure,plot(Pattern);
axis([1,120,-1,2]);
title('Original Signal');

Pr=round(rand(1,120));
figure,plot(Pr);
axis([1,120,-1,2]);
title('Pseudo Random Number');

Hopped_sig=xor(Pattern,Pr);

% Modulating Hopped Signal
DSSS_sig=[];
t=1:120;
fc=0.1;
f1=cos(2.*t.*pi.*fc);
f2=cos(2.*t.*pi.*fc+pi);

for j=1:120
if(Hopped_sig(j)==true)
    DSSS_sig=[DSSS_sig f1];
else
    DSSS_sig=[DSSS_sig f2];

end
end

figure,plot(DSSS_sig);
axis([1,1200,-1,2]);
title('DSSS Signal');

figure,plot(abs(fft(DSSS_sig)));
% axis([1,120,-1,2]);
title('FFT');


 
 
Support : Ebin EPhrem | Ebin Ephrem | #Gabbarism
Copyright © 2011. Services | Embedded Support | Reviews | Virtual Technologys - All Rights Reserved
Template Created by ebinephrem.com Published by Ebin Ephrem
Proudly powered by Blogger