Experiment No 1

30
Experiment No. 1 Source Coding 1 (Text Coding & Compression using Huffman Coding) a. Find out relative frequencies or probabilities in a given text (Each student to use different text of about half page or one page). b. Design Huffman code using Computer program. The Computer program should have proper labels with lot of comment statements for the purpose of ease of readability. Details of special functions/sub-routines used should be included. c. Verify the computer generated code by the one obtained manually/analytically. d. Apply decoding and check whether you get back original data sequence. e. Find entropy of the source (text). f. How much compression (in terms of compression ratio or percentage compression) is obtained? Give comments on the results obtained. Theory: Huffman codes are an important class of prefix codes. The basic idea behind Huffman coding is to assign to each symbol of an alphabet a sequence of bits roughly equal in length to the amount of information conveyed by the symbol. The end result is a source code whose average codeword length approaches the fundamental limit set by the entropy of a discrete memoryless source. Program: %Huffman coding and decoding% function[a code dict] =scan(text) disp('Enter the text'); text= 'You add new functions to the MATLAB vocabulary by expressing them in terms of existing functions. The existing commands and functions that compose the new function reside in a text file called an M-file. M-files can be either scripts or functions. Scripts are simply files containing a sequence of MATLAB statements. Functions make use of their own local variables and accept input arguments. The name of an M-file begins with an alphabetic character and has a filename extension of .m. The M-file name, less its extension, is what MATLAB searches for when you try to use the script or function. A line at the top of a function M-file contains the syntax definition. The name of a function, as defined in the first line of the M-file, should be the same as the name of the file without the .m extension.'; c=text; c n=length(c); a(1:91,1)=32:122; a(1:91,2)=0; %initialize the 2nd column of matrix by 0%

Transcript of Experiment No 1

Page 1: Experiment No 1

Experiment No. 1

Source Coding 1 (Text Coding & Compression using Huffman Coding)a. Find out relative frequencies or probabilities in a given text (Each student to use different text of about half page or

one page).b. Design Huffman code using Computer program. The Computer program should have proper labels with lot of

comment statements for the purpose of ease of readability. Details of special functions/sub-routines used should be included.

c. Verify the computer generated code by the one obtained manually/analytically.d. Apply decoding and check whether you get back original data sequence.e. Find entropy of the source (text).f. How much compression (in terms of compression ratio or percentage compression) is obtained?

Give comments on the results obtained.

Theory: Huffman codes are an important class of prefix codes. The basic idea behind Huffman coding is to assign to each symbol of an alphabet a sequence of bits roughly equal in length to the amount of information conveyed by the symbol. The end result is a source code whose average codeword length approaches the fundamental limit set by the entropy of a discrete memoryless source.

Program:

%Huffman coding and decoding%function[a code dict] =scan(text)disp('Enter the text');text= 'You add new functions to the MATLAB vocabulary by expressing them in terms of existing functions. The existing commands and functions that compose the new function reside in a text file called an M-file. M-files can be either scripts or functions. Scripts are simply files containing a sequence of MATLAB statements. Functions make use of their own local variables and accept input arguments. The name of an M-file begins with an alphabetic character and has a filename extension of .m. The M-file name, less its extension, is what MATLAB searches for when you try to use the script or function. A line at the top of a function M-file contains the syntax definition. The name of a function, as defined in the first line of the M-file, should be the same as the name of the file without the .m extension.';c=text;cn=length(c);a(1:91,1)=32:122;a(1:91,2)=0; %initialize the 2nd column of matrix by 0%

%Calculation of frequencies of characterfor k=1:91; for i=1:n; if c(i)==31+k; a(k,2)=a(k,2)+1; end endendm=length(a);

Page 2: Experiment No 1

%Removal of rows in which the frequency of character is 0 means the 2nd column is equal to 0%for i=m:-1:1; if a(i,2)==0; a(i,:)=[]; end m=length(a);endb=0;for i=1:m b=a(i,2)+b;endfor l=1:m a(l,3)=a(l,2)/b; %calculation of probability of each character in a given text and making 3rd column in the matrix%enddisp('The relative frequencies shown by 2nd column and probabilities shown by 3rd column in a given text is:');a;

