diff options
Diffstat (limited to 'Digital_Communications_by_S_Sharma/2-PROBABILITY_RANDOM_SIGNALS_AND_RANDOM_PROCESS.ipynb')
-rw-r--r-- | Digital_Communications_by_S_Sharma/2-PROBABILITY_RANDOM_SIGNALS_AND_RANDOM_PROCESS.ipynb | 729 |
1 files changed, 729 insertions, 0 deletions
diff --git a/Digital_Communications_by_S_Sharma/2-PROBABILITY_RANDOM_SIGNALS_AND_RANDOM_PROCESS.ipynb b/Digital_Communications_by_S_Sharma/2-PROBABILITY_RANDOM_SIGNALS_AND_RANDOM_PROCESS.ipynb new file mode 100644 index 0000000..63e2df4 --- /dev/null +++ b/Digital_Communications_by_S_Sharma/2-PROBABILITY_RANDOM_SIGNALS_AND_RANDOM_PROCESS.ipynb @@ -0,0 +1,729 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 2: PROBABILITY RANDOM SIGNALS AND RANDOM PROCESS" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.12: Probability_density_function.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability density function \n", +"//Example 2.12\n", +"//Find find the value of k\n", +"clc;\n", +"clear;\n", +"function y=FX1(x) //for -infinte<x<=0\n", +" y=0 \n", +"endfunction\n", +"function y=FX2(x) //for 0<x<=10\n", +" y=k*x^2 \n", +"endfunction\n", +"function y=FX3(x) //for 10<x<infine\n", +" y=100*k\n", +"endfunction\n", +"k=poly(0,'k');\n", +" //from the expression for CDF is given\n", +"y=100*k //for 10<x<infine\n", +"y==1; \n", +"k=1/100; //k=y/100\n", +"disp(k,'i) k = ');\n", +"//CDF function can be expressed\n", +"// FX(x)=P(X<=x)\n", +"P5=FX2(5); //x=5\n", +"disp(P5,'ii) P(X<=5) = ');\n", +" //now differentiating with respect tox we ,have \n", +" //PDF fX=0 for -infinte<x<=0,10<x<infine\n", +"x=poly(0,'x');\n", +"m=x^2/100;\n", +"df=derivat(m); // for 0<x<=10\n", +"disp(' for 0<x<=10',df,'iii)PDF a) fX(x) =');\n", +"disp(' -infinte<x<=0,10<x<infine',0,' b)fX(x) = ');\n", +"\n", +"x1=5,x2=7;\n", +"function y=z(x),\n", +" y=x/50;\n", +"endfunction\n", +"P=intg(x1,x2,z);\n", +"disp(P,'iv) P(5<X<=7) =');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.13: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability \n", +"//Example 2.13\n", +"//page no 54\n", +"//find the probability \n", +"clc;\n", +"clear;\n", +"function y=f(x),\n", +" y=2*exp(-(2*x)),//Probability Density Function\n", +"endfunction\n", +"\n", +"a=1;\n", +"b=3;\n", +"P=intg(a,b,f);//probability that random variable between 1 and 3\n", +"disp(P,'P(1<X<3)=');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.14: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability \n", +"//Example 2.14\n", +"//page no 54\n", +"//find the probability \n", +"clc;\n", +"clear;\n", +"function y=f(x),\n", +" y=12*x^3-21*x^2+10*x,//Probability Density Function\n", +"endfunction\n", +"a=0;\n", +"b=1/2;\n", +"P=intg(a,b,f);\n", +"disp(P,'P(X<=1/2)=');\n", +"disp(1-P,'P(X>1/2)=');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.1_a: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability\n", +"//Example 2.1.a\n", +"//page no 43\n", +"//Find the Probability \n", +"clc;\n", +"clear;\n", +"redballs=3;\n", +"whiteballs=4;\n", +"blackballs=5; \n", +"//P=ways of choosing a red ball/Total no. of ways choosing a ball\n", +"Pro=redballs/(redballs+whiteballs+blackballs);\n", +"disp('Probability Getting red ball is');\n", +"disp(Pro,'P(R)=');\n", +"" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.1_b: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"\n", +"//Caption: Probability\n", +"//Example 2_1b\n", +"//page no 43\n", +"//Find the probability Getting black ball\n", +"clc;\n", +"clear;\n", +"redballs=3;\n", +"whiteballs=4;\n", +"blackballs=5;\n", +"//Probability Getting black ball\n", +"prob=blackballs/(redballs+whiteballs+blackballs);\n", +"p=1-prob;\n", +"disp('Probability not getting black ball');\n", +"disp(p,'P(B~)=');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.1_c: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability\n", +"//Example 2.1.c\n", +"//page no 43\n", +"//Find the probability \n", +"clc;\n", +"clear;\n", +"redballs=3;\n", +"whiteballs=4;\n", +"blackballs=5;\n", +"//Probability Getting black ball\n", +"pb=blackballs/(redballs+whiteballs+blackballs);\n", +"//Probability Getting white ball\n", +"pw=whiteballs/(redballs+whiteballs+blackballs);\n", +"//Probability Getting white ball or black ball\n", +"pwb=pb+pw// black and white are mutuallly exclusive events\n", +"disp('Probability Getting white ball or black ball will be ')\n", +"disp(pwb,'P(B+W)=')\n", +"" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.20: Joint_probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Joint probability\n", +"//Example 2.20\n", +"//Page no 60\n", +"//Find Determine the value of constant C\n", +"clc;\n", +"clear;\n", +"X=[0,0;2,2;2,0];\n", +"Y=[0,0;3,3;0,3];\n", +"function y=f(x,y),\n", +" y=2*x+y;\n", +"endfunction\n", +"P=int2d(X,Y,f);\n", +"C=poly(0,'C');\n", +"//we know that joint PDF \n", +"// double integration fXY(x,y)dxdy=1\n", +"//C*P==1;\n", +"C=1/P;\n", +"disp(C,'C = ')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.23: probability_density_function.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: probability density function \n", +"//Example 2.23\n", +"//page no \n", +"//verify the area under curve is unity,prove that the mean is zero\n", +"clc;\n", +"clear;\n", +"//continuous random variable X in the range(-3,3)\n", +"//PDF of fucntions\n", +"function y=fX1(x)\n", +" y=((3+x)^2)/16; //for -3<=x<=-1\n", +"endfunction\n", +"a1=-3;\n", +"a2=-1;\n", +"\n", +"function y=fX2(x), //for-1<=x<=1\n", +" y=(6-2*x^2)/16;\n", +"endfunction\n", +"b1=-1;\n", +"b2=1;\n", +"\n", +"function y=fX3(x)\n", +" y=((3-x)^2)/16; //for 1<=x<=3\n", +"endfunction\n", +"c1=1;\n", +"c2=3;\n", +"//area under pdf curve\n", +"//area = integral Fx(x)dx from -3 to 3\n", +"area =intg(a1,a2,fX1)+intg(b1,b2,fX2)+intg(c1,c2,fX3);\n", +"disp(area,'Area =');\n", +"disp(' Therefore area under PDF curve is unity.');\n", +"function y=f1(x)\n", +" y=(x*(3+x)^2)/16; //for -3<=x<=-1\n", +"endfunction\n", +"a1=-3;\n", +"a2=-1;\n", +"\n", +"function y=f2(x), //for-1<=x<=1\n", +" y=(x*(6-2*x^2))/16;\n", +"endfunction\n", +"b1=-1;\n", +"b2=1;\n", +"function y=f3(x)\n", +" y=(x*(3-x)^2)/16; //for 1<=x<=3\n", +"endfunction\n", +"c1=1;\n", +"c2=3;\n", +"mx=intg(a1,a2,f1)+intg(b1,b2,f2)+intg(c1,c2,f3);//mean value\n", +"disp(mx,'Mean value =');\n", +"disp(' Therefore mean value is zero.');\n", +"//Therefore area under PDF curve is unity\n", +"//Hence Therefore mean value is zero" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.24: mean_mean_Square_Standard_deviation.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: mean ,mean Square Standard deviation\n", +"//Example 2.24\n", +"//page no \n", +"//Find mean,mean Square ,Standard deviation\n", +"clc;\n", +"clear;\n", +"function y=f(x)\n", +" y=x/(2*%pi); //for 0<=x<=2*%pi\n", +"endfunction\n", +"\n", +"a=0;\n", +"b=2*%pi;\n", +"mx=intg(a,b,f);//mean value\n", +"disp(mx,'Mean value mx=');\n", +"\n", +"function y=fX(x)\n", +" y=x^2/(2*%pi); //for 0<=x<=2*%pi\n", +"endfunction\n", +"a=0;\n", +"b=2*%pi;\n", +"//X^2=E(X^2) \n", +"X2=intg(a,b,fX);//mean square value\n", +"disp(X2,'Mean square value X^2 =');\n", +"\n", +"sigma2=X2-mx^2;//variance\n", +"sigma=sqrt(sigma2);//Standard deviation\n", +"disp(sigma,'Standard deviation sigma=')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.2: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability\n", +"//Example 2.2\n", +"//page no 43\n", +"//find the probability of getting 5\n", +"clc;\n", +"clear;\n", +"total_possibleoutcomes=6*6;\n", +"probabilityofeachoutcome=1/total_possibleoutcomes;//probability of each outcome\n", +"noofways=4; //ways of getting 5\n", +"probability=noofways*probabilityofeachoutcome;//probability of getting 5\n", +"disp(probability,'Probability of getting 5 is');\n", +"" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.31: Mean_and_Variance.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Mean,Variance\n", +"//Example 2.31\n", +"//page no 85\n", +"//find i)Mean\n", +"// ii)Variance of given function\n", +"clc;\n", +"clear;\n", +"\n", +"//Mean Value\n", +"function X=f(x),\n", +" z=3*(1-x)^2,//Marginal Probability Density Function\n", +" X=x*z\n", +"endfunction\n", +"a=0;\n", +"b=1;\n", +"EX=intg(a,b,f);//Mean value of X\n", +"\n", +"function Y=c(y)\n", +" z=3*(1-y)^2,//Marginal Probability Density Function\n", +" Y=y*z\n", +"endfunction\n", +"\n", +"EY=intg(a,b,c);//Mean value of Y\n", +"disp(EX,'i)Mean of X =')\n", +"disp(EY,' Mean of Y =')\n", +"\n", +"//Variance\n", +"function X=g(x),\n", +" z=3*(1-x)^2,//Marginal Probability Density Function\n", +" X=x^2*z\n", +"endfunction\n", +"a=0;\n", +"b=1;\n", +"EX2=intg(a,b,g);\n", +"\n", +"function Y=h(y)\n", +" z=3*(1-y)^2,//Marginal Probability Density Function\n", +" Y=y^2*z\n", +"endfunction\n", +"\n", +"EY2=intg(a,b,h);\n", +"\n", +"vX2=EX2-(EX)^2;//Variance of X\n", +"vY2=EY2-(EY)^2;//Variance of Y\n", +"\n", +"disp(vX2,'ii)Variance of X');\n", +"\n", +"disp(vY2,' Variance of Y');\n", +"" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.3: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability\n", +"//Example 2.3\n", +"//page no 43\n", +"//find the probability \n", +"clc;\n", +"clear;\n", +"total_cards=52;\n", +"ways_of_drawingtwocards=52*51/(2*1);//ways of drawing 2cards from a deck of 52cards\n", +"diamonds=13;\n", +"Hearts=13;\n", +"waysof_diamonds_Hearts=diamonds*Hearts;//ways of drawing a Diamond and a Heart\n", +"probability=waysof_diamonds_Hearts/ways_of_drawingtwocards;\n", +"\n", +"disp(probability,'Probability that one card is Diamond and Othercard is Heart');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.4: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability\n", +"//Example 2.4\n", +"//page no 44\n", +"//find the probability \n", +"clc;\n", +"clear;\n", +"whiteballs=4;\n", +"blackballs=3;\n", +"pa1=whiteballs/(whiteballs+blackballs);//probability of first ball is white\n", +"pa2=(whiteballs-1)/(whiteballs+blackballs-1);//probability of second ball is white\n", +"pa3=(blackballs)/(whiteballs+blackballs-2);//probability of third ball is black\n", +"required_probability=pa1*pa2*pa3;\n", +"disp(required_probability,'probability of first two balls are white and third ball is black');\n", +"" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.5: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"\n", +"//Caption: Probability\n", +"//Example 2.5\n", +"//page no 44\n", +"//find the probability \n", +"clc;\n", +"clear;\n", +"whiteballs=5;\n", +"redballs=3;\n", +"balckballs=2;\n", +"totalballs=whiteballs+redballs+balckballs;\n", +"pw=whiteballs/totalballs;//probability of gettingfirst ball is white\n", +"pr=redballs/(totalballs-1);//probability of getting second ball is red\n", +"pb=balckballs/(totalballs-2);//probability of getting third ball is black\n", +"\n", +"possbilecases=6;\n", +"probabalityof_eachcase=pw*pr*pb;\n", +"totalprobability=6*probabalityof_eachcase;//required probability\n", +"disp(totalprobability,'Probability of balls will be in different colours');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.6: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability\n", +"//Example 2.6\n", +"//page no 45\n", +"//find the probability \n", +"clc;\n", +"clear;\n", +"//Probability of solving the problem\n", +"PA=3/4;\n", +"PB=2/3;\n", +"PC=1/4;\n", +"//Probability of not not able solving the problem\n", +"PNA=1-PA;\n", +"PNB=1-PB;\n", +"PNC=1-PC;\n", +"//probability that no one will solve the problem\n", +"probability_notsolve=PNA*PNB*PNC;\n", +"//probability that problem willbe solved\n", +"probability_solve=1-probability_notsolve;\n", +"disp(probability_solve,'probability that problem willbe solved');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.7: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability\n", +"//Example 2.7\n", +"//page no 45\n", +"//find the probability \n", +"clc;\n", +"clear;\n", +"whiteballs=3;\n", +"redballs=2;\n", +"totalballs=whiteballs+redballs;\n", +"pw1=whiteballs/totalballs;//probability of first ball is white\n", +"pr2=redballs/(totalballs-1)//conditional probability event second ball is red with first white\n", +"probability=pw1*pr2//probability of second ball is red with first ball is white\n", +"disp(probability,'probability of first ball is white and second ball is red');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.8: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability\n", +"//Example 2.8\n", +"//page no 45\n", +"//find the probability that recorded number is 2\n", +"clc;\n", +"clear;\n", +"head=1/2;//probability of getting head\n", +"tail=1-head;//probability of getting tail\n", +"head2= head*1/6;//probability of getting head with recorded number is 2\n", +"tail2=tail*1/36;//probability of getting tail with recorded number is 2\n", +"\n", +"//probability of getting recorded number is 2\n", +"p=head2+tail2;\n", +"disp(p,'probability of getting recorded number is 2');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.9: Probability.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption: Probability\n", +"//Example 2.9\n", +"//page no 46\n", +"//find the probability \n", +"clc;\n", +"clear;\n", +"PA=1/8;\n", +"PB=1/12;\n", +"probability_makingerror=1/10001;\n", +"probability=(PA*PB)/((PA*PB)+((1-PA)*(1-PB)*probability_makingerror));\n", +"disp(probability,'Probability of program is correct');" + ] + } +], +"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 +} |