diff options
Diffstat (limited to 'Analog_Communication_by_V_Chandrasekar/8-Information_theory.ipynb')
-rw-r--r-- | Analog_Communication_by_V_Chandrasekar/8-Information_theory.ipynb | 312 |
1 files changed, 312 insertions, 0 deletions
diff --git a/Analog_Communication_by_V_Chandrasekar/8-Information_theory.ipynb b/Analog_Communication_by_V_Chandrasekar/8-Information_theory.ipynb new file mode 100644 index 0000000..ba5f8a1 --- /dev/null +++ b/Analog_Communication_by_V_Chandrasekar/8-Information_theory.ipynb @@ -0,0 +1,312 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 8: Information theory" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.10_A: SNR.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"W=3000;\n", +"SNR_db=39;// 10log (SNR_ratio)=SRN_db\n", +"SNR_ratio=7943; //10^(3.9)\n", +"\n", +"C=W*log2(1+SNR_ratio);\n", +"\n", +"disp(C,'Capacity (in bits/s) =');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.1_A: Information_Rate.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"p1=1/8;\n", +"p2=1/8;\n", +"p3=5/8;\n", +"p4=1/8; //Quantization Levels\n", +"//B is the Bandwidth of the signal\n", +"\n", +"H=p1*log2(1/p1)+p2*log2(1/p2)+p3*log2(1/p3)+p4*log2(1/p4);\n", +"\n", +"disp(H,'The average Information (in bits/message)=');\n", +"disp('The Information Rate R=rH =2*B(1.55) =3.1B bits/s');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.2_A: ShannonFano_and_Huffman_coding.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"m1=0.2;\n", +"m2=0.3;\n", +"m3=0.2;\n", +"m4=0.15;\n", +"m5=0.15; // probability of 5 source messages \n", +"\n", +"H=m1*log2(1/m1)+m2*log2(1/m2)+m3*log2(1/m3)+m4*log2(1/m4)+m5*log2(1/m5);//Average information in bits\n", +"\n", +"//a) Shannon-fano coding\n", +" //coding\n", +"// m1 0.2 0 0 00\n", +"// m2 0.3 0 1 01\n", +"// m3 0.2 1 0 10\n", +"// m4 0.15 1 1 0 110\n", +"// m5 0.15 1 1 1 111\n", +"\n", +"L=(0.2*2)+(.3*2)+(0.2*2)+(2*0.15*3) //Average code word length(in bits)=probability *coding length\n", +"\n", +"n=H/L; \n", +"\n", +"disp(n*100,'Coding efficiency for Shannon Fano coding is');\n", +"\n", +"//b) Huffman coding\n", +"\n", +"// m1 0.2 01\n", +"// m2 0.3 00 \n", +"// m3 0.2 11\n", +"// m4 0.15 010\n", +"// m5 0.15 110\n", +"\n", +"L=(0.2*2)+(.3*2)+(0.2*2)+(2*0.15*3) //Average code word length(in bits)=probability *coding length\n", +"\n", +"n=H/L;\n", +"\n", +"disp(n*100,'Coding efficiency for Huffman coding is');\n", +"\n", +"//change in answer due to rounded off value in text-book" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.3_A: Gaussian_Channel.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"\n", +"PSD=10^(-9); //noise PSD in W/Hz\n", +"Bw=4000;//Wandwidth in Hz\n", +"\n", +"//a) \n", +"E=0.1 //Energy in Joules\n", +"C=Bw*log2(1+E/(2*PSD*Bw));\n", +"disp(C,'a) Capacity of the gaussian channel(in bits/s) when E is 0.1J=');\n", +"\n", +"//b) \n", +"E=0.001 //Energy in Joules\n", +"C=Bw*log2(1+E/(2*PSD*Bw));\n", +"disp(C,'b) Capacity of the gaussian channel(in bits/s) when E is 0.001J=');\n", +"\n", +"//c)\n", +"Bw=10000;\n", +"C=Bw*log2(1+E/(2*PSD*Bw));\n", +"disp(C,'d) Capacity of the gaussian channel(in bits/s) when Bw is 10Khz=');\n", +"\n", +"disp('100 times fall in Energy when the BW is increased by 2.5 times');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.5_A: Throughput_efficiency.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"k=973;\n", +"n=1023;\n", +"Pa=0.99;\n", +"Tw=10*10^(-6);\n", +"Tl=40*10^(-6);\n", +"N=4;\n", +"\n", +"N_sw=(k/n)*(Pa/(1+Tl/Tw));// efficiency of stop and wait algorithm\n", +"N_sgpull=(k/n)*(1/(1+N*(1-Pa)/Pa));//efficiency of go-back-N algorithm\n", +"Nsr=(k/n)*Pa;// efficiency of selective repeat algorithm\n", +"\n", +"disp(N_sw,'N s&w');\n", +"disp(N_sgpull,'Nsgpull');\n", +"disp(Nsr,'Nsr');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.6_A: Rate_of_source.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"p1=1/2;\n", +"p2=1/4;\n", +"p3=1/8;\n", +"p4=1/16;\n", +"p5=1/16;// probabilities\n", +"\n", +"H=p1*log2(1/p1)+p2*log2(1/p2)+p3*log2(1/p3)+p4*log2(1/p4)+p5*log2(1/p5);\n", +"Bw=4000; //Bandwidth in Hz\n", +"R=2*H*Bw ;\n", +"\n", +"disp(R,'Rate of the source ( in bits/s) is');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.7_A: entropy_of_equiprobable_source.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"\n", +"// probability of all the events are same\n", +"syms N;\n", +"\n", +"H_X=N*[(-1/N)*log(1/N)]; //H(X)=(-1/N)log(1/N)+(-1/N)log(1/N)+....N times\n", +"\n", +"disp(H_X,'H(X)=');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.8_A: Self_Information.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"P0=2/3; //P(X=0)\n", +"P1=2/3; //P(Y=0)\n", +"H_x=0.919;\n", +"H_y=0.919;\n", +"H_b=0.919; //Hb(2/3)\n", +"\n", +"//since X,Y pair is uniformly distributed on three values\n", +"H_xy=log2(3); // H(X,Y)\n", +"\n", +"H_xdivy=H_xy-H_y; //H(X/Y)=H(X,Y)-H(Y)\n", +"I_xdivy=H_x-H_xdivy; //I(X,Y)=H(X)-H(X/Y)\n", +"\n", +"disp(I_xdivy,'I(X,Y)=');\n", +"\n", +"" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} |