%creating dictionary%[dict,avglen] =huffmandict(a(:,1),a(:,3));disp('dictionary');dictfprintf('The average length of huffman code is %f \n',avglen);

% Calculation of Entropy %entro=0;for i=1:m; entro=entro+(a(i,3)*(log(1/a(i,3))));endentropy=entro;disp('The resulted entropy is:');disp(entropy);

% Encoding %hcode= huffmanenco(c,dict);% encodes the signal sig using the Huffman codes described by the code dictionary dict%disp('The encoded text by huffman coding is');disp(hcode);

% Decoding %decoded=huffmandeco(hcode,dict);% decodes the numeric Huffman code vector comp using the code dictionary dict%disp('Result after decoding of huffman code');disp(decoded);n=length(decoded);for i=1:n dectext(i)=char(decoded(i));enddisp('The decoded text');disp(dectext);

Page 3: Experiment No 1

Result obtained:

Enter the text:

c =

You add new functions to the MATLAB vocabulary by expressing them in terms of existing functions. The existing commands and functions that compose the new function reside in a text file called an M-file. M-files can be either scripts or functions. Scripts are simply files containing a sequence of MATLAB statements. Functions make use of their own local variables and accept input arguments. The name of an M-file begins with an alphabetic character and has a filename extension of .m. The M-file name, less its extension, is what MATLAB searches for when you try to use the script or function. A line at the top of a function M-file contains the syntax definition. The name of a function, as defined in the first line of the M-file, should be the same as the name of the file without the .m extension.

The relative frequencies shown by 2nd column and probabilities shown by 3rd column in a given text is:

a =

32.0000 140.0000 0.1743

44.0000 4.0000 0.0050

45.0000 6.0000 0.0075

46.0000 11.0000 0.0137

65.0000 7.0000 0.0087

66.0000 3.0000 0.0037

70.0000 1.0000 0.0012

76.0000 3.0000 0.0037

77.0000 9.0000 0.0112

83.0000 1.0000 0.0012

84.0000 7.0000 0.0087

89.0000 1.0000 0.0012

97.0000 45.0000 0.0560

Page 4: Experiment No 1

98.0000 7.0000 0.0087

99.0000 27.0000 0.0336

100.0000 12.0000 0.0149

101.0000 79.0000 0.0984

102.0000 31.0000 0.0386

103.0000 6.0000 0.0075

104.0000 28.0000 0.0349

105.0000 55.0000 0.0685

107.0000 1.0000 0.0012

108.0000 22.0000 0.0274

109.0000 17.0000 0.0212

110.0000 63.0000 0.0785

111.0000 40.0000 0.0498

112.0000 10.0000 0.0125

113.0000 1.0000 0.0012

114.0000 20.0000 0.0249

115.0000 45.0000 0.0560

116.0000 59.0000 0.0735

117.0000 19.0000 0.0237

118.0000 2.0000 0.0025

119.0000 7.0000 0.0087

120.0000 8.0000 0.0100

121.0000 6.0000 0.0075

dictionary

Page 5: Experiment No 1

dict =

[ 32] [1x3 double]

[ 44] [1x7 double]

[ 45] [1x7 double]

[ 46] [1x6 double]

[ 65] [1x7 double]

[ 66] [1x8 double]

[ 70] [1x10 double]

[ 76] [1x8 double]

[ 77] [1x6 double]

[ 83] [1x10 double]

[ 84] [1x7 double]

[ 89] [1x10 double]

[ 97] [1x4 double]

[ 98] [1x7 double]

[ 99] [1x5 double]

[100] [1x6 double]

[101] [1x3 double]

[102] [1x5 double]

[103] [1x7 double]

[104] [1x5 double]

[105] [1x4 double]

[107] [1x10 double]

[108] [1x5 double]

Page 6: Experiment No 1

[109] [1x5 double]

[110] [1x4 double]

[111] [1x4 double]

[112] [1x6 double]

[113] [1x9 double]

[114] [1x5 double]

[115] [1x4 double]

[116] [1x4 double]

[117] [1x5 double]

[118] [1x9 double]

[119] [1x7 double]

[120] [1x6 double]

[121] [1x7 double]

The average length of huffman code is 4.321295

The resulted entropy is:

