Cours Formation Math Comm
Cours Formation Math Comm
Solutions provided by
Prof PRARTHAN MEHTA
Others
DHARMSINH DESAI UNIVERSITY
Contents
9 SIGNAL MODULATION 26
Experiment: 1
TRUNCATION OF A
SQUARE WAVE USING
FOURIER SERIES
EXPANTION
1 v=1;
// Frequency
2
3 t=0:0.001:0.99;
3
// Assigning of a Y−label of the figure
15 subplot(3 ,2, 2)
16 plot( x2);
// Plotting the First 3 components of the Fourier Series of a Square Wave
17 title( ’ Square Wave Contructed with First 3 Components of Fourier Series ’); //
Assigning a Title of the Figure 18 xlabel( ’ Samples ’) ;
4
// Plotting the First 6 components of the Fourier Series of a Square Wave
33 title( ’ Square Wave Contructed with First 6 Components of Fourier Series ’); //
Assigning a Title of the Figure 34 xlabel( ’ Samples ’) ;
Experiment: 2
ESTIMATION OF THE
ROOTS(ZEROS) FOR A
REAL VALUED FUNCTION
5
USING NEWTON-RAPHSON
METHOD
1
2
3 clear
4
5
6 function [y, deriv] = fcn_nr(x)
7 y = x^3 + 4*(x)^2 -10 ;
8 deriv = 3*(x)^2 + 8 *x;
9
10 endfunction
11
12 xp = -15:1:15 ;
13 n = length( xp);
14 for i=1:n
15 yp(i) = fcn_nr(xp(i));
16 end
17 plot( xp,yp )
18 xlabel( ’x ’)
19 ylabel( ’y ’)
20 title( ’ Plot of function ’)
21
22
23
24 x = input( ’ Enter i n i t i a l guess of root location : ’) ;
25
6
26 itermax = 10; // % max # of iterations
27 iter = 0;
28 errmax = 0.00001; // % convergence tolerance
29 error1 = 1;
30
31
32 while error1 > errmax & iter < itermax
33
34 iter = iter + 1 ;
35 [f fprime] = fcn_nr(x);
36 if fprime == 0
37 break;
38 end;
39
40 xnew = x - f / fprime;
41
42 error1 = abs((xnew - x)/xnew) * 100; // % find
change from previous
43
44 x = xnew // % set up for next iteration
45 disp( ’ Iteration No. ’)
46 disp( iter )
47 disp( ’ the estimated value of the variable x i s=’)
48 disp( x )
49
50
51 end
52
53 ///−−−−Input Parameters −−−−///
54
55 // This code will work for d i f f e r e n t functions of the
variable x. hence the user has to modify the
function & i t s derivative accordingly
56 // Itermax==>maximum number of i t e r a t i o n for which the method has
to estimate the value of the variable
57 //errmax==>maximun tolerable error
7
8
Experiment: 3
1 clear
2 clc
3
4 x=input( ’ enter the digital sequence ’) ;
// Input
the d i g i t a l
sequence 5 N=length( x);
9
18
19 //x==>d i g i t a l sequence for which DFT has to be found
1 clear
2 clc
3
4 x=input( ’ Enter the sequence : ’) ;
10
11
Experiment: 4
1
2 X=input( ’ Enter the Input data Sequence X[ n ] : ’) ;
3 H=input( ’ Enter the Response of the System H[ n ] : ’) ;
4
5 Y=conv(X,H);
6
7 disp( ’The response of the given system for the given inpur data sequence i s Y[ n
] : ’) ;
8 disp( Y);
9
10
11 //−−−Input Variables −−//
12 //X==>d i g i t a l sequence X[ n ]
13 //H==>f i l t e r impulse response H[ n ]
Experiment: 5
13
Scilab code Solution 5.2 Mesh Current
14
26
27 i=R*v;
28
29 disp( ’ the current through the loops=’)
30 disp( i )
31
32
33 //−−Input variables −−//
34 //v1==>voltage in loop 1−−constant
35 //v2==>voltage in loop 2−−constant
36 // r1==>resitance in loop 1 −− constant
37 // r2==>resitance in the common branch of loop1 & loop 2 −−constant
38 // r3==>resitance in loop 2 −− constant
Experiment: 6
STABILITY OF A
FEEDBACK SYSTEM IN
XCOS
This code can be downloaded from the website wwww.scilab.in This code
Experiment: 7
15
IMPLEMENTATION OF
CHANNEL CODING-LINEAR BLOCK
CODE
1
2
3 //% this is a linear block code main script file%
4 clear
5
6 global P n k;
7
8 n=7;
9 k=4;
10 P=[1 1 0; 0 1 1; 1 0 1;1 1 1]; //% parity matrix of size k∗(n−k) to be
11 // % selected so that the systematic generator
12 // % matrix islinearly independent or f u l l rank
13 // % matrix
14
15 //% (n , k) linear block code where k − no . of data bits and n−no input
. of o/p
16 //% data bits . code rate=k/n
17 //% x i s an input vector containing k bits
18
19 //%This i s an linear block encoding function file%
20 function y1=linblkcode(x);
21 global P n k;
22 n=7;
23 k=4;
16
24 P=[1 1 0; 0 1 1; 1 0 1;1 1 1] ;
25 //x=[0 1 1 0];
26
27 //G=[ ] ; // % Generator matrix k∗n
28 G=[eye(k,k) P];
29
30 y1=zeros(1 ,n);
31 for i=1:k
32 var(i,:)=x(1,i) & G(i,:);
33 var(i,:)=bool2s( var(i,:));
34 y1(1,:)=bitxor(var(i,:),y1(1,:));
35 end
36
37 endfunction
38
39
40 //%This is a linear block syndrome function
decoding
file%
41
42 function x1=linblkdecoder(y)
43 //% here y i s recieved vector 7 bits long
44
45 //% (7 ,4) linear block code
46 global P n k;
47
48
49 //H=[ ] ; //% PARITY CHECK MATRIX
50
51 H=[P’ eye(( n-k),(n-k))];
52 Ht=H’; // %transpose of H
53
54 S=zeros(1,n-k); //%syndrome of recieved vector x
55 for i=1:n-k
56 S(i)=y(1) & Ht(1,i);
57 S(i)=bool2s( S(i));
17
58 for j=2:n
59
60 S(i)=bitxor(S(i), bool2s((y(j) & Ht(j,i))));
61 end
62 end
63
64
65
66 //%%∗∗∗∗SYNDROME LOOK UP TABLE∗∗∗∗∗∗∗∗∗∗∗∗
67
68 //%%∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
69 //%
70 if S==[0 0 0]
71 e=[0 0 0 0 0 0 0] ;
72 z=bitxor(y,e);
73 end
74
75 if S==[0 0 1]
76 e=[0 0 0 0 0 0 1] ;
77 z=bitxor(y,e);
78 end
79 if S==[0 1 0]
80 e=[0 0 0 0 0 1 0] ;
81 z=bitxor(y,e);
82 end
83 if S==[1 0 0]
84 e=[0 0 0 0 1 0 0] ;
85 z=bitxor(y,e);
86 end
87 if S==[1 1 1]
88 e=[0 0 0 1 0 0 0] ;
89 z=bitxor(y,e);
90 end
91 if S==[1 0 1]
18
92 e=[0 0 1 0 0 0 0] ;
93 z=bitxor(y,e);
94 end
95 if S==[0 1 1]
96 e=[0 1 0 0 0 0 0] ;
97 z=bitxor(y,e);
98 end
99 if S==[1 1 0]
100 e=[1 0 0 0 0 0 0] ;
101 z=bitxor(y,e);
102 end
103
104
105
106
107 x1=z(1,1:k);
108 endfunction
109
110
111 x=[0 1 1 0]; // % input bits to the
encoder of size 1∗ k
112 y1=linblkcode(x);// // % y1 i s the output of linear block encoder
113
114
115 e1=[1 0 0 0 0 0 0]; // % intentionally
error introduced after
116 // % encoding and
before sending to decoder ( in
117 // % this case pls
introduce only one bit error )
118 y=bitxor(y1,e1);// % input that will
be made available to linear
119 // % block decoder
120
121 x1=linblkdecoder(y) // % x1 i s the output
19
of the linear block decoder
122 // % which will be same as x
provided that here
20
8
1
2
3
4
5 x=input( ’ Enter the input data sequence ’) ;
6 b=input( ’ Enter the co−e f f i t i e n t s for the numerator polynomial : ’) ;
7 a=input( ’ Enter the co−e f f i t i e n t s for the denominator polynomial : ’) ;
8
9 y=filter( b,a,x);
10
11
12 disp( ’The input signal i s=’)
13 disp( x )
14 disp( ’The f i l t e r e d signal i s=’)
15 disp( y )
16 //−−Input Variables −−//
17
18 //x==>input d i g i t a l sequence−−vector
21
Experiment:
19 //b==>vecotr
20 //a==>vector
22
9
SIGNAL MODULATION
1 function out_a=BPSK_a(bit,no_shift,shift)
2 if bit == 1
3 out_a = no_shift
4 else
5 out_a = shift
6 end
7
8 endfunction
9
10 t=0:0.001:1;
11 bit_1=0;
12
13 no_shift1=sin(2 *%pi*10*t);
14 shift1=sin(2 *%pi*10*t+(%pi));
15
16
17
18 out=BPSK_a(bit_1,no_shift1,shift1);
19 plot( t,out )
23
Experiment:
20
21 t1=1:0.001:2;
22 bit_2=1;
23
24 out1=BPSK_a(bit_2,no_shift1,shift1) ;
25 plot( t1,out 1)
26
27 xlabel( ’ time ’)
28 ylabel( ’ Amplitude ’)
29 //−−Input Variables
30 // bit 1 & bit 2==> d i g i t a l logic 1 or 0
24
10
APPLICATION OF LINEAR
ALGEBRA IN DIGITAL
COMMUNICATION
1 r1=[1 0] ;
2 r2=[0 1] ;
3 theta=input(”Enter the theta ( angle for rotation in radian
) : ”)
4 rotat=[cos(theta) sin(theta); -sin(theta) cos( theta ) ] ;
5
6 R=[r1 ; r2];
7
8 new_R=R*rotat;
9
10 rotated_r1=new_R(1,:);
11 rotated_r2=new_R(2,:);
12
13 disp( ’The vector r1==’)
14 disp( r 1)
25
Experiment:
26