SlideShare a Scribd company logo
Experiment=1<br />A program to generate PDF of random number<br />clc<br />clear all<br />clf<br />n=input('enter the no.of random data');<br />y=rand(1,n);<br />t=0.1;<br />for i=1:10<br />    k=(y>t*(i-1)&y<t*i);<br />    b(i)=sum(k);<br />    x(i)=b(i)/(n*t);<br />    disp(x(i));<br />end<br />h=[.1 .2 .3 .4 .5 .6 .7 .8 .9 1]; <br />s=plot(h,x);<br />axis([0.1 1 0 7]);<br />ylabel('PDF');<br />xlabel('random no.');<br />title('PDF of random no.');<br />enter the no.of random data2000<br />    1.0650<br />     0.9550<br />     0.9650<br />     0.9950<br />     1.0550<br />     0.8950<br />     1.0850<br />      0.9200<br />      1.0250<br />      1.0400<br />                                       Experiment no. =2<br />Generation of random number using Linear Congruential  Method<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />d=input('enter the value of modulus m in terms of small integer=');<br />m=input('enter the value of modulus m=')<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br /> <br />%%%% CASE-1ST %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of small integer<br /> <br />if c==0 && m==d<br />    disp('it is multiplicative congruential method');<br />    for i=1:m<br />        a=17;<br />        X(i+1)= mod((a*X(i)+c),m);       %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                       %calculation of the random numbers  <br />    end<br />    <br />%%%% CASE-2ND %%%%%%<br />%when the value of increment is other than zero and the value of modulus is<br />%in terms of small integer<br /> <br />else if c~=0 && m==d<br />    disp('it is mixed congruential method');<br />    for i=1:m<br />        a=17;<br />        X(i+1)= mod((a*X(i)+c),m);       %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                       %calculation of the random numbers  <br />    end<br /> <br />%%%% CASE-3RD %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of %modulus is in terms of 2^b<br /> <br />    else if c~=0 && m==2^b<br />    disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br />    Period= m                             %calculation of period  <br />    a= 1+(4*k)                            %calculation of multiplier  <br />    for i=1:m<br />        X(i+1)= mod((a*X(i)+c),m);        %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                        %calculation of the random numbers <br />    end<br />    <br />%%%% CASE-4TH %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br />    else if c==0 && m==2^b<br />    disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br />    a=3+(8*k)                            %calculation of multiplier <br />    Period= m/4                          %calculation of period  <br />    for i=1:m                             <br />        X(i+1)= mod((a*X(i)+c),m);       %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                      %calculation of the random numbers<br />    end<br />        end<br />        end<br />    end<br />end<br />disp(R);                                         % displaying all the random numbers<br />Experiment =1<br />RESULT<br /> CASE-1ST<br />when the value of increment is equal to zero and the value of modulus is in terms of small integer<br />enter the value of seed X(1)=27<br />enter the value of increment c=0<br />enter the value of modulus m in terms of small integer=100<br />enter the value of modulus m=100<br />m =100<br />enter the value of b=6<br />enter the value of an integer k=1<br />it is multiplicative congruential method<br />  Columns 1 through 15 <br />         0    0.5900    0.0300    0.5100    0.6700    0.3900    0.6300    0.7100    0.0700    0.1900    0.2300    0.9100    0.4700    0.9900    0.8300<br />  Columns 16 through 30 <br />    0.1100    0.8700    0.7900    0.4300    0.3100    0.2700    0.5900    0.0300    0.5100    0.6700    0.3900    0.6300    0.7100    0.0700    0.1900<br />  Columns 31 through 45 <br />    0.2300    0.9100    0.4700    0.9900    0.8300    0.1100    0.8700    0.7900    0.4300    0.3100    0.2700    0.5900    0.0300    0.5100    0.6700<br />  Columns 46 through 60 <br />    0.3900    0.6300    0.7100    0.0700    0.1900    0.2300    0.9100    0.4700    0.9900    0.8300    0.1100    0.8700    0.7900    0.4300    0.3100<br />  Columns 61 through 75 <br />    0.2700    0.5900    0.0300    0.5100    0.6700    0.3900    0.6300    0.7100    0.0700    0.1900    0.2300    0.9100    0.4700    0.9900    0.8300<br />Columns 76 through 90 <br />    0.1100    0.8700    0.7900    0.4300    0.3100    0.2700    0.5900    0.0300    0.5100    0.6700    0.3900    0.6300    0.7100    0.0700    0.1900<br /> Columns 91 through 100  <br /> 0.2300    0.9100    0.4700    0.9900    0.8300    0.1100    0.8700    0.7900    0.4300    0.3100<br />CASE-2ND <br />when the value of increment is other than zero and the value of modulus is in terms of small integer<br />enter the value of seed X(1)=27<br />enter the value of increment c=43<br />enter the value of modulus m in terms of small integer=100<br />enter the value of modulus m=100<br />m = 100<br />enter the value of b=6<br />enter the value of an integer k=1<br />it is mixed congruential method<br /> <br /> Columns 1 through 15 <br />         0    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700<br />  Columns 16 through 30 <br />    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200<br />  Columns 31 through 45 <br />    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700<br />  Columns 46 through 60 <br />    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200<br />  Columns 61 through 75 <br />    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700<br />  Columns 76 through 90 <br />    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200<br />  Columns 91 through 100 <br />    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200    0.2700    0.0200    0.7700    0.5200<br />CASE-3RD <br />when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is in terms of 2^b<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of modulus m in terms of small integer=100<br />enter the value of modulus m=64<br />m = 64<br />enter the value of b=6<br />enter the value of an integer k=1<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period =64<br />a = 5<br />Columns 1 through 15 <br />         0    0.1250    0.6719    0.4063    0.0781    0.4375    0.2344    0.2188    0.1406    0.7500    0.7969    0.0313    0.2031    0.0625    0.3594<br />  Columns 16 through 30 <br />    0.8438    0.2656    0.3750    0.9219    0.6563    0.3281    0.6875    0.4844    0.4688    0.3906         0    0.0469    0.2813    0.4531    0.3125<br />  Columns 31 through 45 <br />    0.6094    0.0938    0.5156    0.6250    0.1719    0.9063    0.5781    0.9375    0.7344    0.7188    0.6406    0.2500    0.2969    0.5313    0.7031<br />  Columns 46 through 60 <br />    0.5625    0.8594    0.3438    0.7656    0.8750    0.4219    0.1563    0.8281    0.1875    0.9844    0.9688    0.8906    0.5000    0.5469    0.7813<br />  Columns 61 through 64 <br />    0.9531    0.8125    0.1094    0.5938<br />CASE-4TH<br />when the value of increment is equal to zero and the value of modulus is in terms of 2^b and the seed is an odd number<br />enter the value of seed X(1)=1<br />enter the value of increment c=0<br />enter the value of modulus m in terms of small integer=100<br />enter the value of modulus m=64<br />m =  64<br />enter the value of b=6<br />enter the value of an integer k=1<br />if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method<br />a =11<br />Period =    16<br />Columns 1 through 15 <br />         0    0.1719    0.8906    0.7969    0.7656    0.4219    0.6406    0.0469    0.5156    0.6719    0.3906    0.2969    0.2656    0.9219    0.1406<br />  Columns 16 through 30 <br />    0.5469    0.0156    0.1719    0.8906    0.7969    0.7656    0.4219    0.6406    0.0469    0.5156    0.6719    0.3906    0.2969    0.2656    0.9219<br />  Columns 31 through 45 <br />    0.1406    0.5469    0.0156    0.1719    0.8906    0.7969    0.7656    0.4219    0.6406    0.0469    0.5156    0.6719    0.3906    0.2969    0.2656<br />  Columns 46 through 60 <br />    0.9219    0.1406    0.5469    0.0156    0.1719    0.8906    0.7969    0.7656    0.4219    0.6406    0.0469    0.5156    0.6719    0.3906    0.2969<br />  Columns 61 through 64 <br />    0.2656    0.9219    0.1406    0.5469<br />Experiment=  3<br />Kolmogorov-Smirnov test for uniformity of random numbers<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />Q=input('enter the specified significance level Q (it can be 0.10,0.05 or 0.01)=')<br />m=2^b                                    %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br />    disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br />    Period= m                                      %calculation of period  <br />    a= 1+(4*k)                                      %calculation of multiplier  <br />    for i=1:m-1<br />        X(i+1)= mod((a*X(i)+c),m);        %calculation of the random integers<br />        Y(i+1)=X(i+1)/m;                         %calculation of the random numbers <br />    end<br />    <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br />    else if c==0 && m==2^b<br />    disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br />    a=3+(8*k)                                      %calculation of multiplier <br />    Period= m/4                                   %calculation of period  <br />    for i=1:m-1                             <br />        X(i+1)= mod((a*X(i)+c),m);       %calculation of the random integers<br />        Y(i+1)=X(i+1)/m;                        %calculation of the random numbers<br />    end<br />        end<br />end<br /> <br />%step 2.) RANK THE DATA FROM SMALLEST TO LARGEST<br />R=sort(Y);<br />disp(R)<br />N= m                                     %sample size   <br />for i=1:m<br />    d1(i)= i/N-R(i);<br />    d2(i)=R(i)-(i-1)/N;<br />end<br /> <br />%step 3.) COMPUTATION OF LARGEST DEVIATION OF SN(x) ABOVE F(x)<br />D1 = max(d1)                             %largest deviation of SN(x) above F(x) <br /> <br />%step 4.) COMPUTATION OF LARGEST DEVIATION OF SN(x) BELOW F(x)<br />D2 = max(d2)                             %largest deviation of SN(x) below F(x)<br /> <br />%step 5.) COMPUTATION OF SAMPLE STATISTIC VALUE<br />D= max(D1,D2)                            %sample statistic <br /> <br />%step 6.) COMPUTATION OF CRITICAL SAMPLE STATISTIC VALUE<br />if Q==0.10<br />    p= 1.22/(N^(1/2));<br />    disp('the critical value DQ=')       <br />    DQ=p                                 %the critical sample statistic value  <br />else if Q==0.05<br />    p= 1.36/(N^(1/2));<br />    disp('the critical value DQ=')<br />    DQ=p                                 %the critical sample statistic value  <br />    else if Q==0.01<br />    p= 1.63/(N^(1/2));<br />    disp('the critical value DQ=')<br />    DQ=p                                 %the critical sample statistic value<br />        end <br />    end<br />end<br /> <br />%step 7.) DECISION FOR UNIFORM DISTRIBUTION<br />if D>DQ<br />    disp('the null hypothesis that the data are a sample form a unoform distribution is rejected or we can say that the random numbers generated are not uniformly distributed');<br />else<br />    disp('the test shows that no difference has been detected between the true distribution and the uniform distribution or we can say that the generated random numbers are uniformly distributed')<br />end <br />Experiment no. =3<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=6<br />enter the value of an integer k=1<br />enter the specified significance level Q (it can be 0.10,0.05 or 0.01)=0.05<br />Q = 0.0500<br />m =  64<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period = 64<br />a =  5<br />Columns 1 through 15 <br /> 0         0    0.0313    0.0469    0.0625    0.0781    0.0938    0.1094    0.1250    0.1406    0.1563    0.1719    0.1875    0.2031    0.2188<br /> Columns 16 through 30 <br />  0.2344    0.2500    0.2656    0.2813    0.2969    0.3125    0.3281    0.3438    0.3594    0.3750    0.3906    0.4063    0.4219    0.4375    0.4531<br />  Columns 31 through 45 <br />    0.4688    0.4844    0.5000    0.5156    0.5313    0.5469    0.5625    0.5781    0.5938    0.6094    0.6250    0.6406    0.6563    0.6719    0.6875<br />  Columns 46 through 60 <br />    0.7031    0.7188    0.7344    0.7500    0.7656    0.7813    0.7969    0.8125    0.8281    0.8438    0.8594    0.8750    0.8906    0.9063    0.9219<br />  Columns 61 through 64 <br />    0.9375    0.9531    0.9688    0.9844<br />N =    64<br />D1 =    0.0313<br />D2 =     0<br />D =    0.0313<br />the critical value DQ=<br />DQ =    0.1700<br />the test shows that no difference has been detected between the true distribution and the uniform distribution or we can say that the generated random numbers are uniformly distributed<br />                                                       Experiment no. =4<br />Run test for testing the independence of generated random numbers<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />Q= 0.05                      %enter the specified significance level Q <br />Z=1.96<br />m=2^b                        %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br />    disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br />    Period= m                                  %calculation of period  <br />    a= 1+(4*k)                                  %calculation of multiplier  <br />    for i=1:m-1<br />        X(i+1)= mod((a*X(i)+c),m);    %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                    %calculation of the random numbers <br />    end<br />    <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br />    else if c==0 && m==2^b<br />    disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br />    a=3+(8*k)                                     %calculation of multiplier <br />    Period= m/4                                  %calculation of period  <br />    for i=1:m-1                             <br />        X(i+1)= mod((a*X(i)+c),m);     %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                     %calculation of the random numbers<br />    end<br />        end<br />end<br />S=sum(R)                                       %sum of random numbers  <br />N=length(R)                                    %length of random numbers<br />M= S/N                                           %mean of random numbers<br />n1=0;                                              %n1=numbers of individual observations above the mean<br />n2=0;                                              %n2=numbers of individual observations below the mean<br />for i=1:N<br />    if R(i)> M<br />        n1=n1+1;<br />    else n2=n2+1;<br />    end<br />end<br />disp('numbers of individual observations above the mean n1=');<br />disp(n1)<br />disp('numbers of individual observations below the mean n2=');<br />disp(n2)<br />mean=(2*n1*n2)/N+(1/2);<br />variance=2*n1*n2*(2*n1*n1-N)/(N^2*(N-1));<br />b=0;<br />for i=1:N-1<br />    if R(i)>M && R(i+1)<M<br />        b=b+1;<br />    else if R(i)<M && R(i+1)>M<br />            b=b+1;<br />        end<br />    end<br />end<br />disp('total no. of runs are b =')<br />disp(b)<br />Zo=(b-mean)/((variance)^(1/2))<br />if -Z<Zo<Z<br />    disp('Hypothesis of independence cannot be rejected on the basis of this test')<br />else<br />    disp('Hypothesis of independence is rejected on the basis of this test')<br />end         <br /> <br />Experiment no.=4<br />RESULT<br />enter the value of seed X(1)=5<br />enter the value of increment c=7<br />enter the value of b=6<br />enter the value of an integer k=1<br />Q = 0.0500<br />Z =    1.9600<br />m =    64<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period =    64<br />a =    5<br />Columns 1 through 15 <br />         0    0.5000    0.6094    0.1563    0.8906    0.5625    0.9219    0.7188    0.7031    0.6250    0.2344    0.2813    0.5156    0.6875    0.5469<br />  Columns 16 through 30 <br />    0.8438    0.3281    0.7500    0.8594    0.4063    0.1406    0.8125    0.1719    0.9688    0.9531    0.8750    0.4844    0.5313    0.7656    0.9375<br />  Columns 31 through 45 <br />    0.7969    0.0938    0.5781         0    0.1094    0.6563    0.3906    0.0625    0.4219    0.2188    0.2031    0.1250    0.7344    0.7813    0.0156<br />  Columns 46 through 60 <br />    0.1875    0.0469    0.3438    0.8281    0.2500    0.3594    0.9063    0.6406    0.3125    0.6719    0.4688    0.4531    0.3750    0.9844    0.0313<br />  Columns 61 through 64 <br />    0.2656    0.4375    0.2969    0.5938<br />S =   31.4219<br />N =    64<br />M =    0.4910<br />numbers of individual observations above the mean n1=    32<br />numbers of individual observations below the mean n2=    32<br />total no. of runs are b =    29<br />Zo =   -0.8820<br />Hypothesis of independence cannot be rejected on the basis of this test<br />Experiment no.=5<br />Autocorrelation test<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />disp('at the specified significance level Q (it can be 0.10,0.05 or 0.01)=0.05')<br />Z=1.96<br />m=2^b                                    %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br />    disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br />    Period= m                                      %calculation of period  <br />    a= 1+(4*k)                                      %calculation of multiplier  <br />    for i=1:m-1<br />        X(i+1)= mod((a*X(i)+c),m);        %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                        %calculation of the random numbers <br />    end<br />    <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br />    else if c==0 && m==2^b<br />    disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br />    a=3+(8*k)                                      %calculation of multiplier <br />    Period= m/4                                  %calculation of period  <br />    for i=1:m-1                             <br />        X(i+1)= mod((a*X(i)+c),m);       %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                       %calculation of the random numbers<br />    end<br />        end<br />end<br />disp(R)<br />N=length(R)<br />i=input('enter the value of starting number=')<br />n=input('enter the value of lag=')<br />M= floor((N-i)/n-1)<br />for k=0:M<br />    b=R(i+k*n)*R(i+(k+1)*n);<br />end<br />c=sum(b)<br />Pin=((1/(M+1))*c)-0.25<br />S.D=(((13*M)+7)^(1/2))/(12*(M+1))<br />Zo=Pin/S.D<br />if -Z<Zo<Z<br />    disp('do not reject the null hypothesis of independence')<br />else <br />    disp('reject the null hyrothesis of independence')<br />end<br />    <br />Experiment no.=5<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=6<br />enter the value of an integer k=1<br />at the specified significance level Q (it can be 0.10,0.05 or 0.01)=0.05<br />Z =1.9600<br />m =    64<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period =    64<br />a =     5<br />Columns 1 through 15 <br />         0    0.1250    0.6719    0.4063    0.0781    0.4375    0.2344    0.2188    0.1406    0.7500    0.7969    0.0313    0.2031    0.0625    0.3594<br />  Columns 16 through 30 <br />    0.8438    0.2656    0.3750    0.9219    0.6563    0.3281    0.6875    0.4844    0.4688    0.3906         0    0.0469    0.2813    0.4531    0.3125<br />  Columns 31 through 45 <br />    0.6094    0.0938    0.5156    0.6250    0.1719    0.9063    0.5781    0.9375    0.7344    0.7188    0.6406    0.2500    0.2969    0.5313    0.7031<br />  Columns 46 through 60 <br />    0.5625    0.8594    0.3438    0.7656    0.8750    0.4219    0.1563    0.8281    0.1875    0.9844    0.9688    0.8906    0.5000    0.5469    0.7813<br />  Columns 61 through 64 <br />    0.9531    0.8125    0.1094    0.5938<br />N =    64<br />enter the value of starting number=2<br />i =     2<br />enter the value of lag=5<br />n =     5<br />M =    11<br />c =    0.7236<br />Pin =   -0.1897<br />S . D= 0.0851<br />Zo =   -2.2304<br />do not reject the null hypothesis of independence<br />                                                                   <br />Experiment no.=6<br />Generation of exponential distributed random number<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />m=2^b                                    %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br />    disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br />    Period= m                                         %calculation of period  <br />    a= 1+(4*k)                                         %calculation of multiplier  <br />    for i=1:m-1<br />        X(i+1)= mod((a*X(i)+c),m);          %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                         %calculation of the random numbers <br />    end<br />    <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br />    else if c==0 && m==2^b<br />    disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br />    a=3+(8*k)                                      %calculation of multiplier <br />    Period= m/4                                  %calculation of period  <br />    for i=1:m-1                             <br />        X(i+1)= mod((a*X(i)+c),m);       %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                       %calculation of the random numbers<br />    end<br />        end<br />end<br />%disp(R)<br />N=length(R)<br />%inverse transform technique to sample from the exponential distribution<br />L=input('enter the value of mean number of occurences per unit time(L)=')<br />for i=1:N<br />    Y(i)=-(1/L)*log(1-R(i));<br />end<br />%disp(Y)<br />t=0.1;<br />for i=1:70<br />    k=(Y>t*(i-1)&Y<t*i);<br />    b(i)=sum(k);<br />    x(i)=b(i)/(N*t);<br />    %disp(x(i))<br />end<br />%disp(b);<br />d=0.1:0.1:7<br />plot(d,x)<br />axis([0.1 7 0 1]);<br />xlabel('random number');<br />ylabel('PDF');<br />title('PDF of exponentially distributed random numbers');<br />Experiment no.:-6<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=12<br />enter the value of an integer k=1<br />m =   4096<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period =        4096<br />a =   5<br />N =   4096<br />enter the value of mean number of occurences per unit time(L)=1<br />L =   1<br />Experiment no.:-7<br /> Generation of normal distributed random number<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />m=2^b                                    %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br />    disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br />    Period= m                                        %calculation of period  <br />    a= 1+(4*k)                                       %calculation of multiplier  <br />    for i=1:m-1<br />        X(i+1)= mod((a*X(i)+c),m);         %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                         %calculation of the random numbers <br />    end<br />    <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br />    else if c==0 && m==2^b<br />    disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br />    a=3+(8*k)                                        %calculation of multiplier <br />    Period= m/4                                    %calculation of period  <br />    for i=1:m-1                             <br />        X(i+1)= mod((a*X(i)+c),m);        %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                        %calculation of the random numbers<br />    end<br />        end<br />end<br />%disp(R)<br />N=length(R)<br />%Direct transformation method to generate normal distributed random no.<br />for i=1:m/2<br />    Z(2*i-1)=((-2*log(R(2*i-1)))^(1/2))*cos(2*pi*R(2*i));<br />    Z(2*i)=((-2*log(R(2*i-1)))^(1/2))*sin(2*pi*R(2*i));<br />end<br />u=8;<br />j=2;<br />disp('value of mean u is 8');<br />disp('value of varience j is 2');<br />for i=1:N<br />    Y(i)=u+(j^1/2)*Z(i);<br />end<br />%Plot of pdf of normal distributed random no.<br />t=0.1;<br />for i=1:120<br />    k=(Y>t*(i-1)&Y<t*i);<br />    b(i)=sum(k);<br />    x(i)=b(i)/(N*t);<br />    %disp(x(i));<br />end<br />h=0.1:0.1:12; <br />s=plot(h,x);<br />axis([4 12 0 2]);<br />ylabel('PDF');<br />xlabel('random no.');<br />title('PDF of normal distributed random no.');<br />                                                  <br />                                                 Experiment no.:-7<br />RESULT<br />enter the value of seed X(1)=254<br />enter the value of increment c=5<br />enter the value of b=15<br />enter the value of an integer k=11<br />m =       32768<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period =    32768<br />a =  45<br />N =   32768<br />value of mean u is 8<br />value of varience j is 2<br />                                                Experiment no.:-8<br />Generation of weibull distributed random number<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />m=2^b                                    %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br />    disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br />    Period= m                                      %calculation of period  <br />    a= 1+(4*k)                                      %calculation of multiplier  <br />    for i=1:m-1<br />        X(i+1)= mod((a*X(i)+c),m);        %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                        %calculation of the random numbers <br />    end<br />    <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br />    else if c==0 && m==2^b<br />    disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br />    a=3+(8*k)                                        %calculation of multiplier <br />    Period= m/4                                     %calculation of period  <br />    for i=1:m-1                             <br />        X(i+1)= mod((a*X(i)+c),m);         %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                         %calculation of the random numbers<br />    End <br />        end<br />end<br />%disp(R)<br />N=length(R)<br />%Inverse transform technique to generate weibull distributed random no.<br />a=input('enter the value of location parameter a=');<br />B=input('enter the value of scale parameter B=');<br />for i=1:m<br />    Y(i)=a*((-log(1-R(i)))^1/B);<br />end<br />%Plot of pdf of weibull distributed random no.<br />t=0.1;<br />for i=1:100<br />    k=(Y>t*(i-1)&Y<t*i);<br />    b(i)=sum(k);<br />    x(i)=b(i)/(N*t);<br />    %disp(x(i));<br />end<br />h=0.1:0.1:10; <br />s=plot(h,x);<br />axis([0 5 0 2]);<br />ylabel('PDF');<br />xlabel('random no.');<br />title('PDF of weibull distributed random no.');<br />Experiment no.:-8<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=15<br />enter the value of an integer k=1<br />m =   32768<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period =   32768<br />a =   5<br />N =   32768<br />enter the value of location parameter a=0.5<br />enter the value of scale parameter B=0.5<br />>><br />Experiment no.:-9<br />Generation of uniformly distributed random no. using CDF<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />m=2^b                                    %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br />    disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br />    Period= m                                           %calculation of period  <br />    a= 1+(4*k)                                          %calculation of multiplier  <br />    for i=1:m-1<br />        X(i+1)= mod((a*X(i)+c),m);             %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                             %calculation of the random numbers <br />    end<br />    <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br />    else if c==0 && m==2^b<br />    disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br />    a=3+(8*k)                                       %calculation of multiplier <br />    Period= m/4                                   %calculation of period  <br />    for i=1:m-1                             <br />        X(i+1)= mod((a*X(i)+c),m);        %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                        %calculation of the random numbers<br />    end<br />        end<br />end<br />%disp(R)<br />N=length(R)<br />%inverse transform technique to sample from the exponential distribution<br />disp(' the value lower limit of interval is a=3');<br />disp(' the value of upper limit of interval is b=7');<br />a=3;<br />b=7;<br />for i=1:N<br />    Y(i)=a+((b-a)*R(i));<br />end<br />%plot of pdf of uniformly distributed random no.in interval [a,b]<br />t=0.1;<br />for i=1:40<br />    k=Y>a+((i-1)*t)&Y<a+(t*i);<br />    b(i)=sum(k);<br />    x(i)=b(i)/(N*t);<br />end<br />h=3.1:0.1:7;<br />plot(h,x)<br />axis([1 9 0 0.5]);<br />xlabel('random no')<br />ylabel('PDF')<br />title('PDF of uniformly distributed random no. is [1/(b-a)=1/4=0.25]');<br />    <br />Experiment no.:-9<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=14<br />enter the value of an integer k=1<br />m =    16384<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period =   16384<br />a =   5<br />N =  16384<br /> the value lower limit of interval is a=3<br /> the value of upper limit of interval is b=7<br />Experiment no.:-10<br />Generation of triangular distributed random number using CDF<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />m=2^b                                    %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br />    disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br />    Period= m                                       %calculation of period  <br />    a= 1+(4*k)                                       %calculation of multiplier  <br />    for i=1:m-1<br />        X(i+1)= mod((a*X(i)+c),m);         %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                         %calculation of the random numbers <br />    end<br />    <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br />    else if c==0 && m==2^b<br />    disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br />    a=3+(8*k)                                       %calculation of multiplier <br />    Period= m/4                                   %calculation of period  <br />    for i=1:m-1                             <br />        X(i+1)= mod((a*X(i)+c),m);       %calculation of the random integers<br />        R(i+1)=X(i+1)/m;                      %calculation of the random numbers<br />    end<br />        end<br />end<br />%disp(R)<br />N=length(R)<br />%Inverse transform technique to generate trianguiar distributed random no.<br />for i=1:N<br />    if R(i)<=0.5<br />        Y(i)=(2*R(i))^(1/2);<br />    else<br />        Y(i)=(2-(2*(1-R(i)))^(1/2));<br />    end<br />end<br />t=0.1;<br />for i=1:21<br />k=Y>(i-1)*t & Y<i*t;<br />b(i)=sum(k);<br />x(i)=b(i)/(N*t);<br />end<br />h=0:0.1:2;<br />plot(h,x)<br />axis([0 2 0 2])<br />xlabel('random no.')<br />ylabel('PDF')<br />title('PDF of triangular distributed random no.')<br />Experiment no.:-10<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=15<br />enter the value of an integer k=1<br />m =<br />       32768<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period =  32768<br />a =   5<br />N =   32768<br />                                                 Experiment no.=11<br />Generation of amplitude modulated waveform<br />clc<br />clear all<br />Vm=input('enter the value of amplitude of modulating signal=');<br />A=input('enter the value of amplitude of carrier signal=');<br />fm=input('enter the value of modulating frequency=');<br />fc=input('enter the value of carrier frequency=');<br />t=0:0.001:1;<br />x=Vm*cos(2*pi*fm*t); % modulating signal<br />%%%%%%%%%%%<br />subplot(4,1,1);<br />plot(t,x)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**modulating signal**');<br />c=A*cos(2*pi*fc*t); % carrier signal<br />%%%%%%%%%%<br />subplot(4,1,2);<br />plot(t,c)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**carrier signal**');<br />m=Vm/A;<br />s=(A*cos(2*pi*fc*t)).*(1+m.*cos(2*pi*fm*t));  % amplitude modulated signal<br />%%%%%%%%%%%%<br />subplot(4,1,3);<br />plot(t,s)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**amplitude modulated signal**');<br />y=c.*x;    %DSB-SC signal         <br />subplot(4,1,4);<br />plot(t,y)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**double side band supressed carrier signal**');<br /> <br />enter the value of amplitude of modulating signal=3<br />enter the value of amplitude of carrier signal=5<br />enter the value of modulating frequency=10<br />enter the value of carrier frequency=50<br />Experiment no.=12<br />Generation of frequency modulated wave<br />clc<br />clf<br />clear all<br />fm=input('enter the value of modulating frequency=');<br />fc=input('enter the value of carrier frequency=');<br />Vm=input('enter the value of amp of modulating signal=');<br />A=input('enter the valur of amp of carrier signal=');<br />mf=input('enter the value of modulating index=');<br />t=0:0.001:1;<br />x=Vm*cos(2*pi*fm*t); % modulating signal<br />%%%%%%%%%%%<br />subplot(3,1,1);<br />plot(t,x)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**modulating signal**');<br />%%%%%%%%%%%%%<br />c=A*cos(2*pi*fc*t); % carrier signal<br />subplot(3,1,2);<br />plot(t,c)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**carrier signal**');<br />%%%%%%%%%%%%%%<br />s=A*cos(2*pi*fc*t+mf*sin(2*pi*fm*t));  % frequency modulated signal<br />subplot(3,1,3);<br />plot(t,s)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**frequency modulated signal**');<br />enter the value of modulating frequency=10<br />enter the value of carrier frequency=50<br />enter the value of amp of modulating signal=4<br />enter the valur of amp of carrier signal=5<br />enter the value of modulating index=4<br />Experiment no.=13<br />Generation of phase modulated signal<br />clc<br />clear all<br />fm=input('enter the value of modulating frequency=');<br />fc=input('enter the value of carrier frequency=');<br />Vm=input('enter the value of amp of modulating signal=');<br />A=input('enter the valur of amp of carrier signal=');<br />mp=input('enter the value of modulating index=');<br />t=0:0.001:1;<br />x=Vm*cos(2*pi*fm*t); % modulating signal<br />%%%%%%%%%%%<br />subplot(3,1,1);<br />plot(t,x)<br />xlabel('time(second)');<br />ylabel('amplitude');<br />title('modulating signal');<br />%%%%%%%%%%%%<br />c=A*cos(2*pi*fc*t); % carrier signal<br />subplot(3,1,2);<br />plot(t,c)<br />xlabel('time(second)');<br />ylabel('amplitude');<br />title('carrier signal');<br />%%%%%%%%%%%%%%%%%<br />s=A*cos(2*pi*fc*t+mp*cos(2*pi*fm*t));  % phase modulated signal<br />subplot(3,1,3);<br />plot(t,s)<br />xlabel('time(second)');<br />ylabel('amplitude');<br />title('phase modulated signal');<br />enter the value of modulating frequency=10<br />enter the value of carrier frequency=50<br />enter the value of amp of modulating signal=4<br />enter the valur of amp of carrier signal=4<br />enter the value of modulating index=7<br />>><br />Experiment no.=14<br />Modulation and demodulation using amplitude shift keying<br />clc<br />clf<br />clear all<br />A=input('enter the value of carrier amplitude=');<br />n=input('enter the number of input data=');<br />x=rand(1,n);<br />%converting the signal( random num)into bipolar form<br />for i=1:10<br />    if(x(i)<0.5)<br />        y(i)=0;<br />    else y(i)=1;<br />    end<br />end<br />subplot(4,2,1); %plotting the input signal<br />stem(y);<br />axis([1 10 -1 1]);<br />title('**input signal**');<br />%plotting the carrier signal<br />    t=1:0.001:10;<br />    c=A*sin(2*pi*3*t);<br />    subplot(4,2,2);<br />    plot(t,c);<br />    xlabel('time->');<br />    ylabel('amplitude->');<br />    title('**carrier signal**');<br />    % plotting the ask signal<br />     for i=1:10<br />           t= i:0.001:(i+1);<br />            s=A*(sin(2*pi*3*t))*y(i);<br />            subplot(4,2,3);<br />            plot(t,s);<br />            hold on;<br />            axis([1 10 -5 5]);<br />             xlabel('time->');<br />            ylabel('amplitude');<br />            title('**ask modulated signal**');<br />          <br />            <br />   %sending modulated signal over awgn channel<br /> <br />   u=awgn(s,5,2);<br />   subplot(4,2,4);<br />   plot(t,u);<br />   hold on;<br />   axis([1 10 -10 10]);<br />   title('signal at reciever');<br />   xlabel('time-->');<br />   ylabel('amplitude');<br />   %operating recieved with LO<br />   recieved=sin(2*pi*3*t).*u;                   <br />   subplot(4,2,5);<br />   plot(t,recieved);<br />   hold on;<br />   axis([1 10 -10 10]);<br />   title('signal at reciever');<br />   xlabel('time-->');<br />   ylabel('amplitude');<br />   %applying integration on signal using successive summation approach<br />   v=1;<br />   w=sin(2*pi*3*t).*s;<br />   for t=i:0.001:(i+1);<br />       p(i)=sum(w(i:v));<br />       v=v+1;<br />   end<br />   v=1;<br />   subplot(4,2,6);<br />   for t=i:0.001:(i+1)<br />       m(i)=sum(recieved(i:v));<br />       plot(t,m(i));<br />       hold on<br />       v=v+1;<br />   end<br />   title('signal at reciever after integration');<br />   xlabel('time-->');<br />   ylabel('amplitude');<br />        end<br />   decision=max(p)/2;<br />   subplot(4,2,7);<br />   for i=1:10<br />       if m(i)>=decision<br />           y(i)=1;<br />       elseif m(i)< decision <br />           y(i)=0;<br />       end<br />       stem(y);<br />       axis([1 10 -1 1]);<br />       hold on;<br />       title('recieved data bits');<br />   end<br />   <br />RESULT (Experiment no.=14)<br />enter the value of carrier amplitude=5<br />enter the number of input data=10<br />>> <br />   <br />Experiment no.=15<br />Generation of Frequency Shift Keying<br />%Experiment-6<br />% Generation of frequency shift keying<br />clc<br />clear all<br />clf<br />fc=input('enter the value of carrier angular frequency=');<br />A=input('enter the value of carrier amplitude=');<br />n=input('enter the number of input data=');<br />x=rand(1,n);<br />%converting the signal(random num)into bipolar form<br />for i=1:n<br />    if(x(i)<0.5)<br />        y(i)=-1;<br />    else y(i)=1;<br />    end<br />end<br />%plotting the input signal<br />subplot(3,1,1);<br />stairs(y);<br />axis([1,10,-2,2]);<br />%plotting the carrier signal<br />    t=1:0.01:10;<br />    c=A*cos(2*pi*fc*t);       %carrier signal<br />    subplot(3,1,2);<br />    plot(t,c);<br />    xlabel('time(second)->');<br />    ylabel('amplitude->');<br />    title('**carrier signal**');<br />    % plotting the fsk signal<br />    subplot(3,1,3);<br />    for t=1:9<br />        for i = t:0.01:t+1<br />            s=A*(cos(2*pi*(fc+2*y(t))*i));         %fsk modulated signal<br />            plot(i,s);<br />            hold on;<br />            xlabel('time(second)->');<br />            ylabel('amplitude');<br />            title('**fsk modulated signal**')<br />        end<br />    end<br />RESULT (Experiment no.=15)<br />enter the value of carrier angular frequency=5<br />enter the value of carrier amplitude=4<br />enter the number of input data=10<br />Experiment no.=16<br />Generation of Phase Shift Keying<br />clc<br />clf<br />clear all<br />fc=input('enter the value of carrier frequency=');<br />A=input('enter the value of carrier amplitude=');<br />n=input('enter the number of input data=');<br />x=rand(1,n);<br />%converting the signal(random num)into bipolar form<br />for i=1:10<br />    if(x(i)<0.5)<br />        y(i)=-1;<br />    else y(i)=1;<br />    end<br />end<br />%plotting the input signal<br />subplot(3,1,1);<br />stairs(y);<br />axis([1 10 -2 2])<br />title('**input signal**');<br />%plotting the carrier signal<br />    t=1:0.01:10;<br />    c=A*cos(2*pi*fc*t);<br />    subplot(3,1,2);<br />    plot(t,c);<br />    xlabel('time->');<br />    ylabel('amplitude->');<br />    title('**carrier signal**');<br />    % plotting the psk signal<br />    subplot(3,1,3);<br />    for t=1:10<br />        for i = t:.01:t+1<br />            s=4*y(t)*(cos(2*pi*fc*i));<br />            plot(i,s);<br />            xlabel('time->');<br />            ylabel('amplitude');<br />            title('**psk modulated signal**');<br />            hold on;<br />        end<br />    end<br />           <br />RESULT (Experiment no.=16)<br />enter the value of carrier frequency=5<br />enter the value of carrier amplitude=4<br />enter the number of input data=10<br />
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile
Rajnifile