2.9700

The encoded text by huffman coding is:

Columns 1 through 20

1 0 1 0 1 0 0 1 0 1 1 0 1 1 1 1 1 0 1 0

Columns 21 through 40

0 0 1 0 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 0

………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………

Page 7: Experiment No 1

Columns 3441 through 3460

1 1 1 0 0 0 1 0 1 0 0 0 0 1 0 1 1 0 1 1

Columns 3461 through 3470

0 0 1 0 0 1 1 1 1 1

Result after decoding of huffman code:

Columns 1 through 20

89 111 117 32 97 100 100 32 110 101 119 32 102 117 110 99 116 105 111 110

Columns 21 through 40

115 32 116 111 32 116 104 101 32 77 65 84 76 65 66 32 118 111 99 97

…………………………………………………………………………………………………………………………………………………………….

Columns 781 through 800

116 104 111 117 116 32 116 104 101 32 46 109 32 101 120 116 101 110 115 105

Columns 801 through 803

111 110 46

The decoded text:

You add new functions to the MATLAB vocabulary by expressing them in terms of existing functions. The existing commands and functions that compose the new function reside in a text file called an M-file. M-files can be either scripts or functions. Scripts are simply files containing a sequence of MATLAB statements. Functions make use of their own local variables and accept input arguments. The name of an M-file begins with an alphabetic character and has a filename extension of .m. The M-file name, less its extension, is what MATLAB searches for when you try to use the script or function. A line at the top of a function M-file contains the syntax definition. The name of a function, as defined in the first line of the M-file, should be the same as the name of the file without the .m extension.

Page 8: Experiment No 1

Experiment no.2

Source coding 2 (Arithmetic Coding)a) Find out relative frequencies or probabilities in a given text (Each student to use different text of

about half page or one page).b) Design Arithmetic code using Computer program.c) Apply decoding and check whether you get back original data sequence.d) Give comments on the results obtained.

Program:

function [coding]=arithmetic(text)disp('entered text =');text= 'You add new functions to the MATLAB vocabulary by expressing them in terms of existing functions. The existing commands and functions that compose the new function reside in a text file called an M-file. M-files can be either scripts or functions. Scripts are simply files containing a sequence of MATLAB statements. Functions make use of their own local variables and accept input arguments. The name of an M-file begins with an alphabetic character and has a filename extension of .m. The M-file name, less its extension, is what MATLAB searches for when you try to use the script or function. A line at the top of a function M-file contains the syntax definition. The name of a function, as defined in the first line of the M-file, should be the same as the name of the file without the .m extension.';c=text;disp(c);x=32:122;x=x';x(:,2)=0; % calclation of frequencyfor i=1:length(c); for j=1:length(x); if c(i)==x(j,1); x(j,2)=x(j,2)+1; end endend % removal of redundant rowsfor i=91:-1:1; if x(i,2)==0; x(i,:)=[]; endendcount=x(:,2); % calculation of probabilityx(:,3)=x(:,2)./length(c);disp('The relative frequencies and probability in a given text = ')disp(x)p=x(:,3); % generation of sequencefor i=1:91;

Page 9: Experiment No 1

x(i,4)=i;endfor i=1:length(c); for j=1:91; if c(i)==x(j,1); seq(i)=x(j,4); end endenddisp('seq =')disp(seq) % arithmetic codingcode = arithenco(seq,count); %in this function count represents the source' statistics by listing the number of times each symbol of alphabet occurs in a test data set.disp('The code of a given text =')disp(code) % decodingdecode = arithdeco(code,count,length(seq));disp('The result after decoding =')disp(decode) % result in text formfor i=1:length(decode); for j=1:91; if decode(i)==x(j,4); msg(i)=char(x(j,1)); end endenddisp('The text after decoding =')disp(msg) % calculation of entropyh=-sum(p.*log2(p));disp('Entropy =')disp(h) % calculation of saving.s=8*length(c); %calculate the length of uncoded text.t=length(code); %calculate the length of coded text.c=(s-t)/s;saving=c*100; %saving in percentdisp('saving=')disp(saving)

Result Obtained:

entered text =

Page 10: Experiment No 1

