PDF of Lab Solutions

Scilab Manual for
Applied Mathematics for Communication
Engineers
by Prof Prarthan Mehta
Others
Dharmsinh Desai University1
Solutions provided by
Prof PRARTHAN MEHTA
Others
DHARMSINH DESAI UNIVERSITY
June 17, 2017
1 Funded
by a grant from the National Mission on Education through ICT,
http://spoken-tutorial.org/NMEICT-Intro. This Scilab Manual and Scilab codes
written in it can be downloaded from the ”Migrated Labs” section at the website
http://scilab.in
1
Contents
List of Scilab Solutions
3
1 TRUNCATION OF A SQUARE WAVE USING FOURIER
SERIES EXPANTION
4
2 ESTIMATION OF THE ROOTS(ZEROS) FOR A REAL
VALUED FUNCTION USING NEWTON-RAPHSON METHOD
3 DFT & IDFT OF A GIVEN SEQUENCE
11
4 SYSTEM RESPONSE USING CONVOLUTION
14
5 NODE VOLTAGE & MESH CURRENT ANALYSIS
15
6 STABILITY OF A FEEDBACK SYSTEM IN XCOS
18
7 IMPLEMENTATION OF CHANNEL CODING-LINEAR
BLOCK CODE
19
8 FILTER DESIGN USING LAPLACE TRANSFORM
24
9 SIGNAL MODULATION
26
10 APPLICATION OF LINEAR ALGEBRA IN DIGITAL COMMUNICATION
28
2
8
List of Experiments
Solution 1.1Truncation of the Square Wave . . .
Solution 2.1Estimation or Roots . . . . . . . . .
Solution 3.1DFT of a Given Sequence . . . . . .
Solution 3.2IDFT of the given responce . . . . .
Solution 4.1System Response using Convolution
Solution 5.1Node Voltage . . . . . . . . . . . . .
Solution 5.2Mesh Current . . . . . . . . . . . . .
Solution 7.1Linear Block Coder Decoder . . . .
Solution 8.1Filter Design . . . . . . . . . . . . .
Solution 9.1BPSK . . . . . . . . . . . . . . . . .
Solution 10.1
Rotation of a Vector . . . . . . . . .
3
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4
8
11
12
14
15
16
19
24
26
28
Experiment: 1
TRUNCATION OF A
SQUARE WAVE USING
FOURIER SERIES
EXPANTION
Scilab code Solution 1.1 Truncation of the Square Wave
1 v =1;
// M u l t i p l i e r V o l t a g e
2 w =15;
// F r e q u e n c y
3 t =0:0.001:0.99;
// I n c r e m e n t a l Time Stamp
4 x1 = v *( cos ( w * t ) - cos (3* w * t ) /3) / %pi ;
//
F i r s t 2 Components o f t h e F o u r i e r S e r i e s o f a
S q u a r e Wave w i t h F r e q u e n c y W r a d / s e c
5 x2 = v *( cos ( w * t ) - cos (3* w * t ) /3+ cos (5* w * t ) /5) / %pi ;
// F i r s t 3
4
6
7
8
9
10
Components o f t h e F o u r i e r S e r i e s o f a S q u a r e Wave
with Frequency W rad / s e c
x3 = v *( cos ( w * t ) - cos (3* w * t ) /3+ cos (5* w * t ) /5 - cos (7* w * t )
/7) / %pi ;
// F i r s t 4 Components
o f t h e F o u r i e r S e r i e s o f a S q u a r e Wave w i t h
Frequency W rad / s e c
x4 = v *( cos ( w * t ) - cos (3* w * t ) /3+ cos (5* w * t ) /5 - cos (7* w * t )
/7+ cos (9* w * t ) /9) / %pi ;
// F i r s t 5 Components
o f t h e F o u r i e r S e r i e s o f a S q u a r e Wave w i t h
Frequency W rad / s e c
x5 = v *( cos ( w * t ) - cos (3* w * t ) /3+ cos (5* w * t ) /5 - cos (7* w * t )
/7+ cos (9* w * t ) /9 - cos (11* w * t ) /11) / %pi ;
//
F i r s t 6 Components o f t h e F o u r i e r S e r i e s o f a
S q u a r e Wave w i t h F r e q u e n c y W r a d / s e c
x6 = v *( cos ( w * t ) - cos (3* w * t ) /3+ cos (5* w * t ) /5 - cos (7* w * t )
/7+ cos (9* w * t ) /9 - cos (11* w * t ) /11+ cos (13* w * t ) /13) /
%pi ;
// F i r s t 7 Components o f t h e F o u r i e r
S e r i e s o f a S q u a r e Wave
subplot (3 ,2 ,1)
// D e v i d i n g t h e F i g u r e Qindow i n S i x Subwindows t o
p l o t d i f f e n r e n t components
11 plot ( x1 ) ;
// P l o t t i n g t h e F i r s t 2 c o mp o n e n t s o f t h e F o u r i e r
S e r i e s o f a S q u a r e Wave
12 title ( ’ S q u a r e Wave C o n t r u c t e d w i t h F i r s t 2
Components o f F o u r i e r S e r i e s ’ ) ;
// A s s i g n i n g
a T i t l e of the Figure
13 xlabel ( ’ S a m p l e s ’ ) ;
// A s s i g n i n g an X−l a b e l o f t h e f i g u r e
14 ylabel ( ’ A m p l i t u d e (V) ’ ) ;
15
16
// A s s i g n i n g o f a Y−l a b e l o f t h e f i g u r e
subplot (3 ,2 ,2)
plot ( x2 ) ;
5
// P l o t t i n g t h e F i r s t 3 c o m po n e n t s o f t h e F o u r i e r
S e r i e s o f a S q u a r e Wave
17 title ( ’ S q u a r e Wave C o n t r u c t e d w i t h F i r s t 3
Components o f F o u r i e r S e r i e s ’ ) ;
// A s s i g n i n g
a T i t l e of the Figure
18 xlabel ( ’ S a m p l e s ’ ) ;
// A s s i g n i n g an X−l a b e l o f t h e f i g u r e
19 ylabel ( ’ A m p l i t u d e (V) ’ ) ;
// A s s i g n i n g o f a Y−l a b e l o f t h e f i g u r e
20 subplot (3 ,2 ,3)
21 plot ( x3 ) ;
// P l o t t i n g t h e F i r s t 4 c o m po n e n t s o f t h e F o u r i e r
S e r i e s o f a S q u a r e Wave
22 title ( ’ S q u a r e Wave C o n t r u c t e d w i t h F i r s t 4
Components o f F o u r i e r S e r i e s ’ ) ;
// A s s i g n i n g
a T i t l e of the Figure
23 xlabel ( ’ S a m p l e s ’ ) ;
24
// A s s i g n i n g an X−l a b e l o f t h e f i g u r e
ylabel ( ’ A m p l i t u d e (V) ’ ) ;
25
26
// A s s i g n i n g o f a Y−l a b e l o f t h e f i g u r e
subplot (3 ,2 ,4)
plot ( x4 ) ;
// P l o t t i n g t h e F i r s t 5 c o m po n e n t s o f t h e F o u r i e r
S e r i e s o f a S q u a r e Wave
27 title ( ’ S q u a r e Wave C o n t r u c t e d w i t h F i r s t 5
Components o f F o u r i e r S e r i e s ’ ) ;
// A s s i g n i n g
a T i t l e of the Figure
28 xlabel ( ’ S a m p l e s ’ ) ;
// A s s i g n i n g an X−l a b e l o f t h e f i g u r e
29 ylabel ( ’ A m p l i t u d e (V) ’ ) ;
6
// A s s i g n i n g o f a Y−l a b e l o f t h e f i g u r e
30
31
32
subplot (3 ,2 ,5)
plot ( x5 ) ;
// P l o t t i n g t h e F i r s t 6 c o m po n e n t s o f t h e F o u r i e r
S e r i e s o f a S q u a r e Wave
33 title ( ’ S q u a r e Wave C o n t r u c t e d w i t h F i r s t 6
Components o f F o u r i e r S e r i e s ’ ) ;
// A s s i g n i n g
a T i t l e of the Figure
34 xlabel ( ’ S a m p l e s ’ ) ;
// A s s i g n i n g an X−l a b e l o f t h e f i g u r e
35 ylabel ( ’ A m p l i t u d e (V) ’ ) ;
// A s s i g n i n g o f a Y−l a b e l o f t h e f i g u r e
36
37
38
subplot (3 ,2 ,6)
plot ( x6 ) ;
// P l o t t i n g t h e F i r s t 7 c o m po n e n t s o f t h e F o u r i e r
S e r i e s o f a S q u a r e Wave
39 title ( ’ S q u a r e Wave C o n t r u c t e d w i t h F i r s t 7
Components o f F o u r i e r S e r i e s ’ ) ;
// A s s i g n i n g
a T i t l e of the Figure
40 xlabel ( ’ S a m p l e s ’ ) ;
// A s s i g n i n g an X−l a b e l o f t h e f i g u r e
41 ylabel ( ’ A m p l i t u d e (V) ’ ) ;
// A s s i g n i n g o f a Y−l a b e l o f t h e f i g u r e
42
43
44
45
46
///−−−I n p u t P a r a m e t e r s −−−//
// v==> v o l t a g e
//w==>F r e q u e n c y
7
Experiment: 2
ESTIMATION OF THE
ROOTS(ZEROS) FOR A
REAL VALUED FUNCTION
USING NEWTON-RAPHSON
METHOD
Scilab code Solution 2.1 Estimation or Roots
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 ) ;
8
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 ( ’ P l o t o f f u n c t i o n ’ )
21
22
23
24 x = input ( ’ E n t e r i n i t i a l g u e s s o f r o o t l o c a t i o n :
25
26 itermax = 10;
// % max # o f i t e r a t i o n s
27 iter = 0;
28 errmax = 0.00001;
// % c o n v e r g e n c e t o l e r a n c e
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; // % f i n d
c h a n g e from p r e v i o u s
43
44
45
46
47
48
49
50
x = xnew
// % s e t up f o r n e x t i t e r a t i o n
disp ( ’ I t e r a t i o n No . ’ )
disp ( iter )
disp ( ’ t h e e s t i m a t e d v a l u e o f t h e v a r i a b l e x i s = ’ )
disp ( x )
9
’ );
51 end
52
53 ///−−−−I n p u t P a r a m e t e r s −−−−///
54
55 // T h i s c o d e w i l l work f o r d i f f e r e n t
f u n c t i o n s of the
v a r i a b l e x . hence the u s e r has to modify the
function & its derivative accordingly
56 // I t e r m a x==>maximum number o f i t e r a t i o n f o r which
t h e method h a s t o e s t i m a t e t h e v a l u e o f t h e
variable
57 // errmax==>maximun t o l e r a b l e e r r o r
10
Experiment: 3
DFT & IDFT OF A GIVEN
SEQUENCE
Scilab code Solution 3.1 DFT of a Given Sequence
1 clear
2 clc
3
4 x = input ( ’ e n t e r t h e
d i g i t a l s e q u e n c e ’ );
// I n p u t
the d i g i t a l sequence
5 N = length ( x ) ;
// F i n d i n g t h e l e n g t h o f t h e s e q u e n c e f o r N−p o i n t
DFT
6
7 for k =1: N
8
y ( k ) =0;
9
for n =1: N
10
y ( k ) = y ( k ) +( x ( n ) *( exp ( - %i *2* %pi *( k -1) *( n -1) / N
// E q u a t i o n t o
)));
f i n d DFT
11
end
12 end
11
disp ( ’ The DFT o f t h e g i v e n s e q u e n c e i s : ’ )
//
D i s p l a y i n g t h e DFT
14 disp ( y )
13
15
16
17
18
19
///−−I n p u t P a r a m e t e r s −−−//
// x==> d i g i t a l s e q u e n c e f o r which DFT h a s t o be f o u n d
Scilab code Solution 3.2 IDFT of the given responce
1 clear
2 clc
3
4 x = input ( ’ E n t e r t h e s e q u e n c e : ’ ) ;
// I n p u t t h e DFT
5 N = length ( x ) ;
// F I n d i n g t h e l e n g t h t o g e t N−p o i n t IDFT
6 for n =1: N
7
y ( n ) =0;
8
for k =1: N
9
y ( n ) = y ( n ) +( x ( k ) *( exp ( %i *2* %pi *( k -1) *( n -1) / N )
// E q u a t i o n t o
));
f i n d t h e IDFT
10
end
11
y(n)=y(n)/N;
12 end
13 disp ( ’ The IDFT o f t h e g i v e n s e q u e n c e
t h e IDFT
14 disp ( y )
15
12
is : ’)
// D i s p l a y i n g
16
17
18
19
//−−I n p u t P a r a m e t e r s −−−//
// x==>F r e q u e n c y domain d i g i t a l r e p r e s e n t a t i o n o f t h e
s e q u e n c e (DFT) f o r which IDFT h a s t o be f o u n d
13
Experiment: 4
SYSTEM RESPONSE USING
CONVOLUTION
Scilab code Solution 4.1 System Response using Convolution
1
2 X = input ( ’ E n t e r t h e I n p u t d a t a S e q u e n c e X [ n ] : ’ ) ;
3 H = input ( ’ E n t e r t h e R e s p o n s e o f t h e System H [ n ] : ’ ) ;
4
5 Y = conv (X , H ) ;
6
7 disp ( ’ The r e s p o n s e o f t h e g i v e n s y s t e m f o r t h e g i v e n
i n pu r data s e q u e n c e i s Y[ n ] : ’ );
8 disp ( Y ) ;
9
10
11
12
13
//−−−I n p u t V a r i a b l e s −−//
//X==> d i g i t a l s e q u e n c e X [ n ]
//H==> f i l t e r i m p u l s e r e s p o n s e H [ n ]
14
Experiment: 5
NODE VOLTAGE & MESH
CURRENT ANALYSIS
Scilab code Solution 5.1 Node Voltage
1 // number o f l o o p s i n t h e n e t w o r k s =2
2
3 v1 = input ( ’ E n t e r t h e v o l t a g e i n l o o p −1 ( i n V) : ’ ) ;
4 i2 = input ( ’ E n t e r t h e c u r r e n t t h r o u g h l o o p −2 ( i n A) : ’ )
;
5 r2 = input ( ’ E n t e r t h e r e s i s t a n c e i n s e r i e s w i t h V1 i n
l o o p −1 ( i n Ohm) : ’ ) ;
6 r1 = input ( ’ E n t e r t h e r e s i s t a n c e b e t w e e n v2 & GND. ( a
common e l e m e n t bwetween l o o p −1 & 2 ) ( i n Ohm) : ’ ) ;
7
8 // Teh node v o l t a g e a t node −2 can be s o l v e d a s
9 // temp1 =(v2−v1 ) / r 2 ;
10 // temp2 =( v2 / r 1 ) ’
11 //0=temp1+temp2+i 2 ;
12 temp3 = i2 * r1 * r2 ;
13 temp4 = v1 / r2 ;
14 temp5 = temp4 - temp3 ;
15 temp6 = temp5 * r1 * r2 ;
16 v2 = temp6 /( r1 + r2 ) ;
15
17
18
19
20
21
22
23
24
25
disp ( ’ V o l t a g e a t Node−2 V2= ’ ) ;
disp ( v2 )
//−−−I n p u t V a r i a b l e s −−−//
// v1==>e q u i v a l e n t v o l t a g e i n l o o p 1 −−c o n s t a n t
// i 2==>v a l u e o f t h e c u r r e n t s o u r c e i n l l o p 2−−
constant
26 // r 2==>v a l u e o f t h e r e s i t a n c e i n s e r i e s w i t h V1 i n
l o o p 1−− c o n s t a n t
27 // r 1==>v a l u e o f t h e r e s i t a n c e i n t h e common b r a n c h
i n l o o p 1 & l o o p 2−− c o n s t a n t
Scilab code Solution 5.2 Mesh Current
1 // number o f l o o p s i n
2
3 v1 = input ( ’ E n t e r t h e
4 v2 = input ( ’ E n t e r t h e
5 r1 = input ( ’ E n t e r t h e
t h e n e t w o r k s =2
v o l t a g e i n l o o p −1 ( i n V) : ’ ) ;
v o l t a g e i n l o o p −2 ( i n V) : ’ ) ;
r e s i s t a n c e i n s e r i e s w i t h V1 i n
l o o p −1 ( i n Ohm) : ’ ) ;
6 r2 = input ( ’ E n t e r t h e r e s i s t a n c e b e t w e e n v2 & GND. ( a
common e l e m e n t bwetween l o o p −1 & 2 ) ( i n Ohm) : ’ ) ;
7 r3 = input ( ’ E n t e r t h e r e s i s t a n c e i n s e r i e s w i t h V2 i n
l o o p −2 ( i n Ohm) : ’ ) ;
8
9
10
11
12
13
14
15
// The mesh c u r r e n t can be s o l v e d a s
// v1 =( r 1+r 2 ) ∗ i 1 −r 2 ∗ i 2 ;
//−v2=−r 2 ∗ i 1 +( r 2+r 3 ) ∗ i 2 ;
// [ v ] = [ r ] [ i ] ;
// [ i ] = [ v ] [ R ] ; where [ R]= i n v ( [ r ] ) ;
16
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
v =[ v1 ; v2 ];
r =[ r1 + r2 - r2 ; - r2 r2 + r3 ];
// i =[ i 1 ; i 2 ] ;
R = inv ( r ) ;
i=R*v;
disp ( ’ t h e c u r r e n t t h r o u g h t h e l o o p s= ’ )
disp ( i )
//−−I n p u t v a r i a b l e s −−//
// v1==>v o l t a g e i n l o o p 1−− c o n s t a n t
// v2==>v o l t a g e i n l o o p 2−− c o n s t a n t
// r 1==>r e s i t a n c e i n l o o p 1 −− c o n s t a n t
// r 2==>r e s i t a n c e i n t h e common b r a n c h o f l o o p 1 &
l o o p 2 −−c o n s t a n t
38 // r 3==>r e s i t a n c e i n l o o p 2 −− c o n s t a n t
17
Experiment: 6
STABILITY OF A
FEEDBACK SYSTEM IN
XCOS
This code can be downloaded from the website wwww.scilab.in This code
can be downloaded from the website wwww.scilab.in
18
Experiment: 7
IMPLEMENTATION OF
CHANNEL CODING-LINEAR
BLOCK CODE
Scilab code Solution 7.1 Linear Block Coder Decoder
1
2
3 //% t h i s i s a l i n e a r b l o c k c o d e main s c r i p t f i l e %
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]; //% p a r i t y
matrix of
s i z e k ∗ ( n−k ) t o be
11
//
% s e l e c t e d so that
the systematic generator
% matrix i s
l i n e a r l y independent or f u l l rank
13 //
% matrix
12
//
14
19
//% ( n , k ) l i n e a r b l o c k c o d e where k − no . o f i n p u t
d a t a b i t s and n−no . o f o / p
16 //% d a t a b i t s . c o d e r a t e=k /n
17 //% x i s an i n p u t v e c t o r c o n t a i n i n g k b i t s
15
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// %This i s an l i n e a r b l o c k e n c o d i n g f u n c t i o n f i l e %
function y1 = linblkcode ( x ) ;
global P n k ;
n =7;
k =4;
P =[1 1 0; 0 1 1; 1 0 1;1 1 1];
// x =[0 1 1 0 ] ;
//G=[ ] ;
//
G =[ eye (k , k ) P ];
% G e n e r a t o r m a t r i x k ∗n
y1 = zeros (1 , n ) ;
for i =1: k
var (i ,:) = x (1 , i ) & G (i ,:) ;
var (i ,:) = bool2s ( var (i ,:) ) ;
y1 (1 ,:) = bitxor ( var (i ,:) , y1 (1 ,:) ) ;
end
endfunction
// %This i s a l i n e a r b l o c k syndrome d e c o d i n g f u n c t i o n
file%
function x1 = linblkdecoder ( y )
//% h e r e y i s r e c i e v e d v e c t o r 7 b i t s l o n g
//% ( 7 , 4 ) l i n e a r b l o c k c o d e
global P n k ;
//H=[ ] ; //% PARITY CHECK MATRIX
20
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
H =[ P ’ eye (( n - k ) ,(n - k ) ) ];
Ht =H ’; // % t r a n s p o s e o f H
S = zeros (1 ,n - k ) ; // %syndrome o f r e c i e v e d v e c t o r x
for i =1: n - k
S ( i ) = y (1) & Ht (1 , i ) ;
S ( i ) = bool2s ( S ( i ) ) ;
for j =2: n
S ( i ) = bitxor ( S ( i ) , bool2s (( y ( j ) & Ht (j , i ) ) ) ) ;
end
end
//%%∗∗∗∗SYNDROME LOOK UP TABLE∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
//%%∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
//%
if S ==[0 0 0]
e =[0 0 0 0 0 0 0];
z = bitxor (y , e ) ;
end
if S ==[0 0 1]
e =[0 0 0 0 0 0 1];
z = bitxor (y , e ) ;
end
if S ==[0 1 0]
e =[0 0 0 0 0 1 0];
z = bitxor (y , e ) ;
end
if S ==[1 0 0]
e =[0 0 0 0 1 0 0];
z = bitxor (y , e ) ;
end
if S ==[1 1 1]
e =[0 0 0 1 0 0 0];
21
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
z = bitxor (y , e ) ;
end
if S ==[1 0 1]
e =[0 0 1 0 0 0 0];
z = bitxor (y , e ) ;
end
if S ==[0 1 1]
e =[0 1 0 0 0 0 0];
z = bitxor (y , e ) ;
end
if S ==[1 1 0]
e =[1 0 0 0 0 0 0];
z = bitxor (y , e ) ;
end
x1 = z (1 ,1: k ) ;
endfunction
x =[0 1 1 0];
//
% input b i t s to the
e n c o d e r o f s i z e 1∗ k
112 y1 = linblkcode ( x ) ; //
//
% y1 i s t h e
output of l i n e a r block encoder
113
114
115 e1 =[1 0 0 0 0 0 0];
// % i n t e n t i o n a l l y
error introduced after
116
//
% e n c o d i n g and
b e f o r e sending to decoder ( in
117
//
% this case pls
i n t r o d u c e o n l y one b i t e r r o r )
118 y = bitxor ( y1 , e1 ) ; //
% input that w i l l
be made a v a i l a b l e t o l i n e a r
119
//
% block decoder
120
22
121 x1 = linblkdecoder ( y ) //
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
% x1 i s t h e o u t p u t
of the l i n e a r block decoder
//
% which w i l l be
same a s x p r o v i d e d t h a t
here
//
% have i n t r o d u c e d
o n l y one b i t e r r o r
disp ( ’ The
disp ( x )
disp ( ’ The
disp ( y1 )
disp ( ’ The
disp ( y )
disp ( ’ The
disp ( x1 )
i n f o r m a t i o n s i g n a l= ’ )
t r a n s m i t t e d encoded s i g n a l= ’ )
r e c i e v e d s i g n a l= ’ )
denoded s i g n a l = ’ )
//−−I n p u t v a r i a b l e s −−//
// ( n , k )==>c o n s t a n t s a c c o r d i n g t o t h e d e s i g n o f
l i n e a r block code
138 //P==>p a r i t y
m a t r i x o f s i z e k ∗ ( n−k ) t o be s e l e c t e d
so that the systematic generator matrix i s
l i n e a r l y independent or f u l l rank matrix
139 // x==>i n f o r m a t i o n s i g n a l −−v e c t o r
23
Experiment: 8
FILTER DESIGN USING
LAPLACE TRANSFORM
Scilab code Solution 8.1 Filter Design
1
2
3
4
5 x = input ( ’ E n t e r t h e i n p u t d a t a s e q u e n c e ’ ) ;
6 b = input ( ’ E n t e r t h e co− e f f i t i e n t s f o r t h e n u m e r a t o r
p ol yn om i al : ’ );
7 a = input ( ’ E n t e r t h e co− e f f i t i e n t s
p ol yn o mi al : ’ );
8
9 y = filter (b ,a , x ) ;
10
11
12 disp ( ’ The i n p u t s i g n a l i s = ’ )
13 disp ( x )
14 disp ( ’ The f i l t e r e d s i g n a l i s = ’ )
15 disp ( y )
16 //−−I n p u t V a r i a b l e s −−//
17
24
f o r the denominator
18
19
20
// x==>i n p u t d i g i t a l s e q u e n c e −−v e c t o r
// b==>v e c o t r
// a==>v e c t o r
25
Experiment: 9
SIGNAL MODULATION
Scilab code Solution 9.1 BPSK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function out_a = BPSK_a ( bit , no_shift , shift )
if bit == 1
out_a = no_shift
else
out_a = shift
end
endfunction
t =0:0.001:1;
bit_1 =0;
no_shift1 = sin (2* %pi *10* t ) ;
shift1 = sin (2* %pi *10* t +( %pi ) ) ;
out = BPSK_a ( bit_1 , no_shift1 , shift1 ) ;
plot (t , out )
t1 =1:0.001:2;
26
22
23
24
25
26
27
28
29
30
bit_2 =1;
out1 = BPSK_a ( bit_2 , no_shift1 , shift1 )
plot ( t1 , out1 )
xlabel ( ’ t i m e ’ )
ylabel ( ’ A m p l i t u d e ’ )
//−−I n p u t V a r i a b l e s
// b i t 1 & b i t 2==> d i g i t a l
27
l o g i c 1 or 0
;
Experiment: 10
APPLICATION OF LINEAR
ALGEBRA IN DIGITAL
COMMUNICATION
Scilab code Solution 10.1 Rotation of a Vector
1 r1 =[1 0];
2 r2 =[0 1];
3 theta = input ( ” E n t e r t h e t h e t a ( a n g l e
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 v e c t o r r 1== ’ )
14 disp ( r1 )
15 disp ( ’ The r o t a t e d v e c t o r r 1= ’ )
28
16
17
18
19
20
21
22
23
24
25
26
27
disp ( rotated_r1 )
disp ( ’ The v e c t o r r 2= ’ )
disp ( r2 )
disp ( ’ The r o t a t e d v e c t o r r 2= ’ )
disp ( rotated_r2 )
//−−I n p u t v a r i a b l e s −−//
// t h e r a==>c o n s t a n t
29