More Related Content

What's hot

QT1 - 06 - Normal Distribution
QT1 - 06 - Normal DistributionQT1 - 06 - Normal Distribution
QT1 - 06 - Normal Distribution
Prithwis Mukerjee
 
Mcqs (measures of dispersion)
Mcqs (measures of dispersion)Mcqs (measures of dispersion)
Mcqs (measures of dispersion)
Nadeem Uddin
 
Airthmetic mean
Airthmetic meanAirthmetic mean
Airthmetic mean
HimanshuMalhotra47
 
January 22, 2015
January 22, 2015January 22, 2015
January 22, 2015
khyps13
 
Chapter7
Chapter7Chapter7
5.5 Point Slope and Standard Form
5.5 Point Slope and Standard Form5.5 Point Slope and Standard Form
5.5 Point Slope and Standard Form
ramjdram
 
Lecture 10.4 bt
Lecture 10.4 btLecture 10.4 bt
Lecture 10.4 bt
btmathematics
 
Proportionspowerpoint
ProportionspowerpointProportionspowerpoint
Proportionspowerpoint
NeilfieOrit2
 
Measures of Dispersion: Standard Deviation and Co- efficient of Variation
Measures of Dispersion: Standard Deviation and Co- efficient of Variation Measures of Dispersion: Standard Deviation and Co- efficient of Variation
Measures of Dispersion: Standard Deviation and Co- efficient of Variation
RekhaChoudhary24
 