You add new functions to the MATLAB vocabulary by expressing them in terms of existing functions. The existing commands and functions that compose the new function reside in a text file called an M-file. M-files can be either scripts or functions. Scripts are simply files containing a sequence of MATLAB statements. Functions make use of their own local variables and accept input arguments. The name of an M-file begins with an alphabetic character and has a filename extension of .m. The M-file name, less its extension, is what MATLAB searches for when you try to use the script or function. A line at the top of a function M-file contains the syntax definition. The name of a function, as defined in the first line of the M-file, should be the same as the name of the file without the .m extension.

The relative frequencies and probability in a given text =

32.0000 140.0000 0.1743

44.0000 4.0000 0.0050

45.0000 6.0000 0.0075

46.0000 11.0000 0.0137

65.0000 7.0000 0.0087

66.0000 3.0000 0.0037

70.0000 1.0000 0.0012

76.0000 3.0000 0.0037

77.0000 9.0000 0.0112

83.0000 1.0000 0.0012

84.0000 7.0000 0.0087

89.0000 1.0000 0.0012

97.0000 45.0000 0.0560

98.0000 7.0000 0.0087

99.0000 27.0000 0.0336

100.0000 12.0000 0.0149

101.0000 79.0000 0.0984

Page 11: Experiment No 1

102.0000 31.0000 0.0386

103.0000 6.0000 0.0075

104.0000 28.0000 0.0349

105.0000 55.0000 0.0685

107.0000 1.0000 0.0012

108.0000 22.0000 0.0274

109.0000 17.0000 0.0212

110.0000 63.0000 0.0785

111.0000 40.0000 0.0498

112.0000 10.0000 0.0125

113.0000 1.0000 0.0012

114.0000 20.0000 0.0249

115.0000 45.0000 0.0560

116.0000 59.0000 0.0735

117.0000 19.0000 0.0237

118.0000 2.0000 0.0025

119.0000 7.0000 0.0087

120.0000 8.0000 0.0100

121.0000 6.0000 0.0075

seq =

Columns 1 through 20

12 26 32 1 13 16 16 1 25 17 34 1 18 32 25 15 31 21 26 25

Page 12: Experiment No 1

Columns 21 through 40

30 1 31 26 1 31 20 17 1 9 5 11 8 5 6 1 33 26 15 13

……………………………………………………………………………………………………………………………………..

………………………………………………………………………………………………………………………………………

Columns 781 through 800

31 20 26 32 31 1 31 20 17 1 4 24 1 17 35 31 17 25 30 21

Columns 801 through 803

26 25 4

The code of a given text =

Columns 1 through 20

0 0 1 1 1 1 0 1 0 1 1 0 1 1 1 0 0 0 1 0

Columns 21 through 40

0 0 1 1 1 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0

………………………………………………………………………………………………………………………….

………………………………………………………………………………………………………………………….

Columns 3421 through 3440

1 0 0 1 1 1 0 1 1 1 0 0 0 0 1 1 1 0 1 0

Columns 3441 through 3452

0 0 1 1 1 1 0 0 0 0 0 0

Page 13: Experiment No 1

The result after decoding =

Columns 1 through 20

12 26 32 1 13 16 16 1 25 17 34 1 18 32 25 15 31 21 26 25

Columns 21 through 40

30 1 31 26 1 31 20 17 1 9 5 11 8 5 6 1 33 26 15 13

……………………………………………………………………………………………………………………………………….

Columns 781 through 800

31 20 26 32 31 1 31 20 17 1 4 24 1 17 35 31 17 25 30 21

Columns 801 through 803

26 25 4

The text after decoding =

You add new functions to the MATLAB vocabulary by expressing them in terms of existing functions. The existing commands and functions that compose the new function reside in a text file called an M-file. M-files can be either scripts or functions. Scripts are simply files containing a sequence of MATLAB statements. Functions make use of their own local variables and accept input arguments. The name of an M-file begins with an alphabetic character and has a filename extension of .m. The M-file name, less its extension, is what MATLAB searches for when you try to use the script or function. A line at the top of a function M-file contains the syntax definition. The name of a function, as defined in the first line of the M-file, should be the same as the name of the file without the .m extension.

Entropy =

4.2848

saving=

46.2640

