diff options
Diffstat (limited to '692/CH2')
-rwxr-xr-x | 692/CH2/EX2.1/P2_1.sce | 28 | ||||
-rwxr-xr-x | 692/CH2/EX2.16/P2_16.sce | 18 | ||||
-rwxr-xr-x | 692/CH2/EX2.2/P2_2.sce | 13 | ||||
-rwxr-xr-x | 692/CH2/EX2.20/P2_20.sce | 20 | ||||
-rwxr-xr-x | 692/CH2/EX2.22/P2_22.sce | 25 | ||||
-rwxr-xr-x | 692/CH2/EX2.26/P2_26.sce | 8 | ||||
-rwxr-xr-x | 692/CH2/EX2.27/P2_27.sce | 27 | ||||
-rwxr-xr-x | 692/CH2/EX2.28/P2_28.sce | 20 | ||||
-rwxr-xr-x | 692/CH2/EX2.29/P2_29.sce | 24 | ||||
-rwxr-xr-x | 692/CH2/EX2.3/P2_3.sce | 18 | ||||
-rwxr-xr-x | 692/CH2/EX2.30/P2_30.sce | 33 | ||||
-rwxr-xr-x | 692/CH2/EX2.31/P2_31.sce | 22 | ||||
-rwxr-xr-x | 692/CH2/EX2.32/P2_32.sce | 21 | ||||
-rwxr-xr-x | 692/CH2/EX2.33/P2_33.sce | 23 | ||||
-rwxr-xr-x | 692/CH2/EX2.46/P2_46.sce | 12 | ||||
-rwxr-xr-x | 692/CH2/EX2.5/P2_5.sce | 16 | ||||
-rwxr-xr-x | 692/CH2/EX2.6/P2_6.sce | 32 | ||||
-rwxr-xr-x | 692/CH2/EX2.7/P2_7.sce | 18 | ||||
-rwxr-xr-x | 692/CH2/EX2.9/P2_9.sce | 17 |
19 files changed, 395 insertions, 0 deletions
diff --git a/692/CH2/EX2.1/P2_1.sce b/692/CH2/EX2.1/P2_1.sce new file mode 100755 index 000000000..b174a1237 --- /dev/null +++ b/692/CH2/EX2.1/P2_1.sce @@ -0,0 +1,28 @@ +//EXAMPLE 2.1 +//Ensemble averaging +clear ; +clc ; +n = 1:50; +clf(); +figure(0) +a=gca(); +a.x_location="origin"; +a.y_location="origin"; + for i =1:length(n) + s(i)=2*n(i)*((0.9)^n(i)); + d(i)=(-0.1)^n(i); //arbitrary noise signal. + end + +M=length(n); + + for i =1:M + d(i)=(-0.1)^i; + S=sum(d); + end +Eav=(s+S/M)'; //Ensemble average. +disp(Eav,'The output of Ensemble averaging is') +plot2d3(n,s) +plot(n,s,'r.') +xtitle('Ensemble averaging','n','Eav-s'); +a.children.children.thickness=2; +a.children.children.foreground=2; diff --git a/692/CH2/EX2.16/P2_16.sce b/692/CH2/EX2.16/P2_16.sce new file mode 100755 index 000000000..8beec2006 --- /dev/null +++ b/692/CH2/EX2.16/P2_16.sce @@ -0,0 +1,18 @@ +//EXAMPLE 2.16, +clear; +clc; +//Given input sequence = [3 4 5] +x=[0 3 4 5 0]; +disp([3 4 5],'Input sequence = ') +//determining median filter +//first sequence +for k=2:4 + if x(k)>x(k-1) & x(k+1)>x(k-1) & x(k+1)>x(k) + y(k-1)=x(k); + else + x(k-1)>x(k+1) & x(k)>x(k+1) & x(k)>x(k-1) + y(k-1)=x(k-1); + end +end +disp(y','The Median Filter of the given input is ='); + diff --git a/692/CH2/EX2.2/P2_2.sce b/692/CH2/EX2.2/P2_2.sce new file mode 100755 index 000000000..aeffc0e8d --- /dev/null +++ b/692/CH2/EX2.2/P2_2.sce @@ -0,0 +1,13 @@ +//EXAMPLE 2.2 , BASIC OPERATIONS. +clear; +clc; +c=[3.2 41 36 -9.5 0]; +disp(c,'c = '); +d=[1.7 -0.5 0 0.8 1]; +disp(d,'d = '); +w1=c.*d; //Multiplication +disp(w1,'The product of two input vectors is ='); +w2=c+d; //addition +disp(w2,'The addition of two input vectors is ='); +w3=3.5*c; +disp(w3,'The scaling of first input vector is ='); diff --git a/692/CH2/EX2.20/P2_20.sce b/692/CH2/EX2.20/P2_20.sce new file mode 100755 index 000000000..0a63db736 --- /dev/null +++ b/692/CH2/EX2.20/P2_20.sce @@ -0,0 +1,20 @@ +//EXAMPLE 2.20,Passive or lossless system. +clear; +clc; +a=input("any value of a less than or equal to one") +n=-10:1:10; + x=n; + y=a*n; + S=0; + for i=1:length(n) + S=S+y^2; + end + + if a<1 then + disp('the system is passive') + else + + a==1 + disp('the system is lossless') + + end diff --git a/692/CH2/EX2.22/P2_22.sce b/692/CH2/EX2.22/P2_22.sce new file mode 100755 index 000000000..035d20a81 --- /dev/null +++ b/692/CH2/EX2.22/P2_22.sce @@ -0,0 +1,25 @@ +//EXAMPLE 2.22,impulse response of accumulator + +clear; +clc; +d=[1]; +t=-1:.01:1; +h=0; +clf(); +figure(0); +a=gca(); +a.x_location="origin"; + +for i=1:length(t) + if t(i)<0 + h=0; + else + h=d; + plot2d3(i-101,h) + plot(i-101,h,'.r') + xtitle('Impulse Response of accumulator','t','Y'); + a.children.children.thickness=1; + a.children.children.foreground=2; + end +end +disp(h,'The impulse response of Accumulator is =') diff --git a/692/CH2/EX2.26/P2_26.sce b/692/CH2/EX2.26/P2_26.sce new file mode 100755 index 000000000..5e434a00e --- /dev/null +++ b/692/CH2/EX2.26/P2_26.sce @@ -0,0 +1,8 @@ +//EXAMPLE 2.26,convolution of x & h +x=[-2 0 1 -1 3]; +disp(x,'x = '); +h=[1 2 0 -1]; +disp(h,'h = '); +n=0:7; +y=convol(x,h); +disp(y,'The convolution of the two inputs is :') diff --git a/692/CH2/EX2.27/P2_27.sce b/692/CH2/EX2.27/P2_27.sce new file mode 100755 index 000000000..259469051 --- /dev/null +++ b/692/CH2/EX2.27/P2_27.sce @@ -0,0 +1,27 @@ +//EXAMPLE 2.27, convolution of an exponential sequence +clear; +clc; +n=0:.5:5 +c=0.5; +b=0.4; +clf(); +figure(0); +a=gca(); +a.x_location="origin"; +x = c^n; +subplot(2,2,1); +plot2d3(n,x,2); +plot(n,x,'.r'); +xtitle('','n','x'); +h = b^n ; +subplot(2,2,2); +plot2d3(n,h,2) +plot(n,h,'.r') +xtitle('','n','h'); +N=0:.5:10; +y = convol (x , h ); +subplot(2,2,3); +plot2d3(N,y,2) +plot(N,y,'.r') +xtitle('convol(x,h)' ,'n','y'); +disp(y,'Convolution of the two exponential sequences is =')
\ No newline at end of file diff --git a/692/CH2/EX2.28/P2_28.sce b/692/CH2/EX2.28/P2_28.sce new file mode 100755 index 000000000..d90addf12 --- /dev/null +++ b/692/CH2/EX2.28/P2_28.sce @@ -0,0 +1,20 @@ +//EXAMPLE 2.28,graphical representation of convolution of x & h. +clear; +clc; +x=[-2 0 1 -1 3]; +disp(x,'x'); +h=[1 2 0 -1]; +disp(h,'h'); +n=0:7; +y=convol(x,h); +disp(y,'convolution = '); +clf(); +figure(0); +a=gca(); +a.x_location="origin"; +a.y_location="origin"; +plot2d3(n,y) +plot(n,y,'r.') +xtitle('convolution','n','Y'); +a.children.children.thickness=2; +a.children.children.foreground=2; diff --git a/692/CH2/EX2.29/P2_29.sce b/692/CH2/EX2.29/P2_29.sce new file mode 100755 index 000000000..fc59af2a4 --- /dev/null +++ b/692/CH2/EX2.29/P2_29.sce @@ -0,0 +1,24 @@ +//Example 2.29,Convolution using Tabular method. +clear; +clc; +x=[-2 0 1 -1 3]; +h=[1 2 0 -1]; +q=length(x); +w=length(h); +z=q+w-1; +y0=0; +for i=1:z; + y(i)=0; + for k=1:i; + if k>q + x(k)=0; + else + if (i-k+1)>w + h(i-k+1)=0; + else + y(i)= y(i) + x(k)*h(i-k+1); + end + end + end +end +disp(y','The Convolution of the two sequences is =') diff --git a/692/CH2/EX2.3/P2_3.sce b/692/CH2/EX2.3/P2_3.sce new file mode 100755 index 000000000..2bde6f5ad --- /dev/null +++ b/692/CH2/EX2.3/P2_3.sce @@ -0,0 +1,18 @@ +//EXAMPLE 2.3, Basic ops on unequal length sequence +clear; +clc; +c=[3.2 41 36 -9.5 0]; +disp(c,'c = '); +g=[-21 1.5 3]; +disp(g,'g = '); +a=length(g); +b=length(c); +i=0; + while(i<b-a) + g(b-i)=0; + i=i+1; + end +w4=g.*c; +disp(w4,'The product of two sequences is ='); +w5=c+g; +disp(w5,'The addition of two sequences is ='); diff --git a/692/CH2/EX2.30/P2_30.sce b/692/CH2/EX2.30/P2_30.sce new file mode 100755 index 000000000..121266d91 --- /dev/null +++ b/692/CH2/EX2.30/P2_30.sce @@ -0,0 +1,33 @@ +//EXAMPLE 2.30 +//Convolution of two sided sequences +clear; +clc; +g=[3 -2 4];//originating at n=-1 +h=[4 2 -1];//originating at n=0 +q=length(g); +w=length(h); +z=q+w-1; +y0=0; +for i=1:z; + y(i)=0; + for k=1:i; + if k>q + g(k)=0; + else + if (i-k+1)>w + h(i-k+1)=0; + else + y(i)= y(i) + g(k)*h(i-k+1); + end + end + end +end +n=-1:z-2; +disp(y,'The Convolution of the two sequences is =') +clf(); +a=gca(); +figure(0); +a.x_location="origin"; +plot2d3(n,y,2); +plot(n,y,'r.'); +xtitle('convolution','n','y'); diff --git a/692/CH2/EX2.31/P2_31.sce b/692/CH2/EX2.31/P2_31.sce new file mode 100755 index 000000000..f596eea0c --- /dev/null +++ b/692/CH2/EX2.31/P2_31.sce @@ -0,0 +1,22 @@ +//EXAMPLE 2.31, Stability for causal system. +//h[i]=impulse response of LTI system. +clear; +clc; +n= -5:0.001:5; +a=0.6; + +for i=1:length(n) + if (n(i)<0) + h(i)=0; + else + h(i)=abs(a^n(i)); + + end +end +S=sum(h); +if(S<%inf) + disp('BIBO stable system'); +else + disp('BIBO unstable system'); + +end diff --git a/692/CH2/EX2.32/P2_32.sce b/692/CH2/EX2.32/P2_32.sce new file mode 100755 index 000000000..1328e312c --- /dev/null +++ b/692/CH2/EX2.32/P2_32.sce @@ -0,0 +1,21 @@ +//EXAMPLE2.32 Stability for anti-Causal system. +//h[i]=impulse response of LTI system. +clear; +clc; +n= -5:1/1000:5; +a=5; +for i=1:length(n) + if (n(i)>-1) + h(i)=0; + else + h(i)=a^n(i); + S=sum(h); + end +end + +if(S<%inf) + disp('BIBO stable system'); +else + disp('BIBO unstable system'); + +end diff --git a/692/CH2/EX2.33/P2_33.sce b/692/CH2/EX2.33/P2_33.sce new file mode 100755 index 000000000..078908a6c --- /dev/null +++ b/692/CH2/EX2.33/P2_33.sce @@ -0,0 +1,23 @@ +//EXAMPLE 2.33 ,stability of finite impulse response. +//h[i]=impulse response of LTI system. +clear; +clc; +n= -5:1/100:5; +a= input('value of a'); +N1=input('lower limit'); +N2=input('upper limit'); +for i=1:length(a) + if (n(i)<N1 & n(i)>N2) + h(i)=0; + else + h(i)=a^n(i); + S=sum(h); + end +end + +if(S<%inf) + disp('BIBO stable system'); //as long as N1,N2!=%inf +else + disp('BIBO unstable system'); + +end diff --git a/692/CH2/EX2.46/P2_46.sce b/692/CH2/EX2.46/P2_46.sce new file mode 100755 index 000000000..384771268 --- /dev/null +++ b/692/CH2/EX2.46/P2_46.sce @@ -0,0 +1,12 @@ +//EXAMPLE 2.46, Cross corelation Computation. +// Given two finite length sequence.x[n],y[n]: +clear; +clc; +x=[1 3 -2 1 2 -1 4 4 2]; +disp(x,'x'); +y=[2 -1 4 1 -2 3]; +disp(y,'y'); +//Cross corelation rxy[n]: + +rxy=convol(x,mtlb_fliplr(y)); +disp(rxy,'The Cross-Corelation Operation of the Inputs is =') diff --git a/692/CH2/EX2.5/P2_5.sce b/692/CH2/EX2.5/P2_5.sce new file mode 100755 index 000000000..a1a3b05cc --- /dev/null +++ b/692/CH2/EX2.5/P2_5.sce @@ -0,0 +1,16 @@ +//EXAMPLE 2.5,Conjugate-Antisymmetric & Conjugate-symmetric parts of Sequence +clc; +clear; +g=[0, 1+%i*4, -2+%i*3, 4-%i*2, -5-%i*6, -%i*2, 3]; +disp(g,'g = ') +g1=conj(g); //Conjugate of g; +disp(g1,conj(g)); +a=length(g); +for i=1:a + g2(1,i)=g1(a-i+1); +end + +gcs=(g+g2)/2 //Conjugate-Symmetric part +disp(gcs,'The Conjugate symmetric part is ='); +gcas=(g-g2)/2; //Conjugate-Antisymmetric part +disp(gcas,'The Conjugate antisymmetric part is =');
\ No newline at end of file diff --git a/692/CH2/EX2.6/P2_6.sce b/692/CH2/EX2.6/P2_6.sce new file mode 100755 index 000000000..6b612e905 --- /dev/null +++ b/692/CH2/EX2.6/P2_6.sce @@ -0,0 +1,32 @@ +//EXAMPLE 2.6, Energy Signal + +clear ; +clc ; +n = -5:5; +for i =1:length ( n ) + if(n(i)>=1) + h(i)=1/n(i); + else + h(i)=0; + end +end + +Sum=0; +N=1:10000; + for i=1:length(N) + h(i)=(1/N(i))^2; + end + +Energy = sum(h); + + if (Energy<%inf ) then + disp ('Energy Signal') ; + disp(Energy,'Energy of signal = '); + else + if (Energy/length(N)<%inf ) then + disp ('Power Signal') ; + + else + disp ('Niether Energy nor Power Signal') ; + end + end diff --git a/692/CH2/EX2.7/P2_7.sce b/692/CH2/EX2.7/P2_7.sce new file mode 100755 index 000000000..a20487216 --- /dev/null +++ b/692/CH2/EX2.7/P2_7.sce @@ -0,0 +1,18 @@ +//EXAMPLE 2.7,Example of Power signal +clear ; +clc ; + +Sum=0; +N=1:10000; + for i=1:length(N) + h1= 3*((-1)^i); + h=h1^2; + end + +Energy = sum(h); + if (Energy/(2*(length(N))+1)<%inf ) then + disp ('Power Signal') ; + disp(Energy/2,'Power Signal = '); + else + disp ('Not a Power Signal') ; + end diff --git a/692/CH2/EX2.9/P2_9.sce b/692/CH2/EX2.9/P2_9.sce new file mode 100755 index 000000000..ecba03118 --- /dev/null +++ b/692/CH2/EX2.9/P2_9.sce @@ -0,0 +1,17 @@ +//EXAMPLE 2.9, Generation of a Square wave sequence: +clc; +clear; +clf(); +a=gca(); +figure(0); +a.x_location="origin"; +x=[0:1:80]; +y1=sin(x*.05*%pi); +y2=sin(x*.15*%pi); +y3=sin(x*.25*%pi); +y4=y1+y2/3+y3/5; +plot2d3(x,y4,2) +plot(x,y4,'r.') +xtitle('Approximate Square wave','x','y4'); +a.children.children.thickness=3; + |