11.4 slope intercept form of a linear equation
11.4 slope intercept form of a linear equation11.4 slope intercept form of a linear equation
11.4 slope intercept form of a linear equation
GlenSchlee
 
How much time will be used for driving
How much time will be used for drivingHow much time will be used for driving
How much time will be used for driving
Ruo Yang
 
Final technology presentatio
Final technology presentatioFinal technology presentatio
Final technology presentatio
EvaSadowski
 
Ejercicio resuelto-de-estadc3adstica-descriptiva1
Ejercicio resuelto-de-estadc3adstica-descriptiva1Ejercicio resuelto-de-estadc3adstica-descriptiva1
Ejercicio resuelto-de-estadc3adstica-descriptiva1
Sandra Hernández Cely
 

What's hot (13)

QT1 - 06 - Normal Distribution
QT1 - 06 - Normal DistributionQT1 - 06 - Normal Distribution
QT1 - 06 - Normal Distribution
 
Mcqs (measures of dispersion)
Mcqs (measures of dispersion)Mcqs (measures of dispersion)
Mcqs (measures of dispersion)
 
Airthmetic mean
Airthmetic meanAirthmetic mean
Airthmetic mean
 
January 22, 2015
January 22, 2015January 22, 2015
January 22, 2015
 
Chapter7
Chapter7Chapter7
Chapter7
 