Page 14: Experiment No 1

Experiment no.3(a)

Basic Digital Communication. (a). Computer based Generation of random binary data and its verification.

Program:

close all;clear all;clc;%random binary data%n=input('Enter the number of binary sequence:')A=randint(1,n);%finding no. of ones%N1=max(size(find(A==1)));%finding no. of zeroes%Z0=max(size(find(A==0)));totalsize=N1+Z0; fprintf('\n total length of binary sequence is %i\n',totalsize);fprintf('\n No of ones in binary sequence is: %i',N1);fprintf('\n No of zeroes in binary sequence is: %i\n',Z0); %Verification:calculate the probability of ones and zeroes as to 50 perc% disp('Probability of ones and zeroes respectively');%probability of ones%ones=N1/totalsize;disp(ones); %probability of zeroes%zeroes=Z0/totalsize;disp(zeroes);

Result Obtained:

Enter the number of binary sequence:10000

n = 10000

total length of binary sequence is 10000

No of ones in binary sequence is: 5042

No of zeroes in binary sequence is: 4958

Probability of ones and zeroes respectively

0.5042

0.4958

Page 15: Experiment No 1

Experiment no.3(b)

(b) Computer based Generation of AWGN for a specific value of mean, and standard deviation. Use computer program to find the pdf, mean value, and standard deviation of the generated sequence. Each student should generate a different sequence using a different value of seed integer.

Program:

clear all;clc;n=input('Enter the sequence length:');noise=normrnd(0,1,1,n);%finding the mean% avg=mean(noise); %finding the standard deviation% stddev=std(noise); %plot the experimental and practical% x=-4:0.01:4;pd=normpdf(x,avg,stddev);theoritical=[-2:.01:2]; pdn=normpdf(theoritical,0,1);plot(theoritical,pdn,'r:');hold onplot(x,pd,'b-');legend('theoritical','practical');hold offxlabel('x');ylabel('prob density function p(x)'); fprintf('\n The mean value is: %i',avg);fprintf('\n The standard deviation is: %i\n',stddev);

Result Obtained:

Enter the sequence length:10000

The mean value is: 1.884803e-003 The standard deviation is: 9.874310e-001

Page 16: Experiment No 1

-4 -3 -2 -1 0 1 2 3 40

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

x

prob

den

sity

fun

ctio

n p(

x)Plot of experimental and theoritical pdf

theoriticalpractical

Page 17: Experiment No 1

Experiment No. 4

Baseband Binary Signalling over AWGN channel.a. Write a program to simulate a baseband binary signaling (e.g. BPSK) over an AWGN channel and using

threshold detector at the receiver. Find the BER vs SNR curve. Make sure that enough bits are transmitted at different SNRs to get an accurate curve.

b. Compare the curve obtained in (a) above with the empirically obtained curve using the formula for BER vs SNR.

c. Check whether MATLAB or some of its tool-box has some readymade command for this kind of curve to be obtained.

Program:

% Baseband signalingclear all;clc;n=input('Enter the length of binary sequence:');inptsig = randn(1,n);SNR=input('\nEnter the SNR value:');%Generation of BPSK signal over an awgn channelfor i=1:n if(inptsig(i)>0) inptdata(i)=+1; else inptdata(i)=-1; end end disp('The transmitted signal is:');for i=1:n fprintf('%i',inptdata(i));end %AWGN channel simulationfor j=0:SNR awgnsig = awgn(inptsig,j); for i=1:n if(awgnsig(i)>0) rcvdata(i)=1; else rcvdata(i)=-1; end end %Bit error rate calculation corct=0; incrct=0; for i=1:n if(inptdata(i)==rcvdata(i)) corct=corct+1; else incrct=incrct+1; endendber(j+1)=incrct/n;end% Ploting BER vs SNR both by simulated data

Page 18: Experiment No 1

snr= 0:SNR;subplot(2,1,1);semilogy(snr,ber);grid onxlabel('SNR (dB)');ylabel('BER ');legend('experimental');title('BER vs SNR curve for BPSK');subplot(2,1,2);semilogy(snr,0.5*erfc(snr/4));grid onxlabel('SNR (dB)');ylabel('BER ');legend('theoritical');title('BER vs SNR Curve for BPSK over AWGN');

