From 7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 10 Oct 2017 12:27:19 +0530 Subject: initial commit / add all books --- 3812/CH4/EX4.1/4_1.sce | 66 ++++++++++++++++++++++++++++++++++++++++++++ 3812/CH4/EX4.12/4_12_b.sce | 21 ++++++++++++++ 3812/CH4/EX4.14.a/4_14_a.sce | 22 +++++++++++++++ 3812/CH4/EX4.2/4_2.sce | 23 +++++++++++++++ 3812/CH4/EX4.3/4_3.sce | 21 ++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 3812/CH4/EX4.1/4_1.sce create mode 100644 3812/CH4/EX4.12/4_12_b.sce create mode 100644 3812/CH4/EX4.14.a/4_14_a.sce create mode 100644 3812/CH4/EX4.2/4_2.sce create mode 100644 3812/CH4/EX4.3/4_3.sce (limited to '3812/CH4') diff --git a/3812/CH4/EX4.1/4_1.sce b/3812/CH4/EX4.1/4_1.sce new file mode 100644 index 000000000..6afc7b735 --- /dev/null +++ b/3812/CH4/EX4.1/4_1.sce @@ -0,0 +1,66 @@ +//example 4_1 +//determine the fourier series coefficient of the signal plot its magnitude and phase spectrum +clear; +close; +clc; +N = 10; +n = 0:0.01:N; +Wo = 2*%pi/N; +xn =ones(1,length(n))+sin(Wo*n)+3*cos(Wo*n)+cos(2*Wo*n+%pi/2); +for k =0:N-2 + C(k+1,:) = exp(-sqrt(-1)*Wo*n.*k); + a(k+1) = xn*C(k+1,:)'/length(n); + if(abs(a(k+1))<=0.1) + a(k+1)=0; + end +end +a =a'; +a_conj =conj(a); +ak = [a_conj($:-1:1),a(2:$)]; +Mag_ak = abs(ak); +for i = 1:length(a) + Phase_ak(i) = atan(imag(ak(i))/(real(ak(i))+0.0001)); +end +Phase_ak = Phase_ak' +Phase_ak = [Phase_ak(1:$-1) -Phase_ak($:-1:1)]; +k = -(N-2):(N-2); +// +figure +subplot(2,1,1) +a = gca(); +a.y_location = "origin"; +a.x_location = "origin"; +plot2d3('gnn',k,real(ak),5) +poly1 = a.children(1).children(1); +poly1.thickness = 3; +title('Real part of(ak)') +xlabel(' k') +subplot(2,1,2) +a = gca(); +a.y_location = "origin"; +a.x_location = "origin"; +plot2d3('gnn',k,imag(ak),5) +poly1 = a.children(1).children(1); +poly1.thickness = 3; +title('imaginary part of(ak)') +xlabel(' k') +// +figure +subplot(2,1,1) +a = gca(); +a.y_location = "origin"; +a.x_location = "origin"; +plot2d3('gnn',k,Mag_ak,5) +poly1 = a.children(1).children(1); +poly1.thickness = 3; +title('abs(ak)') +xlabel(' k') +subplot(2,1,2) +a = gca(); +a.y_location = "origin"; +a.x_location = "origin"; +plot2d3('gnn',k,Phase_ak,5) +poly1 = a.children(1).children(1); +poly1.thickness = 3; +title('<(ak)') +xlabel(' k') diff --git a/3812/CH4/EX4.12/4_12_b.sce b/3812/CH4/EX4.12/4_12_b.sce new file mode 100644 index 000000000..84a6c32e5 --- /dev/null +++ b/3812/CH4/EX4.12/4_12_b.sce @@ -0,0 +1,21 @@ +//Example 4_12_b +clc; +clear; +N=8; +n=0:0.01:N; +Wo=3*%pi/N; +xn=1*ones(1,length(n))+1*sin(Wo*n+%pi/4); +for k=0:N-2 +C(k+1,:)=exp(-sqrt(-1)*Wo*n.*k); +a(k+1)=xn*C(k+1,:)'/length(n); +if(abs(a(k+1))<=0.1) +a(k+1)=0; +end +end +a=a'; +a_conj=conj(a); +ak=[a_conj($:-1:1),a(2:$)]; +Mag_ak=abs(ak); +k=-(N-2):(N-2); +plot2d3('gnn',k,Mag_ak,5) +xtitle('abs(ak)','k','ak') diff --git a/3812/CH4/EX4.14.a/4_14_a.sce b/3812/CH4/EX4.14.a/4_14_a.sce new file mode 100644 index 000000000..8f810210f --- /dev/null +++ b/3812/CH4/EX4.14.a/4_14_a.sce @@ -0,0 +1,22 @@ +//Example 4_14_a +//determine the fourier series coeffient of x(n) +clc; +clear; +N=6; +n=0:0.01:N; +Wo=2*%pi/N; +xn=1*ones(1,length(n))+1*cos(Wo*n); +for k=0:N-2 +C(k+1,:)=exp(-sqrt(-1)*Wo*n.*k); +a(k+1)=xn*C(k+1,:)'/length(n); +if(abs(a(k+1))<=0.1) +a(k+1)=0; +end +end +a=a'; +a_conj=conj(a); +ak=[a_conj($:-1:1),a(2:$)]; +Mag_ak=abs(ak); +k=-(N-2):(N-2); +plot2d3('gnn',k,Mag_ak,5) +xtitle('abs(ak)','k','ak') diff --git a/3812/CH4/EX4.2/4_2.sce b/3812/CH4/EX4.2/4_2.sce new file mode 100644 index 000000000..ed0048742 --- /dev/null +++ b/3812/CH4/EX4.2/4_2.sce @@ -0,0 +1,23 @@ +//Example 4_2 +//Finad DTFS coefficients of periodic square wave +clc; +clear; +N=10; +N1=2; +Wo=2*%pi/N; +xn=ones(1,length(N)); +n=-(2*N1+1):(2*N1+1); +a(1)=(2*N1+1)/N; +for k=1:2*N1 +a(k+1)=sin((2*%pi*k*(N1+0.5))/N)/sin(%pi*k/N); +a(k+1)=a(k+1)/N; +if(abs(a(k+1))<=0.1) +a(k+1)=0; +end +end +a=a'; +a_conj=conj(a); +ak=[a_conj($:-1:1),a(2:$)]; +k=-2*N1:2*N1; +plot2d3('gnn',k,abs(ak)) +xtitle('Magnitude spectrum','k','jakj') diff --git a/3812/CH4/EX4.3/4_3.sce b/3812/CH4/EX4.3/4_3.sce new file mode 100644 index 000000000..bc17d1e5e --- /dev/null +++ b/3812/CH4/EX4.3/4_3.sce @@ -0,0 +1,21 @@ +//Example 4_3 +//Discrete Time Fourier Transform coefficient of Periodic Impulse Train +clc; +clear; +N=5; +N1=-3*N:3*N; +xn=[zeros(1,N-1),1]; +x=[1 xn xn xn xn xn xn ]; +ak=1/N; +XW=2*%pi*ak*ones(1,2*N); +Wo=2*%pi/N; +n=-N:N-1; +W=Wo*n; +figure +subplot(2,1,1) +plot2d3('gnn',N1,x,2); +xtitle('Periodic Impulse Train','n','x[n]') +subplot(2,1,2) +plot2d3('gnn',W,XW,2); +xtitle('DTFT of Periodic Impulse Train','w','jX(exp(jw))j') +disp(Wo) -- cgit