5.5 Point Slope and Standard Form
5.5 Point Slope and Standard Form5.5 Point Slope and Standard Form
5.5 Point Slope and Standard Form
 
Lecture 10.4 bt
Lecture 10.4 btLecture 10.4 bt
Lecture 10.4 bt
 
Proportionspowerpoint
ProportionspowerpointProportionspowerpoint
Proportionspowerpoint
 
Measures of Dispersion: Standard Deviation and Co- efficient of Variation
Measures of Dispersion: Standard Deviation and Co- efficient of Variation Measures of Dispersion: Standard Deviation and Co- efficient of Variation
Measures of Dispersion: Standard Deviation and Co- efficient of Variation
 
11.4 slope intercept form of a linear equation
11.4 slope intercept form of a linear equation11.4 slope intercept form of a linear equation
11.4 slope intercept form of a linear equation
 
How much time will be used for driving
How much time will be used for drivingHow much time will be used for driving
How much time will be used for driving
 
Final technology presentatio
Final technology presentatioFinal technology presentatio
Final technology presentatio
 
Ejercicio resuelto-de-estadc3adstica-descriptiva1
Ejercicio resuelto-de-estadc3adstica-descriptiva1Ejercicio resuelto-de-estadc3adstica-descriptiva1
Ejercicio resuelto-de-estadc3adstica-descriptiva1
 

Similar to Rajnifile

Semana7 dn
Semana7 dnSemana7 dn
Semana7 dn
Jorge Obando
 
Taxi for Professor Evans
Taxi for Professor EvansTaxi for Professor Evans
Taxi for Professor Evans
Anthony J. Evans
 
Trigo functions
Trigo functionsTrigo functions
Trigo functions
Sabariah Osman
 
Mathematics TAKS Exit Level Review
Mathematics TAKS Exit Level ReviewMathematics TAKS Exit Level Review
Mathematics TAKS Exit Level Review
guest3f17823
 