Result Obtained:

Enter the length of binary sequence:1000

Enter the SNR value:20

The transmitted signal is:11-1111111-11-11-111-111-111-1-111-1-1-1-1111-1-1-111-1-1-11-1-111-1111-1-1-1-1-11-1-11111111-1-1-11-111-1-1-11-1-11-1-1-1-11-111-11111-11-1-111-1-1-1-11-1-11111-1111-11-11-1-11-1-11-1-1-1-11-1-1-1-1111-1-1-111-1111-111-1-1-1-1-1-1-1-11-1-1-11-1-1111-1-1-111-1-1-11-1-111-11-11-1-1-111-1-11-11-1-11-1111-1-111-1-11-111111-11-1-1-111-1-1-111-11-1-111-111-11-111-1-11-1-1-1-1-1-11-1-11-1-11-1111-1-1-1-1-1111-1-1-1-1-111-11-111-1-1-111111111-1-111-11-111-11-11-1-11-1-111-11-1111-1-111-11-111111-1-111-11-1-1-11-11-11-1-1-11111-1-1-1-11-111-11-1111-1-111-11-11-1-1-11-111-11-1-111-1-11-1-1-1-11-1-1-1-1-1-111-11-1-1-111-1-11-1-1-11-11-1-11-1-1-1-111-11-1-11-1-1-11-11-1-1-11111-11-1-1-1-1111-11-11-11-1-1-1-11-1-1-11-1-111-1-1-1-11-1-111-1111-1111111-11-1-11111-11-11-1-11-111-1-11-1-11111-1-1-1-111-11-11-1-111-1111-1-1-1-111-111-1-1-11-11-1-11-1-111-1-1-11-111-11-11-1-11111-1-11-1-111-1-11-11-11-1-1-1111111-11-111-11-1-1-1-1-1-111-111-111111-11-11111111-11-1111-1-11-11-11-11-11-11-111-1-1-1111-1111111-1-1-11-1-1-1-1-11111-11-111-1-111-111-111-11-1-1-1-111-1111-1-11111-11-111-111-1111-1-1-1-1-1-1-1-11-111-1-111-1-111111-1-11111-1-1-1-11-11-1-11111-1111-1-11-1-1-1-1-1-1-1-11-1-11-1-111-11-1-111111-11-1-111-1-111-1-111-1-1-1-111-1-1-1-1-1-11-1111111-11-11-1-1-1-11-11-11-1-111111-11-1-11-111-1-1-1-1-1-1-11-1-11-11-11-111111-111-1-1-1-1111-1-11-111-1-11-11-1-11-111-1-1-111111-111-1-1111-1-11-111-1-111-1111-11-11-11-1-11-1-11-1111-111-1-11-11-1-11-1-1-1-11-11-11-111-1-11-1-1-111-111-1-1-1-1-11-11-11-11

Page 19: Experiment No 1

0 5 10 15 2010

-2

10-1

100

SNR (dB)

BER

BER vs SNR curve for BPSK

0 5 10 15 2010

-15

10-10

10-5

100

SNR (dB)

BER

BER vs SNR Curve for BPSK over AWGN

experimental

theoritical

Comments:

We will get the better BER vs SNR curve if we transmit more number of bit.

BER Vs SNR can also be analyzed by MATLAB, as it has a readymade tool for that so called “bertool” and can be open by the same command.

Page 20: Experiment No 1

Experiment no: 5

Baseband Binary signaling over channel with ISI and AWGNa) Simulate a channel having a sampled impulse response of two components. b) Find the BER vs SNR for baseband BPSK signaling over this channel, and compare the results

obtained in expt. 4.c) Design a suitable linear feed-forward transversal equalizer(s) for the given channel. Again obtain the

BER vs SNR curve experimentally through a computer simulation program.d) Comment on the results obtained.

Part (a) – Calculation of Equalizer impulse response

Program:

%This program is to find out the equalizer impulse responseclose all;clear all;clc;N = input('Type in the length of output vector = '); % Read the numerator and denominator coefficients num = input('Type in the numerator coefficients = ');den = input('Type in the denominator coefficients = '); % Compute the desired number of inverse transform coefficients x = [1 zeros(1, N-1)]; y = filter(num, den, x);disp('Coefficients of the power series expansion');disp(y);

Result Obtained:

Type in the length of output vector = 2Type in the numerator coefficients = 1Type in the denominator coefficients = [0.6 0.4]Coefficients of the power series expansion 1.6667 -1.1111

Page 21: Experiment No 1

Part (b) – Program to find out BER vs SNR for baseband BPSK signaling without using equalizer

Program:

%This program is to generate the binary data and transmit it on the%distorted cannel of impulse response [0.8 0.6] with modulation technique%BPSK%Base-band Binary signaling over Gaussian Channelclose all;clear all;clc;N=input ('Enter the length of data :');S= input('Enter the SNR value :');tx=randn(1,N);SNR=S; c=[0.8 0.6]; %Generation of BPSK signal over an awgn channelfor n=1:Nif (tx(n)>0)tx_data(n)=1;elsetx_data(n)=-1;endend % AWGN channel simulationfor snr=0:SNR Rx=awgn(tx_data,snr,'measured','dB'); Rt=conv(Rx,c);%Thershold detection of received signal for n=1:N if(Rt(n)>0) rx(n)=1; else rx(n)=-1; end end % Bit error rate calculationhit=0;miss=0; for n=1:N if(rx(n)==tx_data(n)) hit=hit+1; else miss=miss+1; end endBER(snr+1)=miss/N; endber= smooth(BER); % Ploting BER vs SNR both by simulated data

Page 22: Experiment No 1

S=0:SNR;subplot(211);semilogy(S,ber,'r');grid onxlabel('SNR in dB');ylabel('BER');title('BER Vs SNR curve for BPSK over AWGN without equalizer');legend('simulated');subplot(212);semilogy(S,0.5*erfc(S./4));grid ontitle('BER Vs SNR curve for BPSK over AWGN without equalizer');xlabel('SNR in dB');ylabel('BER');legend('Theoretical');

Result Obtained:

Enter the length of data :10000

Enter the SNR value :20

0 5 10 15 2010

-3

10-2

10-1

100

SNR in dB

BER

BER Vs SNR curve for BPSK over AWGN without equalizer

simulated

0 5 10 15 2010

-15

10-10

10-5

100 BER Vs SNR curve for BPSK over AWGN without equalizer

SNR in dB

BER

Theoretical

Part (c) – Program to find out BER vs SNR for baseband BPSK signaling using equalizer

Page 23: Experiment No 1

Program:

%This program is to generate the binary data and transmit it on the%distorted cannel of impulse response [0.8 0.6] and equalizer used here is%of 6 tapclose all;clear all;clc;N=input ('Enter the length of binary data :');S= input('Enter the SNR value :');tx=randn(1,N);SNR=S; c=[0.8 0.6]; %Generation of BPSK signal over an awgn channel for n=1:N if (tx(n)>0) tx_data(n)=1; else tx_data(n)=-1; endend % AWGN channel simulation for snr=0:SNRRx=awgn(tx_data,snr,'measured','dB');Rt=conv(Rx,c);Tap=[1.2500 -0.9375 0.7031 -0.5273 0.3955 -0.2966];R=conv(Rt,Tap); %Thershold detection of received signal for n=1:Nif(R(n)>0)rx(n)=1;elserx(n)=-1;endend % Bit error rate calculation hit=0;miss=0; for n=1:Nif(rx(n)==tx_data(n))hit=hit+1;elsemiss=miss+1;endendBER(snr+1)=miss/N; end

Page 24: Experiment No 1

% Ploting BER vs SNR both by simulated data S=0:SNR;semilogy(S,BER)grid onxlabel('SNR in dB');ylabel('BER');title('BER Vs SNR curve for BPSK over AWGN with equalizer ');

Result Obtained:

Enter the length of binary data : 10000

Enter the SNR value : 25

0 2 4 6 8 10 12 1410

-4

10-3

10-2

10-1

100

SNR in dB

BER

BER Vs SNR curve for BPSK over AWGN with equalizer

Comments:

Page 25: Experiment No 1

It can be seen from the above figures that error performance degrades when channel impulse response also comes into picture.

When equalization is done error performance improves.