Regression
RegressionRegression
Random variables Report
Random variables ReportRandom variables Report
Random variables Report
Bahzad5
 
Math Exam Help
Math Exam HelpMath Exam Help
Math Exam Help
Live Exam Helper
 
CHAPTER TENObjectiveA brief introduction of the basic concept
CHAPTER TENObjectiveA brief introduction of the basic conceptCHAPTER TENObjectiveA brief introduction of the basic concept
CHAPTER TENObjectiveA brief introduction of the basic concept
TawnaDelatorrejs
 
Statistics for entrepreneurs
Statistics for entrepreneurs Statistics for entrepreneurs
Statistics for entrepreneurs
Dr. Trilok Kumar Jain
 
ML Module 3.pdf
ML Module 3.pdfML Module 3.pdf
ML Module 3.pdf
Shiwani Gupta
 
Math pi random sequence
Math pi random sequenceMath pi random sequence
Math pi random sequence
kaidora
 
Mca4020 probability and statistics
Mca4020  probability and statisticsMca4020  probability and statistics
Mca4020 probability and statistics
smumbahelp
 
simple linear regression - brief introduction
simple linear regression - brief introductionsimple linear regression - brief introduction
simple linear regression - brief introduction
edinyoka
 
Data Project 1-use a significance level of 0.05Companies in the Do.pdf
Data Project 1-use a significance level of 0.05Companies in the Do.pdfData Project 1-use a significance level of 0.05Companies in the Do.pdf
Data Project 1-use a significance level of 0.05Companies in the Do.pdf
tesmondday29076
 
Lecture 03 Inferential Statistics 1
Lecture 03 Inferential Statistics 1Lecture 03 Inferential Statistics 1
Lecture 03 Inferential Statistics 1
Riri Ariyanty
 
Different Types of Machine Learning Algorithms
Different Types of Machine Learning AlgorithmsDifferent Types of Machine Learning Algorithms
Different Types of Machine Learning Algorithms
rahmedraj93
 
C language numanal
C language numanalC language numanal
C language numanal
aluavi
 
슬로우캠퍼스: scikit-learn & 머신러닝 (강박사)
슬로우캠퍼스:  scikit-learn & 머신러닝 (강박사)슬로우캠퍼스:  scikit-learn & 머신러닝 (강박사)
슬로우캠퍼스: scikit-learn & 머신러닝 (강박사)
마이캠퍼스
 
Mca4020 probability and statistics
Mca4020  probability and statisticsMca4020  probability and statistics
Mca4020 probability and statistics
smumbahelp
 
Mca4020 probability and statistics
Mca4020  probability and statisticsMca4020  probability and statistics
Mca4020 probability and statistics
smumbahelp
 

Similar to Rajnifile (20)

Semana7 dn
Semana7 dnSemana7 dn
Semana7 dn
 
Taxi for Professor Evans
Taxi for Professor EvansTaxi for Professor Evans
Taxi for Professor Evans
 
Trigo functions
Trigo functionsTrigo functions
Trigo functions
 
Mathematics TAKS Exit Level Review
Mathematics TAKS Exit Level ReviewMathematics TAKS Exit Level Review
Mathematics TAKS Exit Level Review
 
Regression
RegressionRegression
Regression
 
Random variables Report
Random variables ReportRandom variables Report
Random variables Report
 
Math Exam Help
Math Exam HelpMath Exam Help
Math Exam Help
 
CHAPTER TENObjectiveA brief introduction of the basic concept
CHAPTER TENObjectiveA brief introduction of the basic conceptCHAPTER TENObjectiveA brief introduction of the basic concept
CHAPTER TENObjectiveA brief introduction of the basic concept
 
Statistics for entrepreneurs
Statistics for entrepreneurs Statistics for entrepreneurs
Statistics for entrepreneurs
 
ML Module 3.pdf
ML Module 3.pdfML Module 3.pdf
ML Module 3.pdf
 
Math pi random sequence
Math pi random sequenceMath pi random sequence
Math pi random sequence
 
Mca4020 probability and statistics
Mca4020  probability and statisticsMca4020  probability and statistics
Mca4020 probability and statistics
 
simple linear regression - brief introduction
simple linear regression - brief introductionsimple linear regression - brief introduction
simple linear regression - brief introduction
 
Data Project 1-use a significance level of 0.05Companies in the Do.pdf
Data Project 1-use a significance level of 0.05Companies in the Do.pdfData Project 1-use a significance level of 0.05Companies in the Do.pdf
Data Project 1-use a significance level of 0.05Companies in the Do.pdf
 
Lecture 03 Inferential Statistics 1
Lecture 03 Inferential Statistics 1Lecture 03 Inferential Statistics 1
Lecture 03 Inferential Statistics 1
 
Different Types of Machine Learning Algorithms
Different Types of Machine Learning AlgorithmsDifferent Types of Machine Learning Algorithms
Different Types of Machine Learning Algorithms
 
C language numanal
C language numanalC language numanal
C language numanal
 
슬로우캠퍼스: scikit-learn & 머신러닝 (강박사)
슬로우캠퍼스:  scikit-learn & 머신러닝 (강박사)슬로우캠퍼스:  scikit-learn & 머신러닝 (강박사)
슬로우캠퍼스: scikit-learn & 머신러닝 (강박사)
 
Mca4020 probability and statistics
Mca4020  probability and statisticsMca4020  probability and statistics
Mca4020 probability and statistics
 
Mca4020 probability and statistics
Mca4020  probability and statisticsMca4020  probability and statistics
Mca4020 probability and statistics
 

Rajnifile

  • 1. Experiment=1<br />A program to generate PDF of random number<br />clc<br />clear all<br />clf<br />n=input('enter the no.of random data');<br />y=rand(1,n);<br />t=0.1;<br />for i=1:10<br /> k=(y>t*(i-1)&y<t*i);<br /> b(i)=sum(k);<br /> x(i)=b(i)/(n*t);<br /> disp(x(i));<br />end<br />h=[.1 .2 .3 .4 .5 .6 .7 .8 .9 1]; <br />s=plot(h,x);<br />axis([0.1 1 0 7]);<br />ylabel('PDF');<br />xlabel('random no.');<br />title('PDF of random no.');<br />enter the no.of random data2000<br /> 1.0650<br /> 0.9550<br /> 0.9650<br /> 0.9950<br /> 1.0550<br /> 0.8950<br /> 1.0850<br /> 0.9200<br /> 1.0250<br /> 1.0400<br /> Experiment no. =2<br />Generation of random number using Linear Congruential Method<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />d=input('enter the value of modulus m in terms of small integer=');<br />m=input('enter the value of modulus m=')<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br /> <br />%%%% CASE-1ST %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of small integer<br /> <br />if c==0 && m==d<br /> disp('it is multiplicative congruential method');<br /> for i=1:m<br /> a=17;<br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers <br /> end<br /> <br />%%%% CASE-2ND %%%%%%<br />%when the value of increment is other than zero and the value of modulus is<br />%in terms of small integer<br /> <br />else if c~=0 && m==d<br /> disp('it is mixed congruential method');<br /> for i=1:m<br /> a=17;<br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers <br /> end<br /> <br />%%%% CASE-3RD %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of %modulus is in terms of 2^b<br /> <br /> else if c~=0 && m==2^b<br /> disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br /> Period= m %calculation of period <br /> a= 1+(4*k) %calculation of multiplier <br /> for i=1:m<br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers <br /> end<br /> <br />%%%% CASE-4TH %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br /> else if c==0 && m==2^b<br /> disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br /> a=3+(8*k) %calculation of multiplier <br /> Period= m/4 %calculation of period <br /> for i=1:m <br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers<br /> end<br /> end<br /> end<br /> end<br />end<br />disp(R); % displaying all the random numbers<br />Experiment =1<br />RESULT<br /> CASE-1ST<br />when the value of increment is equal to zero and the value of modulus is in terms of small integer<br />enter the value of seed X(1)=27<br />enter the value of increment c=0<br />enter the value of modulus m in terms of small integer=100<br />enter the value of modulus m=100<br />m =100<br />enter the value of b=6<br />enter the value of an integer k=1<br />it is multiplicative congruential method<br /> Columns 1 through 15 <br /> 0 0.5900 0.0300 0.5100 0.6700 0.3900 0.6300 0.7100 0.0700 0.1900 0.2300 0.9100 0.4700 0.9900 0.8300<br /> Columns 16 through 30 <br /> 0.1100 0.8700 0.7900 0.4300 0.3100 0.2700 0.5900 0.0300 0.5100 0.6700 0.3900 0.6300 0.7100 0.0700 0.1900<br /> Columns 31 through 45 <br /> 0.2300 0.9100 0.4700 0.9900 0.8300 0.1100 0.8700 0.7900 0.4300 0.3100 0.2700 0.5900 0.0300 0.5100 0.6700<br /> Columns 46 through 60 <br /> 0.3900 0.6300 0.7100 0.0700 0.1900 0.2300 0.9100 0.4700 0.9900 0.8300 0.1100 0.8700 0.7900 0.4300 0.3100<br /> Columns 61 through 75 <br /> 0.2700 0.5900 0.0300 0.5100 0.6700 0.3900 0.6300 0.7100 0.0700 0.1900 0.2300 0.9100 0.4700 0.9900 0.8300<br />Columns 76 through 90 <br /> 0.1100 0.8700 0.7900 0.4300 0.3100 0.2700 0.5900 0.0300 0.5100 0.6700 0.3900 0.6300 0.7100 0.0700 0.1900<br /> Columns 91 through 100 <br /> 0.2300 0.9100 0.4700 0.9900 0.8300 0.1100 0.8700 0.7900 0.4300 0.3100<br />CASE-2ND <br />when the value of increment is other than zero and the value of modulus is in terms of small integer<br />enter the value of seed X(1)=27<br />enter the value of increment c=43<br />enter the value of modulus m in terms of small integer=100<br />enter the value of modulus m=100<br />m = 100<br />enter the value of b=6<br />enter the value of an integer k=1<br />it is mixed congruential method<br /> <br /> Columns 1 through 15 <br /> 0 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700<br /> Columns 16 through 30 <br /> 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200<br /> Columns 31 through 45 <br /> 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700<br /> Columns 46 through 60 <br /> 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200<br /> Columns 61 through 75 <br /> 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700<br /> Columns 76 through 90 <br /> 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200<br /> Columns 91 through 100 <br /> 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200 0.2700 0.0200 0.7700 0.5200<br />CASE-3RD <br />when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is in terms of 2^b<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of modulus m in terms of small integer=100<br />enter the value of modulus m=64<br />m = 64<br />enter the value of b=6<br />enter the value of an integer k=1<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period =64<br />a = 5<br />Columns 1 through 15 <br /> 0 0.1250 0.6719 0.4063 0.0781 0.4375 0.2344 0.2188 0.1406 0.7500 0.7969 0.0313 0.2031 0.0625 0.3594<br /> Columns 16 through 30 <br /> 0.8438 0.2656 0.3750 0.9219 0.6563 0.3281 0.6875 0.4844 0.4688 0.3906 0 0.0469 0.2813 0.4531 0.3125<br /> Columns 31 through 45 <br /> 0.6094 0.0938 0.5156 0.6250 0.1719 0.9063 0.5781 0.9375 0.7344 0.7188 0.6406 0.2500 0.2969 0.5313 0.7031<br /> Columns 46 through 60 <br /> 0.5625 0.8594 0.3438 0.7656 0.8750 0.4219 0.1563 0.8281 0.1875 0.9844 0.9688 0.8906 0.5000 0.5469 0.7813<br /> Columns 61 through 64 <br /> 0.9531 0.8125 0.1094 0.5938<br />CASE-4TH<br />when the value of increment is equal to zero and the value of modulus is in terms of 2^b and the seed is an odd number<br />enter the value of seed X(1)=1<br />enter the value of increment c=0<br />enter the value of modulus m in terms of small integer=100<br />enter the value of modulus m=64<br />m = 64<br />enter the value of b=6<br />enter the value of an integer k=1<br />if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method<br />a =11<br />Period = 16<br />Columns 1 through 15 <br /> 0 0.1719 0.8906 0.7969 0.7656 0.4219 0.6406 0.0469 0.5156 0.6719 0.3906 0.2969 0.2656 0.9219 0.1406<br /> Columns 16 through 30 <br /> 0.5469 0.0156 0.1719 0.8906 0.7969 0.7656 0.4219 0.6406 0.0469 0.5156 0.6719 0.3906 0.2969 0.2656 0.9219<br /> Columns 31 through 45 <br /> 0.1406 0.5469 0.0156 0.1719 0.8906 0.7969 0.7656 0.4219 0.6406 0.0469 0.5156 0.6719 0.3906 0.2969 0.2656<br /> Columns 46 through 60 <br /> 0.9219 0.1406 0.5469 0.0156 0.1719 0.8906 0.7969 0.7656 0.4219 0.6406 0.0469 0.5156 0.6719 0.3906 0.2969<br /> Columns 61 through 64 <br /> 0.2656 0.9219 0.1406 0.5469<br />Experiment= 3<br />Kolmogorov-Smirnov test for uniformity of random numbers<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />Q=input('enter the specified significance level Q (it can be 0.10,0.05 or 0.01)=')<br />m=2^b %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br /> disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br /> Period= m %calculation of period <br /> a= 1+(4*k) %calculation of multiplier <br /> for i=1:m-1<br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> Y(i+1)=X(i+1)/m; %calculation of the random numbers <br /> end<br /> <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br /> else if c==0 && m==2^b<br /> disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br /> a=3+(8*k) %calculation of multiplier <br /> Period= m/4 %calculation of period <br /> for i=1:m-1 <br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> Y(i+1)=X(i+1)/m; %calculation of the random numbers<br /> end<br /> end<br />end<br /> <br />%step 2.) RANK THE DATA FROM SMALLEST TO LARGEST<br />R=sort(Y);<br />disp(R)<br />N= m %sample size <br />for i=1:m<br /> d1(i)= i/N-R(i);<br /> d2(i)=R(i)-(i-1)/N;<br />end<br /> <br />%step 3.) COMPUTATION OF LARGEST DEVIATION OF SN(x) ABOVE F(x)<br />D1 = max(d1) %largest deviation of SN(x) above F(x) <br /> <br />%step 4.) COMPUTATION OF LARGEST DEVIATION OF SN(x) BELOW F(x)<br />D2 = max(d2) %largest deviation of SN(x) below F(x)<br /> <br />%step 5.) COMPUTATION OF SAMPLE STATISTIC VALUE<br />D= max(D1,D2) %sample statistic <br /> <br />%step 6.) COMPUTATION OF CRITICAL SAMPLE STATISTIC VALUE<br />if Q==0.10<br /> p= 1.22/(N^(1/2));<br /> disp('the critical value DQ=') <br /> DQ=p %the critical sample statistic value <br />else if Q==0.05<br /> p= 1.36/(N^(1/2));<br /> disp('the critical value DQ=')<br /> DQ=p %the critical sample statistic value <br /> else if Q==0.01<br /> p= 1.63/(N^(1/2));<br /> disp('the critical value DQ=')<br /> DQ=p %the critical sample statistic value<br /> end <br /> end<br />end<br /> <br />%step 7.) DECISION FOR UNIFORM DISTRIBUTION<br />if D>DQ<br /> disp('the null hypothesis that the data are a sample form a unoform distribution is rejected or we can say that the random numbers generated are not uniformly distributed');<br />else<br /> disp('the test shows that no difference has been detected between the true distribution and the uniform distribution or we can say that the generated random numbers are uniformly distributed')<br />end <br />Experiment no. =3<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=6<br />enter the value of an integer k=1<br />enter the specified significance level Q (it can be 0.10,0.05 or 0.01)=0.05<br />Q = 0.0500<br />m = 64<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period = 64<br />a = 5<br />Columns 1 through 15 <br /> 0 0 0.0313 0.0469 0.0625 0.0781 0.0938 0.1094 0.1250 0.1406 0.1563 0.1719 0.1875 0.2031 0.2188<br /> Columns 16 through 30 <br /> 0.2344 0.2500 0.2656 0.2813 0.2969 0.3125 0.3281 0.3438 0.3594 0.3750 0.3906 0.4063 0.4219 0.4375 0.4531<br /> Columns 31 through 45 <br /> 0.4688 0.4844 0.5000 0.5156 0.5313 0.5469 0.5625 0.5781 0.5938 0.6094 0.6250 0.6406 0.6563 0.6719 0.6875<br /> Columns 46 through 60 <br /> 0.7031 0.7188 0.7344 0.7500 0.7656 0.7813 0.7969 0.8125 0.8281 0.8438 0.8594 0.8750 0.8906 0.9063 0.9219<br /> Columns 61 through 64 <br /> 0.9375 0.9531 0.9688 0.9844<br />N = 64<br />D1 = 0.0313<br />D2 = 0<br />D = 0.0313<br />the critical value DQ=<br />DQ = 0.1700<br />the test shows that no difference has been detected between the true distribution and the uniform distribution or we can say that the generated random numbers are uniformly distributed<br /> Experiment no. =4<br />Run test for testing the independence of generated random numbers<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />Q= 0.05 %enter the specified significance level Q <br />Z=1.96<br />m=2^b %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br /> disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br /> Period= m %calculation of period <br /> a= 1+(4*k) %calculation of multiplier <br /> for i=1:m-1<br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers <br /> end<br /> <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br /> else if c==0 && m==2^b<br /> disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br /> a=3+(8*k) %calculation of multiplier <br /> Period= m/4 %calculation of period <br /> for i=1:m-1 <br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers<br /> end<br /> end<br />end<br />S=sum(R) %sum of random numbers <br />N=length(R) %length of random numbers<br />M= S/N %mean of random numbers<br />n1=0; %n1=numbers of individual observations above the mean<br />n2=0; %n2=numbers of individual observations below the mean<br />for i=1:N<br /> if R(i)> M<br /> n1=n1+1;<br /> else n2=n2+1;<br /> end<br />end<br />disp('numbers of individual observations above the mean n1=');<br />disp(n1)<br />disp('numbers of individual observations below the mean n2=');<br />disp(n2)<br />mean=(2*n1*n2)/N+(1/2);<br />variance=2*n1*n2*(2*n1*n1-N)/(N^2*(N-1));<br />b=0;<br />for i=1:N-1<br /> if R(i)>M && R(i+1)<M<br /> b=b+1;<br /> else if R(i)<M && R(i+1)>M<br /> b=b+1;<br /> end<br /> end<br />end<br />disp('total no. of runs are b =')<br />disp(b)<br />Zo=(b-mean)/((variance)^(1/2))<br />if -Z<Zo<Z<br /> disp('Hypothesis of independence cannot be rejected on the basis of this test')<br />else<br /> disp('Hypothesis of independence is rejected on the basis of this test')<br />end <br /> <br />Experiment no.=4<br />RESULT<br />enter the value of seed X(1)=5<br />enter the value of increment c=7<br />enter the value of b=6<br />enter the value of an integer k=1<br />Q = 0.0500<br />Z = 1.9600<br />m = 64<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period = 64<br />a = 5<br />Columns 1 through 15 <br /> 0 0.5000 0.6094 0.1563 0.8906 0.5625 0.9219 0.7188 0.7031 0.6250 0.2344 0.2813 0.5156 0.6875 0.5469<br /> Columns 16 through 30 <br /> 0.8438 0.3281 0.7500 0.8594 0.4063 0.1406 0.8125 0.1719 0.9688 0.9531 0.8750 0.4844 0.5313 0.7656 0.9375<br /> Columns 31 through 45 <br /> 0.7969 0.0938 0.5781 0 0.1094 0.6563 0.3906 0.0625 0.4219 0.2188 0.2031 0.1250 0.7344 0.7813 0.0156<br /> Columns 46 through 60 <br /> 0.1875 0.0469 0.3438 0.8281 0.2500 0.3594 0.9063 0.6406 0.3125 0.6719 0.4688 0.4531 0.3750 0.9844 0.0313<br /> Columns 61 through 64 <br /> 0.2656 0.4375 0.2969 0.5938<br />S = 31.4219<br />N = 64<br />M = 0.4910<br />numbers of individual observations above the mean n1= 32<br />numbers of individual observations below the mean n2= 32<br />total no. of runs are b = 29<br />Zo = -0.8820<br />Hypothesis of independence cannot be rejected on the basis of this test<br />Experiment no.=5<br />Autocorrelation test<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />disp('at the specified significance level Q (it can be 0.10,0.05 or 0.01)=0.05')<br />Z=1.96<br />m=2^b %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br /> disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br /> Period= m %calculation of period <br /> a= 1+(4*k) %calculation of multiplier <br /> for i=1:m-1<br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers <br /> end<br /> <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br /> else if c==0 && m==2^b<br /> disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br /> a=3+(8*k) %calculation of multiplier <br /> Period= m/4 %calculation of period <br /> for i=1:m-1 <br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers<br /> end<br /> end<br />end<br />disp(R)<br />N=length(R)<br />i=input('enter the value of starting number=')<br />n=input('enter the value of lag=')<br />M= floor((N-i)/n-1)<br />for k=0:M<br /> b=R(i+k*n)*R(i+(k+1)*n);<br />end<br />c=sum(b)<br />Pin=((1/(M+1))*c)-0.25<br />S.D=(((13*M)+7)^(1/2))/(12*(M+1))<br />Zo=Pin/S.D<br />if -Z<Zo<Z<br /> disp('do not reject the null hypothesis of independence')<br />else <br /> disp('reject the null hyrothesis of independence')<br />end<br /> <br />Experiment no.=5<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=6<br />enter the value of an integer k=1<br />at the specified significance level Q (it can be 0.10,0.05 or 0.01)=0.05<br />Z =1.9600<br />m = 64<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period = 64<br />a = 5<br />Columns 1 through 15 <br /> 0 0.1250 0.6719 0.4063 0.0781 0.4375 0.2344 0.2188 0.1406 0.7500 0.7969 0.0313 0.2031 0.0625 0.3594<br /> Columns 16 through 30 <br /> 0.8438 0.2656 0.3750 0.9219 0.6563 0.3281 0.6875 0.4844 0.4688 0.3906 0 0.0469 0.2813 0.4531 0.3125<br /> Columns 31 through 45 <br /> 0.6094 0.0938 0.5156 0.6250 0.1719 0.9063 0.5781 0.9375 0.7344 0.7188 0.6406 0.2500 0.2969 0.5313 0.7031<br /> Columns 46 through 60 <br /> 0.5625 0.8594 0.3438 0.7656 0.8750 0.4219 0.1563 0.8281 0.1875 0.9844 0.9688 0.8906 0.5000 0.5469 0.7813<br /> Columns 61 through 64 <br /> 0.9531 0.8125 0.1094 0.5938<br />N = 64<br />enter the value of starting number=2<br />i = 2<br />enter the value of lag=5<br />n = 5<br />M = 11<br />c = 0.7236<br />Pin = -0.1897<br />S . D= 0.0851<br />Zo = -2.2304<br />do not reject the null hypothesis of independence<br /> <br />Experiment no.=6<br />Generation of exponential distributed random number<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />m=2^b %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br /> disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br /> Period= m %calculation of period <br /> a= 1+(4*k) %calculation of multiplier <br /> for i=1:m-1<br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers <br /> end<br /> <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br /> else if c==0 && m==2^b<br /> disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br /> a=3+(8*k) %calculation of multiplier <br /> Period= m/4 %calculation of period <br /> for i=1:m-1 <br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers<br /> end<br /> end<br />end<br />%disp(R)<br />N=length(R)<br />%inverse transform technique to sample from the exponential distribution<br />L=input('enter the value of mean number of occurences per unit time(L)=')<br />for i=1:N<br /> Y(i)=-(1/L)*log(1-R(i));<br />end<br />%disp(Y)<br />t=0.1;<br />for i=1:70<br /> k=(Y>t*(i-1)&Y<t*i);<br /> b(i)=sum(k);<br /> x(i)=b(i)/(N*t);<br /> %disp(x(i))<br />end<br />%disp(b);<br />d=0.1:0.1:7<br />plot(d,x)<br />axis([0.1 7 0 1]);<br />xlabel('random number');<br />ylabel('PDF');<br />title('PDF of exponentially distributed random numbers');<br />Experiment no.:-6<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=12<br />enter the value of an integer k=1<br />m = 4096<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period = 4096<br />a = 5<br />N = 4096<br />enter the value of mean number of occurences per unit time(L)=1<br />L = 1<br />Experiment no.:-7<br /> Generation of normal distributed random number<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />m=2^b %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br /> disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br /> Period= m %calculation of period <br /> a= 1+(4*k) %calculation of multiplier <br /> for i=1:m-1<br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers <br /> end<br /> <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br /> else if c==0 && m==2^b<br /> disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br /> a=3+(8*k) %calculation of multiplier <br /> Period= m/4 %calculation of period <br /> for i=1:m-1 <br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers<br /> end<br /> end<br />end<br />%disp(R)<br />N=length(R)<br />%Direct transformation method to generate normal distributed random no.<br />for i=1:m/2<br /> Z(2*i-1)=((-2*log(R(2*i-1)))^(1/2))*cos(2*pi*R(2*i));<br /> Z(2*i)=((-2*log(R(2*i-1)))^(1/2))*sin(2*pi*R(2*i));<br />end<br />u=8;<br />j=2;<br />disp('value of mean u is 8');<br />disp('value of varience j is 2');<br />for i=1:N<br /> Y(i)=u+(j^1/2)*Z(i);<br />end<br />%Plot of pdf of normal distributed random no.<br />t=0.1;<br />for i=1:120<br /> k=(Y>t*(i-1)&Y<t*i);<br /> b(i)=sum(k);<br /> x(i)=b(i)/(N*t);<br /> %disp(x(i));<br />end<br />h=0.1:0.1:12; <br />s=plot(h,x);<br />axis([4 12 0 2]);<br />ylabel('PDF');<br />xlabel('random no.');<br />title('PDF of normal distributed random no.');<br /> <br /> Experiment no.:-7<br />RESULT<br />enter the value of seed X(1)=254<br />enter the value of increment c=5<br />enter the value of b=15<br />enter the value of an integer k=11<br />m = 32768<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period = 32768<br />a = 45<br />N = 32768<br />value of mean u is 8<br />value of varience j is 2<br /> Experiment no.:-8<br />Generation of weibull distributed random number<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />m=2^b %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br /> disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br /> Period= m %calculation of period <br /> a= 1+(4*k) %calculation of multiplier <br /> for i=1:m-1<br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers <br /> end<br /> <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br /> else if c==0 && m==2^b<br /> disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br /> a=3+(8*k) %calculation of multiplier <br /> Period= m/4 %calculation of period <br /> for i=1:m-1 <br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers<br /> End <br /> end<br />end<br />%disp(R)<br />N=length(R)<br />%Inverse transform technique to generate weibull distributed random no.<br />a=input('enter the value of location parameter a=');<br />B=input('enter the value of scale parameter B=');<br />for i=1:m<br /> Y(i)=a*((-log(1-R(i)))^1/B);<br />end<br />%Plot of pdf of weibull distributed random no.<br />t=0.1;<br />for i=1:100<br /> k=(Y>t*(i-1)&Y<t*i);<br /> b(i)=sum(k);<br /> x(i)=b(i)/(N*t);<br /> %disp(x(i));<br />end<br />h=0.1:0.1:10; <br />s=plot(h,x);<br />axis([0 5 0 2]);<br />ylabel('PDF');<br />xlabel('random no.');<br />title('PDF of weibull distributed random no.');<br />Experiment no.:-8<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=15<br />enter the value of an integer k=1<br />m = 32768<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period = 32768<br />a = 5<br />N = 32768<br />enter the value of location parameter a=0.5<br />enter the value of scale parameter B=0.5<br />>><br />Experiment no.:-9<br />Generation of uniformly distributed random no. using CDF<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />m=2^b %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br /> disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br /> Period= m %calculation of period <br /> a= 1+(4*k) %calculation of multiplier <br /> for i=1:m-1<br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers <br /> end<br /> <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br /> else if c==0 && m==2^b<br /> disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br /> a=3+(8*k) %calculation of multiplier <br /> Period= m/4 %calculation of period <br /> for i=1:m-1 <br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers<br /> end<br /> end<br />end<br />%disp(R)<br />N=length(R)<br />%inverse transform technique to sample from the exponential distribution<br />disp(' the value lower limit of interval is a=3');<br />disp(' the value of upper limit of interval is b=7');<br />a=3;<br />b=7;<br />for i=1:N<br /> Y(i)=a+((b-a)*R(i));<br />end<br />%plot of pdf of uniformly distributed random no.in interval [a,b]<br />t=0.1;<br />for i=1:40<br /> k=Y>a+((i-1)*t)&Y<a+(t*i);<br /> b(i)=sum(k);<br /> x(i)=b(i)/(N*t);<br />end<br />h=3.1:0.1:7;<br />plot(h,x)<br />axis([1 9 0 0.5]);<br />xlabel('random no')<br />ylabel('PDF')<br />title('PDF of uniformly distributed random no. is [1/(b-a)=1/4=0.25]');<br /> <br />Experiment no.:-9<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=14<br />enter the value of an integer k=1<br />m = 16384<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period = 16384<br />a = 5<br />N = 16384<br /> the value lower limit of interval is a=3<br /> the value of upper limit of interval is b=7<br />Experiment no.:-10<br />Generation of triangular distributed random number using CDF<br />clc<br />clf<br />clear all<br />X(1)=input('enter the value of seed X(1)=');<br />c=input('enter the value of increment c=');<br />b=input('enter the value of b=');<br />k=input('enter the value of an integer k=');<br />m=2^b %value of modulus<br /> <br />% step 1.)GENERATION OF RANDOM NUMBERS USING LINEAR CONGRUENTIAL METHOD<br /> <br />%%%% CASE-first %%%%%%<br />%when the value of increment is other than zero and is relatively a prime number to m and the value of modulus is<br />%in terms of 2^b<br /> <br />if c~=0 && m==2^b<br /> disp('if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method');<br /> Period= m %calculation of period <br /> a= 1+(4*k) %calculation of multiplier <br /> for i=1:m-1<br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers <br /> end<br /> <br />%%%% CASE-second %%%%%%<br />%when the value of increment is equal to zero and the value of modulus is<br />%in terms of 2^b and the seed is an odd number<br /> <br /> else if c==0 && m==2^b<br /> disp('if X(1) is odd then the longest possible period is P = m/4=2^(b-2) and it is multiplicative congruential method');<br /> a=3+(8*k) %calculation of multiplier <br /> Period= m/4 %calculation of period <br /> for i=1:m-1 <br /> X(i+1)= mod((a*X(i)+c),m); %calculation of the random integers<br /> R(i+1)=X(i+1)/m; %calculation of the random numbers<br /> end<br /> end<br />end<br />%disp(R)<br />N=length(R)<br />%Inverse transform technique to generate trianguiar distributed random no.<br />for i=1:N<br /> if R(i)<=0.5<br /> Y(i)=(2*R(i))^(1/2);<br /> else<br /> Y(i)=(2-(2*(1-R(i)))^(1/2));<br /> end<br />end<br />t=0.1;<br />for i=1:21<br />k=Y>(i-1)*t & Y<i*t;<br />b(i)=sum(k);<br />x(i)=b(i)/(N*t);<br />end<br />h=0:0.1:2;<br />plot(h,x)<br />axis([0 2 0 2])<br />xlabel('random no.')<br />ylabel('PDF')<br />title('PDF of triangular distributed random no.')<br />Experiment no.:-10<br />RESULT<br />enter the value of seed X(1)=1<br />enter the value of increment c=3<br />enter the value of b=15<br />enter the value of an integer k=1<br />m =<br /> 32768<br />if c is relatively prime to m then the longest possible period is P = m=2^b and it is mixed congruential method<br />Period = 32768<br />a = 5<br />N = 32768<br /> Experiment no.=11<br />Generation of amplitude modulated waveform<br />clc<br />clear all<br />Vm=input('enter the value of amplitude of modulating signal=');<br />A=input('enter the value of amplitude of carrier signal=');<br />fm=input('enter the value of modulating frequency=');<br />fc=input('enter the value of carrier frequency=');<br />t=0:0.001:1;<br />x=Vm*cos(2*pi*fm*t); % modulating signal<br />%%%%%%%%%%%<br />subplot(4,1,1);<br />plot(t,x)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**modulating signal**');<br />c=A*cos(2*pi*fc*t); % carrier signal<br />%%%%%%%%%%<br />subplot(4,1,2);<br />plot(t,c)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**carrier signal**');<br />m=Vm/A;<br />s=(A*cos(2*pi*fc*t)).*(1+m.*cos(2*pi*fm*t)); % amplitude modulated signal<br />%%%%%%%%%%%%<br />subplot(4,1,3);<br />plot(t,s)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**amplitude modulated signal**');<br />y=c.*x; %DSB-SC signal <br />subplot(4,1,4);<br />plot(t,y)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**double side band supressed carrier signal**');<br /> <br />enter the value of amplitude of modulating signal=3<br />enter the value of amplitude of carrier signal=5<br />enter the value of modulating frequency=10<br />enter the value of carrier frequency=50<br />Experiment no.=12<br />Generation of frequency modulated wave<br />clc<br />clf<br />clear all<br />fm=input('enter the value of modulating frequency=');<br />fc=input('enter the value of carrier frequency=');<br />Vm=input('enter the value of amp of modulating signal=');<br />A=input('enter the valur of amp of carrier signal=');<br />mf=input('enter the value of modulating index=');<br />t=0:0.001:1;<br />x=Vm*cos(2*pi*fm*t); % modulating signal<br />%%%%%%%%%%%<br />subplot(3,1,1);<br />plot(t,x)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**modulating signal**');<br />%%%%%%%%%%%%%<br />c=A*cos(2*pi*fc*t); % carrier signal<br />subplot(3,1,2);<br />plot(t,c)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**carrier signal**');<br />%%%%%%%%%%%%%%<br />s=A*cos(2*pi*fc*t+mf*sin(2*pi*fm*t)); % frequency modulated signal<br />subplot(3,1,3);<br />plot(t,s)<br />xlabel('time(second)->');<br />ylabel('amplitude->');<br />title('**frequency modulated signal**');<br />enter the value of modulating frequency=10<br />enter the value of carrier frequency=50<br />enter the value of amp of modulating signal=4<br />enter the valur of amp of carrier signal=5<br />enter the value of modulating index=4<br />Experiment no.=13<br />Generation of phase modulated signal<br />clc<br />clear all<br />fm=input('enter the value of modulating frequency=');<br />fc=input('enter the value of carrier frequency=');<br />Vm=input('enter the value of amp of modulating signal=');<br />A=input('enter the valur of amp of carrier signal=');<br />mp=input('enter the value of modulating index=');<br />t=0:0.001:1;<br />x=Vm*cos(2*pi*fm*t); % modulating signal<br />%%%%%%%%%%%<br />subplot(3,1,1);<br />plot(t,x)<br />xlabel('time(second)');<br />ylabel('amplitude');<br />title('modulating signal');<br />%%%%%%%%%%%%<br />c=A*cos(2*pi*fc*t); % carrier signal<br />subplot(3,1,2);<br />plot(t,c)<br />xlabel('time(second)');<br />ylabel('amplitude');<br />title('carrier signal');<br />%%%%%%%%%%%%%%%%%<br />s=A*cos(2*pi*fc*t+mp*cos(2*pi*fm*t)); % phase modulated signal<br />subplot(3,1,3);<br />plot(t,s)<br />xlabel('time(second)');<br />ylabel('amplitude');<br />title('phase modulated signal');<br />enter the value of modulating frequency=10<br />enter the value of carrier frequency=50<br />enter the value of amp of modulating signal=4<br />enter the valur of amp of carrier signal=4<br />enter the value of modulating index=7<br />>><br />Experiment no.=14<br />Modulation and demodulation using amplitude shift keying<br />clc<br />clf<br />clear all<br />A=input('enter the value of carrier amplitude=');<br />n=input('enter the number of input data=');<br />x=rand(1,n);<br />%converting the signal( random num)into bipolar form<br />for i=1:10<br /> if(x(i)<0.5)<br /> y(i)=0;<br /> else y(i)=1;<br /> end<br />end<br />subplot(4,2,1); %plotting the input signal<br />stem(y);<br />axis([1 10 -1 1]);<br />title('**input signal**');<br />%plotting the carrier signal<br /> t=1:0.001:10;<br /> c=A*sin(2*pi*3*t);<br /> subplot(4,2,2);<br /> plot(t,c);<br /> xlabel('time->');<br /> ylabel('amplitude->');<br /> title('**carrier signal**');<br /> % plotting the ask signal<br /> for i=1:10<br /> t= i:0.001:(i+1);<br /> s=A*(sin(2*pi*3*t))*y(i);<br /> subplot(4,2,3);<br /> plot(t,s);<br /> hold on;<br /> axis([1 10 -5 5]);<br /> xlabel('time->');<br /> ylabel('amplitude');<br /> title('**ask modulated signal**');<br /> <br /> <br /> %sending modulated signal over awgn channel<br /> <br /> u=awgn(s,5,2);<br /> subplot(4,2,4);<br /> plot(t,u);<br /> hold on;<br /> axis([1 10 -10 10]);<br /> title('signal at reciever');<br /> xlabel('time-->');<br /> ylabel('amplitude');<br /> %operating recieved with LO<br /> recieved=sin(2*pi*3*t).*u; <br /> subplot(4,2,5);<br /> plot(t,recieved);<br /> hold on;<br /> axis([1 10 -10 10]);<br /> title('signal at reciever');<br /> xlabel('time-->');<br /> ylabel('amplitude');<br /> %applying integration on signal using successive summation approach<br /> v=1;<br /> w=sin(2*pi*3*t).*s;<br /> for t=i:0.001:(i+1);<br /> p(i)=sum(w(i:v));<br /> v=v+1;<br /> end<br /> v=1;<br /> subplot(4,2,6);<br /> for t=i:0.001:(i+1)<br /> m(i)=sum(recieved(i:v));<br /> plot(t,m(i));<br /> hold on<br /> v=v+1;<br /> end<br /> title('signal at reciever after integration');<br /> xlabel('time-->');<br /> ylabel('amplitude');<br /> end<br /> decision=max(p)/2;<br /> subplot(4,2,7);<br /> for i=1:10<br /> if m(i)>=decision<br /> y(i)=1;<br /> elseif m(i)< decision <br /> y(i)=0;<br /> end<br /> stem(y);<br /> axis([1 10 -1 1]);<br /> hold on;<br /> title('recieved data bits');<br /> end<br /> <br />RESULT (Experiment no.=14)<br />enter the value of carrier amplitude=5<br />enter the number of input data=10<br />>> <br /> <br />Experiment no.=15<br />Generation of Frequency Shift Keying<br />%Experiment-6<br />% Generation of frequency shift keying<br />clc<br />clear all<br />clf<br />fc=input('enter the value of carrier angular frequency=');<br />A=input('enter the value of carrier amplitude=');<br />n=input('enter the number of input data=');<br />x=rand(1,n);<br />%converting the signal(random num)into bipolar form<br />for i=1:n<br /> if(x(i)<0.5)<br /> y(i)=-1;<br /> else y(i)=1;<br /> end<br />end<br />%plotting the input signal<br />subplot(3,1,1);<br />stairs(y);<br />axis([1,10,-2,2]);<br />%plotting the carrier signal<br /> t=1:0.01:10;<br /> c=A*cos(2*pi*fc*t); %carrier signal<br /> subplot(3,1,2);<br /> plot(t,c);<br /> xlabel('time(second)->');<br /> ylabel('amplitude->');<br /> title('**carrier signal**');<br /> % plotting the fsk signal<br /> subplot(3,1,3);<br /> for t=1:9<br /> for i = t:0.01:t+1<br /> s=A*(cos(2*pi*(fc+2*y(t))*i)); %fsk modulated signal<br /> plot(i,s);<br /> hold on;<br /> xlabel('time(second)->');<br /> ylabel('amplitude');<br /> title('**fsk modulated signal**')<br /> end<br /> end<br />RESULT (Experiment no.=15)<br />enter the value of carrier angular frequency=5<br />enter the value of carrier amplitude=4<br />enter the number of input data=10<br />Experiment no.=16<br />Generation of Phase Shift Keying<br />clc<br />clf<br />clear all<br />fc=input('enter the value of carrier frequency=');<br />A=input('enter the value of carrier amplitude=');<br />n=input('enter the number of input data=');<br />x=rand(1,n);<br />%converting the signal(random num)into bipolar form<br />for i=1:10<br /> if(x(i)<0.5)<br /> y(i)=-1;<br /> else y(i)=1;<br /> end<br />end<br />%plotting the input signal<br />subplot(3,1,1);<br />stairs(y);<br />axis([1 10 -2 2])<br />title('**input signal**');<br />%plotting the carrier signal<br /> t=1:0.01:10;<br /> c=A*cos(2*pi*fc*t);<br /> subplot(3,1,2);<br /> plot(t,c);<br /> xlabel('time->');<br /> ylabel('amplitude->');<br /> title('**carrier signal**');<br /> % plotting the psk signal<br /> subplot(3,1,3);<br /> for t=1:10<br /> for i = t:.01:t+1<br /> s=4*y(t)*(cos(2*pi*fc*i));<br /> plot(i,s);<br /> xlabel('time->');<br /> ylabel('amplitude');<br /> title('**psk modulated signal**');<br /> hold on;<br /> end<br /> end<br /> <br />RESULT (Experiment no.=16)<br />enter the value of carrier frequency=5<br />enter the value of carrier amplitude=4<br />enter the number of input data=10<br />