Signal Processing - Mrs - S. Chaya
Signal Processing - Mrs - S. Chaya
Signal Processing
by Mrs S. Chaya
Electronics Engineering
AIKTC 1
Solutions provided by
Mr R.Senthilkumar- Assistant Professor
Electronics Engineering
Institute of Road and Transport Technology
2
List of Experiments
3
List of Figures
1.1 Exp1a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 Exp1a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3 Exp1b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.4 Exp1b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1 Exp2a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.2 Exp2a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.3 Exp2b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.4 Exp2b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.1 Exp3a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.2 Exp3a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.3 Exp3b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.4 Exp3b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.1 Exp4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.1 Exp5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.2 Exp5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.1 Exp6a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.2 Exp6a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.3 Exp6b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.4 Exp6c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6.5 Exp6d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.1 Exp7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.1 Exp8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
9.1 Exp9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4
10.1 Exp10a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
10.2 Exp10b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
11.1 Exp11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
12.1 Exp12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
13.1 Exp13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
5
Experiment: 1
cameraman.jpeg
1 // Image Q u a n t i z a t i o n
2 clear ;
3 clc ;
4 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Chaya Lab \
s c i l a b \ cameraman . j p e g ’ ) ;
5 quanta = 50;
6 J = double ( I ) /255;
7 J = uint8 ( J * quanta ) ;
8 J = double ( J ) / quanta ;
9 figure
10 ShowImage (I , ’ O r i g i n a l Image ’ )
11 figure
12 ShowImage (J , ’ Q u a n t i z e d Image ’ )
6
Figure 1.1: Exp1a
7
check Appendix AP 1 for dependency:
cameraman.jpeg
1 // Image S a m p l i n g
2 clear ;
3 clc ;
4 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Chaya Lab \
s c i l a b \ cameraman . j p e g ’ ) ;
5 J = imresize (I ,0.5) ; // R e d u c i n g t h e s a m p l i n g r a t e
6 K1 = imresize (J ,2 , ’ n e a r e s t ’ ) ; // I n c r e a s i n g t h e
sampling rate
7 K2 = imresize (J ,2 , ’ b i l i n e a r ’ ) ;
8 K3 = imresize (J ,2 , ’ b i c u b i c ’ ) ;
9 figure
10 ShowImage (I , ’ O r i g i n a l Image ’ )
11 figure
12 ShowImage (J , ’ R e d u c i n g t h e S a m p l i n g Rate by 2 ’ )
13 figure
14 ShowImage ( K1 , ’ I n c r e a s i n g t h e S a m p l i n g Rate by 2
n e a r e s t n e i g h b o u r method ’ )
15 figure
16 ShowImage ( K2 , ’ I n c r e a s i n g t h e S a m p l i n g Rate by 2
b i l i n e a r method ’ )
17 figure
18 ShowImage ( K3 , ’ I n c r e a s i n g t h e S a m p l i n g Rate by 2
b i c u b i c method ’ )
8
Figure 1.2: Exp1a
9
Figure 1.3: Exp1b
10
11
Figure 1.4: Exp1b
12
Experiment: 2
Understanding basic
relationship between pixel
1 // Image A r i t h m e t i c − d i v i s i o n , m u l t i p l i c a t i o n , image
s u b t r a c t i o n and image a d d i t i o n
2 clc ;
3 clear ;
4 close ;
5 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Chaya Lab
\ s c i l a b \ cameraman . j p e g ’ ) ; // SIVP t o o l b o x
6 J = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Chaya Lab \
s c i l a b \ r i c e . j p g ’ ) ; // SIVP t o o l b o x
7 IMA = imadd (I , J ) ; // SIVP t o o l b o x
8 figure
9 ShowImage ( IMA , ’ Image A d d i t i o n ’ ) // IPD t o o l b o x
13
10 IMS = imabsdiff (I , J ) ; // SIVP t o o l b o x
11 figure
12 ShowImage ( IMS , ’ Image S u b t r a c t i o n ’ ) ; // IPD t o o l b o x
13 IMD = imdivide (I , J ) ; // SIVP t o o l b o x
14 IMD = imdivide ( IMD ,0.01) ; // SIVP t o o l b o x
15 figure
16 ShowImage ( uint8 ( IMD ) , ’ Image D i v i s i o n ’ ) ; // IPD t o o l b o x
17 IMM = immultiply (I , I ) ; // SIVP t o o l b o x
18 figure
19 ShowImage ( uint8 ( IMM ) , ’ Image M u l t i p l y ’ ) ; // IPD t o o l b o x
1 // Image A r i t h m e t i c − D i s t a n c e and C o n n e c t i v i t y : To
understand the notion of c o n n e c t i v i t y
2 // and n e i g h b o r h o o d d e f i n e d f o r a p o i n t i n an image .
3 clc ;
4 clear ;
5 close ;
6 // f u n c t i o n t o c o n v e r t g r a y t o b i n a r y
7 function X = gray2bin ( x )
8 xmean = mean2 ( x ) ;
9 [m , n ]= size ( x ) ;
10 X = zeros (m , n ) ;
11 for i = 1: m
14
Figure 2.1: Exp2a
15
Figure 2.2: Exp2a
16
12 for j = 1: n
13 if x (i , j ) > xmean then
14 X (i , j ) = 1;
15 end
16 end
17 end
18 endfunction
19 // f u n c t i o n t o f i n d t o t a l l e n g t h o f two d i m e n s i o n a l
matrix
20 function n = numdims ( X )
21 n = length ( size ( X ) ) ;
22 endfunction
23 // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
24 // F u n t i o n t o pad z e r o s i n c o l u m n s and r o w s a t b o t h
e n d s o f an b i n a r y image
25 function B = padarray ( b )
26 // pad z e r o s i n c o l u m n s and r o w s a t b o t h e n d s o f
an b i n a r y image
27 [m , n ] = size ( b ) ;
28 num_dims = length ( size ( b ) ) ;
29 B = zeros ( m + num_dims , n + num_dims ) ;
30 for i = num_dims : m + num_dims -1
31 for j = num_dims : m + num_dims -1
32 B (i , j ) = b (i -1 ,j -1) ;
33 end
34 end
35 endfunction
36 // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
37 // [ 1 ] . E u c l i d e a n D i s t a n c e b e t w e e n i m a g e s and t h e i r
histograms
38 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Chaya Lab \
s c i l a b \ l e nn a . jpg ’ );
39 J = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Chaya Lab \
s c i l a b \ cameraman . j p e g ’ )
40 h_I = CreateHistogram ( I ) ; // IPD t o o l b o x
41 h_J = CreateHistogram ( J ) ; // IPD t o o l b o x
42 I = double ( I ) ;
43 J = double ( J ) ;
17
44 E_dist_Hist = sqrt ( sum (( h_I - h_J ) .^2) ) ; // E u c l i d e a n
D i s t a n c e b e t w e e n h i s t o g r a m s o f two i m a g e s
45 E_dist_images = sqrt ( sum (( I (:) -J (:) ) .^2) ) ; //
E u c l i d e a n D i s t a n c e b e t w e e n two i m a g e s
46 disp ( E_dist_images , ’ E u c l i d e a n D i s t a n c e b e t w e e n two
images ’ );
47 disp ( E_dist_Hist , ’ E u c l i d e a n D i s t a n c e b e t w e e n
h i s t o g r a m s o f two i m a g e s ’ )
48 // [ 2 ] . C o n n e c t i v i t y − 8 c o n n e c t e d t o t h e b a c k g r o u n d
49 // e x e c ( g r a y 2 b i n )
50 Ibin = gray2bin ( I ) ;
51 Jbin = gray2bin ( J ) ;
52 // c o n v e r s i o n o f g r a y image i n t o b i n a r y image
53 conn = [1 ,1 ,1;1 ,1 ,1;1 ,1 ,1]; //8− c o n n e c t i v i t y
54 // e x e c ( ’ C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Gautam PAL Lab
\ numdims . s c i ’ )
55 num_dims = numdims ( I ) ;
56 // e x e c ( ’ C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Gautam PAL Lab
\ padarray . sci ’ )
57 B = padarray ( Ibin ) ;
58 global FILTER_ERODE ;
59 StructureElement = CreateStructureElement ( ’ s q u a r e ’ ,
3) ;
60 B_eroded = MorphologicalFilter (B , FILTER_ERODE ,
StructureElement . Data ) ; // IPD t o o l b o x
61 // n o t e : S t r u c t u r e E l e m e n t . Data and conn b o t h a r e same
values
62 // e x c e p t t h a t S t r u c t u r e E l e m e n t . Data i s b o o l e a n
e i t h e r true or f a l s e
63 p = B &~ B_eroded ;
64 [m , n ] = size ( p ) ;
65 for i = num_dims : m + num_dims -2
66 for j = num_dims : n + num_dims -2
67 pout (i -1 ,j -1) = p (i , j ) ;
68 end
69 end
70 figure
71 ShowImage ( uint8 ( I ) , ’ Gray Lenna Image ’ )
18
72 figure
73 ShowImage ( Ibin , ’ B i n a r y Lenna Image ’ )
74 figure
75 ShowImage ( pout , ’ 8 n e i g h b o u r h o o d c o n n e c t i v i y i n Lenna
Image ’ )
76 //RESULT
77 // E u c l i d e a n D i s t a n c e b e t w e e n two i m a g e s
78 //
79 // 19797.433
80 //
81 // E u c l i d e a n D i s t a n c e b e t w e e n h i s t o g r a m s o f two
images
82 //
83 // 5770.7
19
Figure 2.3: Exp2b
20
Figure 2.4: Exp2b
21
Experiment: 3
1 // Note : D e t a i l s o f s c i l a b s o f t w a r e v e r s i o n and OS
v e r s i o n used :
2 //OS : Windows 7
3 // S c i l a b v e r s i o n : 5 . 4 . 1
4 // IPD Atom v e r s i o n : 8 . 3 . 1 − 2
5 // SIVP Atom v e r s i o n : 0 . 5 . 3 . 1 − 2
6 // 2 . Program t o s h a r p e n image
7 // Read image and d i s p l a y i t .
8 // For C o l o u r Image
9 clc ;
10 clear all ;
11 close ;
12 a = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
s i g n a l p r o c e s s i n g l a b \ h e s t i a n . jpg ’ );
13 ShowColorImage (a , ’ O r i g i n a l Image ’ )
14 title ( ’ O r i g i n a l Image ’ ) ;
15 // S h a r p e n t h e image and d i s p l a y i t .
16 // b = i m s h a r p e n ( a ) ;
17 // f i g u r e , imshow ( b ) , t i t l e ( ’ S h a r p e n e d Image ’ ) ;
18
19
22
20 radius =1;
21 amount = 0.8000;
22 threshold = 0;
23 // G a u s s i a n b l u r r i n g f i l t e r
24 filtRadius = ceil ( radius *2) ;
25 filtSize = 2* filtRadius + 1;
26 gaussFilt = fspecial ( ’ g a u s s i a n ’ ,[ filtSize filtSize ] ,
radius ) ;
27 // High−p a s s f i l t e r
28 sharpFilt = zeros ( filtSize , filtSize ) ;
29 sharpFilt ( filtRadius +1 , filtRadius +1) = 1;
30 sharpFilt = sharpFilt - gaussFilt ;
31 sharpFilt = amount * sharpFilt ;
32 sharpFilt ( filtRadius +1 , filtRadius +1) = sharpFilt (
filtRadius +1 , filtRadius +1) + 1;
33 B = imfilter (a , sharpFilt ) ;
34 figure
35 ShowColorImage (B , ’ S h a r p e n e d Image ’ ) ;
hestian.jpg
1 // Note : D e t a i l s o f s c i l a b s o f t w a r e v e r s i o n and OS
v e r s i o n used :
2 //OS : Windows 7
3 // S c i l a b v e r s i o n : 5 . 4 . 1
4 // IPD Atom v e r s i o n : 8 . 3 . 1 − 2
5 // SIVP Atom v e r s i o n : 0 . 5 . 3 . 1 − 2
6 // 2 . b . Program t o s h a r p e n image
23
Figure 3.1: Exp3a
24
Figure 3.2: Exp3a
25
7 // Read image and d i s p l a y i t .
8 // For Gray Image
9 clc ;
10 clear all ;
11 close ;
12 a = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
s i g n a l p r o c e s s i n g l a b \ r i c e . j p g ’ ) ; // SIVP t o o l b o x
13 ShowImage (a , ’ O r i g i n a l Image ’ ) // SIVP t o o l b o x
14 title ( ’ O r i g i n a l Image ’ ) ;
15 // S h a r p e n t h e image and d i s p l a y i t .
16 // b = i m s h a r p e n ( a ) ;
17 // f i g u r e , imshow ( b ) , t i t l e ( ’ S h a r p e n e d Image ’ ) ;
18
19
20 radius =1;
21 amount = 0.8000;
22 threshold = 0;
23 // G a u s s i a n b l u r r i n g f i l t e r
24 filtRadius = ceil ( radius *2) ;
25 filtSize = 2* filtRadius + 1;
26 gaussFilt = fspecial ( ’ g a u s s i a n ’ ,[ filtSize filtSize ] ,
radius ) ;
27 // High−p a s s f i l t e r
28 sharpFilt = zeros ( filtSize , filtSize ) ;
29 sharpFilt ( filtRadius +1 , filtRadius +1) = 1;
30 sharpFilt = sharpFilt - gaussFilt ;
31 sharpFilt = amount * sharpFilt ;
32 sharpFilt ( filtRadius +1 , filtRadius +1) = sharpFilt (
filtRadius +1 , filtRadius +1) + 1;
33 B = imfilter (a , sharpFilt ) ;
34 figure
35 ShowImage (B , ’ S h a r p e n e d Image ’ ) ; // IPD t o o l b o x
26
Figure 3.3: Exp3b
27
Figure 3.4: Exp3b
28
rice.jpg
29
Experiment: 4
1 // L o s s l e s s Image C o m p r e s s i o n − I m p l e m e n t a t i o n o f
a r i t h m e t i c coding f o r images
2 // Note 1 : I n o r d e r t o run t h i s program download
Huffman t o o l b o x from
3 // s c i l a b atoms
4 // Note 2 : The Huffman atom i s u s e d t o e n c o d e i m a g e s
30
of small s i z e only
5 // S o f t w a r e v e r s i o n
6 //OS Windows7
7 // S c i l a b 5 . 4 . 1
8 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
9 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
10 clear ;
11 clc ;
12 close ;
13 a = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Chaya Lab \
s c i l a b \ cameraman . j p e g ’ ) ;
14 A = imresize (a ,[16 16]) ; // Only Image o f s m a l l s i z e
i s p o s s i b l e to c a l l huffcode
15 B = size ( A ) ;
16 A = A (:) . ’;
17 A = double ( A ) ;
18 [ QT , QM ]= huffcode ( A ) ; // Huffman E n c o d i n g
19 disp ( ’ c o m p r e s s e d B i t s e q u e n c e : ’ ) ;
20 disp ( QT ) ;
21 disp ( ’ Code T a b l e : ’ ) ;
22 disp ( QM ) ;
23 // Now , t h e r e v e r s e o p e r a t i o n
24 C = huffdeco ( QT , QM ) ; // Huffman D e c o d i n g
25 for i =1: B (1)
26 E (i ,1: B (2) ) = C (( i -1) * B (2) +1: i * B (2) ) ;
27 end
28 D = E ’;
29 E = imresize (D ,[32 ,32]) ;
30 figure
31 ShowImage (a , ’ O r i g i n a l cameraman Image 256 x256 ’ )
32 figure
33 ShowImage (E , ’ R e c o n s t r u c t e d cameraman Image 32 x32 ’ ) ;
cameraman.jpeg
31
Experiment: 5
1 // L o s s y Image C o m p r e s s i o n −B l o c k T r u n c a t i o n Coding
2 // Note : D e t a i l s o f s c i l a b s o f t w a r e v e r s i o n and OS
v e r s i o n used :
3 //OS : Windows 7
4 // S c i l a b v e r s i o n : 5 . 4 . 1
5 // IPD Atom v e r s i o n : 8 . 3 . 1 − 2
6 // SIVP Atom v e r s i o n : 0 . 5 . 3 . 1 − 2
7 clc ;
8 clear ;
9 close ;
10 function out_put = btcimage ( in_put , block_size )
11 // Note : D e t a i l s o f s c i l a b s o f t w a r e v e r s i o n and
OS v e r s i o n u s e d :
12 //OS : Windows 7
13 // S c i l a b v e r s i o n : 5 . 4 . 1
14 // IPD Atom v e r s i o n : 8 . 3 . 1 − 2
15 // SIVP Atom v e r s i o n : 0 . 5 . 3 . 1 − 2
16 X = imread ( in_put ) ;
17 Y = imfinfo ( in_put ) ;
32
18 K = block_size ;
19 X1 = double ( X ) ;
20 y1 = size ( X ) ;
21 n = y1 (1) ;
22 m = y1 (2) ;
23 k =1; l =1;
24
25
26 if ( Y . ColorType == ’ g r a y s c a l e ’ )
27
28 // IMAGE ENCODING
29
30 //
31 // FOR GRAY SCALE IMAGES
32 //
33 figure (1)
34 ShowImage (X , ’ O r i g i n a l ’ )
35 title ( ’ ORIGINAL ’ ) ;
36 for i =1: K : n
37 for j =1: K : m
38 tmp ([1: K ] ,[1: K ]) = X1 ([ i : i +( K -1) ] ,[ j : j
+( K -1) ]) ;
39 mn = mean ( mean ( tmp ) ) ;
40 tmp1 ([ i : i +( K -1) ] ,[ j : j +( K -1) ]) = tmp > mn
;
41 Lsmat =( tmp < mn ) ;
42 Mrmat =( tmp >= mn ) ;
43 Lsmn = sum ( sum ( Lsmat ) ) ;
44 Mrmn = sum ( sum ( Mrmat ) ) ;
45 Mu ( k ) = sum ( sum ( Lsmat .* tmp ) ) /( Lsmn +.5)
; k = k +1;
46 Mi ( l ) = sum ( sum ( Mrmat .* tmp ) ) / Mrmn ; l = l
+1;
47 end
48 end
49 figure (2)
50 ShowImage ( tmp1 , ’ Encoded Image ’ )
51 title ( ’ENCODED ’ ) ;
33
52
53 // IMAGE DECODING
54
55 k =1; l =1;
56 for i =1: K : n
57 for j =1: K : m
58 tmp21 ([1: K ] ,[1: K ]) = tmp1 ([ i : i +( K -1)
] ,[ j : j +( K -1) ]) ;
59 tmp22 =( tmp21 * round ( Mu ( k ) ) ) ; k = k +1;
60 tmp21 =(( tmp21 ==0) * round ( Mi ( l ) ) ) ; l = l
+1;
61 tmp21 = tmp21 + tmp22 ;
62 out_put ([ i : i +( K -1) ] ,[ j : j +( K -1) ]) =
tmp21 ;
63 end
64 end
65 figure (3)
66 ShowImage ( uint8 ( out_put ) , ’ Decoded Image ’ )
67 title ( ’DECODED ’ ) ;
68
69 //
70 // FOR COLORED IMAGES
71 //
72
73 elseif ( Y . ColorType == ’ t r u e c o l o r ’ )
74 R = X (: ,: ,1) ;
75 G = X (: ,: ,2) ;
76 B = X (: ,: ,3) ;
77 // IMAGE ENCODING
78 figure (1)
79 ShowColorImage (X , ’ O r i g i n a l ’ )
80 title ( ’ ORIGINAL ’ ) ;
81 for b =1:3
82 for i =1: K : n
83 for j =1: K : m
84 tmp ([1: K ] ,[1: K ]) = X1 ([ i : i +( K -1)
] ,[ j : j +( K -1) ] , b ) ;
85 mn = mean ( mean ( tmp ) ) ;
34
86 tmp1 ([ i : i +( K -1) ] ,[ j : j +( K -1) ] , b ) =
tmp > mn ;
87 Lsmat =( tmp < mn ) ;
88 Mrmat =( tmp >= mn ) ;
89 Lsmn = sum ( sum ( Lsmat ) ) ;
90 Mrmn = sum ( sum ( Mrmat ) ) ;
91 Mu (b , k ) = sum ( sum ( Lsmat .* tmp ) ) /(
Lsmn +.5) ; k = k +1;
92 Mi (b , l ) = sum ( sum ( Mrmat .* tmp ) ) /
Mrmn ; l = l +1;
93 end
94 end
95 end
96 end
97 endfunction
98
99 //MAIN PROGRAM
100 I = ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Chaya Lab \ s c i l a b \
cameraman . j p e g ’ ;
101 block_size = 2;
102 // e x e c ( ’ b t c i m a g e . s c i ’ )
103 // e x e c ( ’ C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Chaya Lab \
s c i l a b \ btcimage . sci ’ ) ;
104 out_put = btcimage (I , block_size ) ;
cameraman.jpeg
35
Figure 5.1: Exp5
36
Figure 5.2: Exp5
37
Experiment: 6
1 // C a p t i o n : Program t o g e n e r a t e and p l o t d i f f e r e n t
basic sequences
2 clear all ;
3 clc ;
4 close ;
5 // G e n e r a t i o n o f U n i t I m p u l s e s i g n a l
6 L = 4; // U p p e r l i m i t
7 n = -L : L ;
8 x = [ zeros (1 , L ) ,1 , zeros (1 , L ) ];
9
10 b = gca () ;
11 b . y_location = ” m i d d l e ” ;
12 plot2d3 ( ’ gnn ’ ,n , x )
13 a = gce () ;
14 a . children (1) . thickness =4;
15 xtitle ( ’ G r a p h i c a l R e p r e s e n t a t i o n o f U n i t Sample
Sequence ’ , ’ n ’ , ’ x [ n ] ’ );
16 // G e n e r a t i o n o f U n i t S t e p S i g n a l
17 L = 10; // U p p e r l i m i t
38
18 t = -L : L ;
19 x = [ zeros (1 , L ) , ones (1 , L +1) ];
20 figure (1)
21 subplot (2 ,1 ,1)
22 a = gca () ;
23 a . thickness =2;
24 a . y_location = ” m i d d l e ” ;
25 plot2d2 (t , x )
26 xtitle ( ’ G r a p h i c a l R e p r e s e n t a t i o n o f U n i t S t e p S i g n a l
’ , ’ t ’ , ’ x ( t ) ’ );
27 // G e n e r a t i o n o f U n i t S t e p S e q u e n c e
28 L = 4; // U p p e r l i m i t
29 n = -L : L ;
30 x = [ zeros (1 , L ) , ones (1 , L +1) ];
31 subplot (2 ,1 ,2)
32 a = gca () ;
33 a . thickness = 2;
34 a . y_location = ” m i d d l e ” ;
35 plot2d3 ( ’ gnn ’ ,n , x )
36 xtitle ( ’ G r a p h i c a l R e p r e s e n t a t i o n o f U n i t S t e p
Sequence ’ , ’ n ’ , ’ x [ n ] ’ );
37 // G e n e r a t i o n o f Ramp S e q u e n c e
38 L = 4; // U p p e r l i m i t
39 n = -L : L ;
40 x = [ zeros (1 , L ) ,0: L ];
41 figure (2)
42 subplot (2 ,1 ,1)
43 b = gca () ;
44 b . y_location = ’ m i d d l e ’ ;
45 plot2d3 ( ’ gnn ’ ,n , x )
46 a = gce () ;
47 a . children (1) . thickness =2;
48 xtitle ( ’ G r a p h i c a l R e p r e s e n t a t i o n o f D i s c r e t e U n i t
Ramp S e q u e n c e ’ , ’ n ’ , ’ x [ n ] ’ ) ;
49 // G e n e r a t i o n o f Ramp S i g n a l
50 L = 4; // U p p e r l i m i t
51 t = -L : L ;
52 x = [ zeros (1 , L ) ,0: L ];
39
53 subplot (2 ,1 ,2)
54 b = gca () ;
55 b . y_location = ’ m i d d l e ’ ;
56 plot2d (n , x )
57 a = gce () ;
58 a . children (1) . thickness =2;
59 xtitle ( ’ G r a p h i c a l R e p r e s e n t a t i o n o f D i s c r e t e U n i t
Ramp S e q u e n c e ’ , ’ t ’ , ’ x ( t ) ’ ) ;
60 // G e n e r a t i o n o f E x p o n e n t i a l l y I n c r e a s i n g s i g n a l
61 a =1.5;
62 n = 0:10;
63 x = (a)^n;
64 figure (3)
65 subplot (2 ,1 ,1)
66 a = gca () ;
67 a . thickness = 2;
68 a . x_location = ” o r i g i n ” ;
69 a . y_location = ” o r i g i n ” ;
70 plot2d3 ( ’ gnn ’ ,n , x )
71 xtitle ( ’ G r a p h i c a l R e p r e s e n t a t i o n o f E x p o n e n t i a l
I n c r e a s i n g S i g n a l ’ , ’ n ’ , ’ x [ n ] ’ );
72 // G e n e r a t i o n o f E x p o n e n t a i l l y D e c r e a s i n g S i g n a l
73 a =0.5;
74 n = 0:10;
75 x = (a)^n;
76 subplot (2 ,1 ,2)
77 a = gca () ;
78 a . thickness = 2;
79 a . x_location = ” o r i g i n ” ;
80 a . y_location = ” o r i g i n ” ;
81 plot2d3 ( ’ gnn ’ ,n , x )
82 xtitle ( ’ G r a p h i c a l R e p r e s e n t a t i o n o f E x p o n e n t i a l
D e c r e a s i n g S i g n a l ’ , ’ n ’ , ’ x [ n ] ’ );
40
Figure 6.1: Exp6a
1 // C a p t i o n : Program t o D e m o n s t r a t e t h e s i g n a l F o l d i n g
2 clc ;
3 clear ;
4 x = input ( ’ E n t e r t h e i n p u t s e q u e n c e := ’ ) ;
5 m = length ( x ) ;
6 lx = input ( ’ E n t e r t h e s t a r t i n g p o i n t o f o r i g i n a l
s i g n a l= ’ );
7 hx = lx +m -1;
8 n = lx :1: hx ;
9 subplot (2 ,1 ,1)
10 a = gca () ;
11 a . x_location = ” o r i g i n ” ;
41
Figure 6.2: Exp6a
42
Figure 6.3: Exp6b
43
12 a . y_location = ” o r i g i n ” ;
13 a . data_bounds = [ -5 ,0;5 ,5];
14 plot2d3 ( ’ gnn ’ ,n , x )
15 xlabel ( ’ n===> ’ )
16 ylabel ( ’ Amplitude −−−> ’ )
17 title ( ’ O r i g i n a l S e q u e n c e ’ )
18 subplot (2 ,1 ,2)
19 a = gca () ;
20 a . x_location = ” o r i g i n ” ;
21 a . y_location = ” o r i g i n ” ;
22 a . data_bounds = [ -5 ,0;5 ,5];
23 plot2d3 ( -n , x )
24 xlabel ( ’ n===> ’ )
25 ylabel ( ’ Amplitude −−−> ’ )
26 title ( ’ F o l d e d S e q u e n c e ’ )
27 // Example
28
29 // E n t e r t h e i n p u t s e q u e n c e : = [ 1 , 2 , 3 , 2 , 5 ]
30 //
31 // E n t e r t h e s t a r t i n g p o i n t o f o r i g i n a l s i g n a l =−1
1 // C a p t i o n : Program t o d e m o n s t r a t e t h e A m p l i t u d e &
Time S c a l i n g o f a s i g n a l
2 clc ;
3 clear ;
4 x = input ( ’ E n t e r i n p u t S e q u e n c e := ’ ) ;
5 m = length ( x ) ;
6 lx = input ( ’ E n t e r s t a r t i n g p o i n t o f o r i g i n a l s i g n a l
:= ’ )
7 hx = lx +m -1;
8 n = lx :1: hx ;
44
Figure 6.4: Exp6c
45
9 subplot (2 ,2 ,1)
10 a = gca () ;
11 a . x_location = ” o r i g i n ” ;
12 a . y_location = ” o r i g i n ” ;
13 a . data_bounds = [ -10 ,0;10 ,10];
14 plot2d3 ( ’ gnn ’ ,n , x )
15 xlabel ( ’ n====> ’ )
16 ylabel ( ’ Amplitude −−−−> ’ )
17 title ( ’ o r g i n a l s e q u e n c e ’ )
18 // A m p l i t u d e S c a l i n g
19 a = input ( ’ A m p l i t u d e S c a l i n g F a c t o r := ’ )
20 y =a*x;
21 subplot (2 ,2 ,2)
22 a = gca () ;
23 a . x_location = ” o r i g i n ” ;
24 a . y_location = ” o r i g i n ” ;
25 a . data_bounds = [ -10 ,0;10 ,10];
26 plot2d3 ( ’ gnn ’ ,n , y )
27 xlabel ( ’ n====> ’ )
28 ylabel ( ’ Amplitdue −−−−> ’ )
29 title ( ’ A m p l i t u d e S c a l e d S e q u e n c e ’ )
30 // Time S c a l i n g −C o m p r e s s i o n
31 C = input ( ’ E n t e r C o m p r e s s i o n f a c t o r −Time S c a l i n g
factor ’)
32 n = lx / C :1/ C : hx / C ;
33 subplot (2 ,2 ,3)
34 a = gca () ;
35 a . x_location = ” o r i g i n ” ;
36 a . y_location = ” o r i g i n ” ;
37 a . data_bounds = [ -10 ,0;10 ,10];
38 plot2d3 ( ’ gnn ’ ,n , x )
39 xlabel ( ’ n===> ’ )
40 ylabel ( ’ Amplitude −−−> ’ )
41 title ( ’ Compressed S e q u e n c e ’ )
42 // Time S c a l i n g −E x p a n s i o n
43 d = input ( ’ E n t e r E x t e n s i o n f a c t o r −Time S c a l i n g
factor ’)
44 n = lx * d : d : hx * d ;
46
45 subplot (2 ,2 ,4)
46 a = gca () ;
47 a . x_location = ” o r i g i n ” ;
48 a . y_location = ” o r i g i n ” ;
49 a . data_bounds = [ -10 ,0;10 ,10];
50 plot2d3 ( ’ gnn ’ ,n , x )
51 xlabel ( ’ n===> ’ )
52 ylabel ( ’ Amplitude −−−> ’ )
53 title ( ’ Extended S e q u e n c e ’ )
54 // Example
55 // E n t e r i n p u t S e q u e n c e : = [ 1 , 2 , 3 , 4 , 5 ]
56 //
57 // E n t e r s t a r t i n g p o i n t o f o r i g i n a l s i g n a l := 2
58 //
59 // A m p l i t u d e S c a l i n g F a c t o r := 2
60 //
61 // E n t e r C o m p r e s s i o n f a c t o r −Time S c a l i n g f a c t o r 2
62 //
63 // E n t e r E x t e n s i o n f a c t o r −Time S c a l i n g f a c t o r 2
1 // C a p t i o n : Program t o d e m o n s t r a t e t h e s h i f t i n g o f t h e
d i s c r e t e time s i g n a l
2 clc ;
3 clear ;
4 close ;
5 x = input ( ’ E n t e r t h e i n p u t s e q u e n c e := ’ )
6 m = length ( x ) ;
7 lx = input ( ’ E n t e r t h e s t a r t i n g p o i n t o f o r i g i n a l
s i g n a l := ’ )
8 hx = lx +m -1;
9 n = lx :1: hx ;
47
Figure 6.5: Exp6d
10 subplot (3 ,1 ,1)
11 a = gca () ;
12 a . x_location = ” o r i g i n ” ;
13 a . y_location = ” o r i g i n ” ;
14 a . data_bounds = [ -10 ,0;10 ,10];
15 plot2d3 ( ’ gnn ’ ,n , x ) ;
16 xlabel ( ’ n===> ’ )
17 ylabel ( ’ Amplitdue −−−> ’ )
18 title ( ’ O r i g i n a l S e q u e n c e ’ )
19 //
20 d = input ( ’ E n t e r t h e d e l a y := ’ )
21 n = lx + d :1: hx + d ;
22 subplot (3 ,1 ,2)
23 a = gca () ;
24 a . x_location = ” o r i g i n ” ;
25 a . y_location = ” o r i g i n ” ;
26 a . data_bounds = [ -10 ,0;10 ,10];
27 plot2d3 ( ’ gnn ’ ,n , x )
28 xlabel ( ’ n===> ’ )
48
29 ylabel ( ’ Amplitude −−−> ’ )
30 title ( ’ D e l a y e d S e q u e n c e ’ )
31 //
32 a = input ( ’ E n t e r t h e a d v a n c e := ’ )
33 n = lx - a :1: hx - a ;
34 subplot (3 ,1 ,3)
35 a = gca () ;
36 a . x_location = ” o r i g i n ” ;
37 a . y_location = ” o r i g i n ” ;
38 a . data_bounds = [ -10 ,0;10 ,10];
39 plot2d3 ( ’ gnn ’ ,n , x )
40 xlabel ( ’ n===> ’ )
41 ylabel ( ’ Amplitude −−−> ’ )
42 title ( ’ Advanced S e q u e n c e ’ )
43 // Example
44 // E n t e r t h e i n p u t s e q u e n c e : = [ 1 , 2 , 3 , 4 , 5 ]
45 //
46 // E n t e r t h e s t a r t i n g p o i n t o f o r i g i n a l s i g n a l :=0
47 //
48 // E n t e r t h e d e l a y :=2
49 //
50 // E n t e r t h e a d v a n c e :=3
49
Experiment: 7
1 // Note : D e t a i l s o f s c i l a b s o f t w a r e v e r s i o n and OS
v e r s i o n used :
2 //OS : Windows 7
3 // S c i l a b v e r s i o n : 5 . 4 . 1
4 // IPD Atom v e r s i o n : 8 . 3 . 1 − 2
5 // SIVP Atom v e r s i o n : 0 . 5 . 3 . 1 − 2
6 // 5 .PROGRAM TO IMPLEMENT DISCRETE FOURIER TRANSFORM
7 //DFT
8 clc ;
9 close ;
10 clear all ;
11 N = input ( ’ Howmany p o i n t DFT do you want ? ’ ) ;
12 x2 = input ( ’ E n t e r t h e s e q u e n c e= ’ ) ;
13 n2 = length ( x2 ) ;
14 c = zeros ( N ) ;
15 x2 =[ x2 zeros (1 ,N - n2 ) ];
16 for k =1: N
50
Figure 7.1: Exp7
51
17 for n =1: N
18 w = exp (( -2* %pi * %i *( k -1) *( n -1) ) / N ) ;
19 x(n)=w;
20 c (k , n ) = x ( n ) ;
21 end
22
23 end
24 r = x2 * c ;
25 // p l o t t i n g m a g n i t u d e and a n g l e
26 subplot (2 ,1 ,1)
27 plot2d3 ( ’ gnn ’ ,0:N -1 , abs ( r ) ,2) ;
28 title ( ’DFT−a b s o l u t e v a l u e ’ ) ;
29 subplot (2 ,1 ,2)
30 a = gca ()
31 plot2d3 ( ’ gnn ’ ,0:N -1 , atan ( imag ( r ) ./( real ( r ) +0.0001) )
,5) ;
32 a . x_location = ” o r i g i n ” ;
33 title ( ’DFT−a n g l e ’ ) ;
34 disp (r , ’ D i s c r e t e F o u r i e r T r a n s f o r m R e s u l t ’ )
35 //RESULT
36 // Example 1
37 //Howmany p o i n t DFT do you want ? 4
38 // E n t e r t h e s e q u e n c e = [ 1 , 2 , 3 , 4 ]
39 // D i s c r e t e F o u r i e r T r a n s f o r m R e s u l t
40 // 1 0 . − 2 . + 2 . i − 2 . − 9 . 7 9 7D−16 i − 2 . − 2 . i
41 //
42 // Example 2
43 //Howmany p o i n t DFT do you want ?8
44 // E n t e r t h e s e q u e n c e = [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ]
45 // D i s c r e t e F o u r i e r T r a n s f o r m R e s u l t
46 // column 1 t o 5
47 //
48 // 8 . − 5 . 5 5 1D−16 + 2 . 2 2 0D−16 i − 4 . 2 8 6D−16 −
4 . 4 4 1D−16 i − 2 . 2 2 0D−16 + 8 . 8 8 2D−16 i − 4 . 8 9 9D−16
i
49 //
50 // column 6 t o 8
51 //
52
52 // − 2 . 1 0 9D−15 − 1 . 2 2 1D−15 i − 2 . 9 3 3D−15 − 6 . 6 6 1D
−16 i 3 . 5 5 3D−15 + 1 . 1 1 0D−15 i
53 //
54 // Example 3
55 //Howmany p o i n t DFT do you want ? 8
56 // E n t e r t h e s e q u e n c e= [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ]
57 // D i s c r e t e F o u r i e r T r a n s f o r m R e s u l t
58 //
59 //
60 // column 1 t o 7
61 //
62 // 28. − 4. + 9.6568542 i − 4. + 4. i − 4. +
1 . 6 5 6 8 5 4 2 i − 4 . − 3 . 4 2 9D−15 i − 4 . − 1 . 6 5 6 8 5 4 2 i
− 4. − 4. i
63 //
64 // column 8
65 //
66 // − 4 . − 9 . 6 5 6 8 5 4 2 i
67 //
53
Experiment: 8
1 // C a p t i o n : To D e s i g n an Low P a s s FIR F i l t e r
2 // F i l t e r Length =5 , Order = 4
3 // Window = R e c t a n g u l a r Window
4 clc ;
5 clear ;
6 xdel ( winsid () ) ;
7 fc = input ( ” E n t e r Analog c u t o f f f r e q . i n Hz=” )
8 fs = input ( ” E n t e r Analog s a m p l i n g f r e q . i n Hz=” )
9 M = input ( ” E n t e r o r d e r o f f i l t e r =” )
10 w = (2* %pi ) *( fc / fs ) ;
11 disp (w , ’ D i g i t a l c u t o f f f r e q u e n c y i n r a d i a n s . c y c l e s /
samples ’ );
12 wc = w / %pi ;
13 disp ( wc , ’ N o r m a l i z e d d i g i t a l c u t o f f f r e q u e n c y i n
c y c l e s / samples ’ );
14 [ wft , wfm , fr ]= wfir ( ’ l p ’ ,M +1 ,[ wc /2 ,0] , ’ r e ’ ,[0 ,0]) ;
15 disp ( wft , ’ I m p u l s e R e s p o n s e o f LPF FIR F i l t e r : h [ n ]= ’ )
;
16 // P l o t t i n g t h e Magnitude R e s p o n s e o f LPF FIR F i l t e r
54
Figure 8.1: Exp8
17 subplot (2 ,1 ,1)
18 plot (2* fr , wfm )
19 xlabel ( ’ N o r m a l i z e d D i g i t a l F r e q u e n c y w−−−> ’ )
20 ylabel ( ’ Magnitude | H(w) |= ’ )
21 title ( ’ Magnitude R e s p o n s e o f FIR LPF ’ )
22 xgrid (1)
23 subplot (2 ,1 ,2)
24 plot ( fr * fs , wfm )
25 xlabel ( ’ Analog F r e q u e n c y i n Hz f −−−> ’ )
26 ylabel ( ’ Magnitude | H(w) |= ’ )
27 title ( ’ Magnitude R e s p o n s e o f FIR LPF ’ )
28 xgrid (1)
29 // Example
30 // E n t e r Analog c u t o f f f r e q . i n Hz= 250
31 //
32 // E n t e r Analog s a m p l i n g f r e q . i n Hz= 2 0 0 0
33 //
34 // E n t e r o r d e r o f f i l t e r = 4
35 //
55
36 // D i g i t a l c u t o f f f r e q u e n c y i n r a d i a n s . c y c l e s /
samples
37 //
38 // 0.7853982
39 //
40 // N o r m a l i z e d d i g i t a l c u t o f f f r e q u e n c y i n c y c l e s /
samples
41 //
42 // 0.25
43 //
44 // I m p u l s e R e s p o n s e o f LPF FIR F i l t e r : h [ n ]=
45 //
46 // 0.1591549 0.2250791 0.25 0.2250791
0.1591549
56
Experiment: 9
1 // Note : D e t a i l s o f s c i l a b s o f t w a r e v e r s i o n and OS
v e r s i o n used :
2 //OS : Windows 7
3 // S c i l a b v e r s i o n : 5 . 4 . 1
4 // IPD Atom v e r s i o n : 8 . 3 . 1 − 2
5 // SIVP Atom v e r s i o n : 0 . 5 . 3 . 1 − 2
6 // 1 . Q u a n t i z a t i o n and s a m p l i n g
7
8 // Q u a n t i z e a s i g n a l t o n b i t s . This code assumes
t h e s i g n a l i s b e t w e e n −1
9 // and +1.
10 clc ;
11 clear all ;
12 close ;
13 n =8; // Number o f b i t s ;
14 m = 120; // Number o f s a m p l e s ;
15 t = 2* %pi *[0:( m -1) ]/ m ;
57
Figure 9.1: Exp9
16 x = sin ( t ) ; // s i g n a l b e t w e e n −1 and 1 .
17 // T r y i n g ” s i n ( ) ”
instead of ”
sawtooth ”
18 // r e s u l t s i n more
interesting error
( to the
19 // e x t e n t t h a t e r r o r
is interesting ) .
20 x ( find (x >=1) ) =(1 - %eps ) ; // Make s i g n a l from −1
to j u s t l e s s than 1 .
21 xq = floor (( x +1) *2^( n -1) ) ; // S i g n a l i s one o f 2ˆ n
i n t v a l u e s ( 0 t o 2ˆ n −1)
22 xq = xq /(2^( n -1) ) ; // S i g n a l i s from 0 t o 2 (
quantized )
23 xq = xq -(2^( n ) -1) /2^( n ) ; // S h i f t s i g n a l down (
rounding )
24
25 xe =x - xq ; // E r r o r
58
26 subplot (3 ,1 ,1)
27 plot2d3 ( ’ gnn ’ ,1: length ( x ) ,x ) ;
28 title ( sprintf ( ’ S i g n a l , Q u a n t i z e d s i g n a l and E r r o r
f o r %g b i t s , %g q u a n t i z a t i o n l e v e l s ’ ,n ,2^ n ) ) ;
29 disp (x , ’ e x a c t v a l u e ’ )
30 subplot (3 ,1 ,2)
31 plot2d3 ( ’ gnn ’ ,1: length ( xq ) ,xq ,2) ;
32 title ( ’ Q u a n t i z e d V a l u e ’ )
33 disp ( xq , ’ Q u a n t i z e d v a l u e ’ )
34 subplot (3 ,1 ,3)
35 plot2d3 ( ’ gnn ’ ,1: length ( xe ) ,xe ,5) ;
36 title ( ’ Q u a n t i z a t i o n E r r o r o r Q u a n t i z a t i o n N o i s e ’ )
37 disp ( xe , ’ Q u a n t i z a t i o n e r r o r o r n o i s e ’ )
59
Experiment: 10
1 // S t e p r e s p o n s e o f d i s c r e t e t i m e s y s t e m s
2 // R e f e r Exp10a . x c o s f i l e f o r s i m u l i n k a n a l y s i s
1 // S t e p r e s p o n s e o f C o n t i n u o u s t i m e s y s t e m s
2 // R e f e r Exp10b . x c o s f i l e f o r s i m u l i n k a n a l y s i s
60
Figure 10.1: Exp10a
61
This code can be downloaded from the website wwww.scilab.in
62
Experiment: 11
1 // Note : D e t a i l s o f s c i l a b s o f t w a r e v e r s i o n and OS
v e r s i o n used :
2 //OS : Windows 7
3 // S c i l a b v e r s i o n : 5 . 4 . 1
4 // IPD Atom v e r s i o n : 8 . 3 . 1 − 2
5 // SIVP Atom v e r s i o n : 0 . 5 . 3 . 1 − 2
6 clc ;
7 clear all ;
8 close ;
9 n = 6; // f i l t e r o r d e r
10 Wn = [2.5 e6 ,29 e6 ]/500 e6 ; // n o r m a l i z e d c u t o f f
f r e q u e n c i e s [ lower , upper ]
11 ftype = ’ bp ’ ; // b a n d p a s s f i l t e r
12 fdesign = ’ b u t t ’ ; // B u t t e r w o r t h F i l t e r
13 delta =[];
14 hz = iir (n , ftype , fdesign , Wn /2 , delta )
15 [p ,z , g ]= iir (n , ftype , fdesign , Wn /2 , delta )
63
Figure 11.1: Exp11
64
16 [ hzm , fr ]= frmag ( hz ,256) ;
17 plot2d ( fr ’ , hzm ’) ;
18 xtitle ( ’ D i s c r e t e I I R f i l t e r band p a s s 0.005 < f r <
0 . 0 5 8 ’ , ’ ’ , ’ ’ );
19 xgrid (1)
20 // R e s u l t
21
22 //−−>hz ( 2 )
23 // a n s =
24 //
25 // 2 4
26 // 0.0000002 − 0.0000015 z + 0.0000037 z
27 // 6 8
28 // − 0.0000049 z + 0.0000037 z
29 // 10 12
30 // − 0.0000015 z + 0.0000002 z
31 //
32 //−−>hz ( 3 )
33 // a n s =
34 //
35 // 2
36 // 0.5250468 − 6.6287407 z + 38.377802 z
37 // 3 4
38 // − 134.73451 z + 319.45814 z
39 // 5 6
40 // − 538.91189 z + 663.25134 z
41 // 7 8
42 // − 600.03003 z + 396.0233 z
43 // 9 10
44 // − 185.96443 z + 58.974503 z
45 // 11 12
46 // − 11.340535 z + z
47 //
48 //−−>hz ( 1 )
49 // a n s =
50 //
51 // ! r num den dt !
52 //
65
53 //−−>p
54 // p =
55 //
56 // 0.9964120 − 0.0154005 i
57 // 0.9892502 − 0.0129619 i
58 // 0.9822499 − 0.0060512 i
59 // 0.9822499 + 0.0060512 i
60 // 0.9892502 + 0.0129619 i
61 // 0.9964120 + 0.0154005 i
62 // 0.9464056 + 0.1686845 i
63 // 0.8907712 + 0.1177110 i
64 // 0.8651786 + 0.0429743 i
65 // 0.8651786 − 0.0429743 i
66 // 0.8907712 − 0.1177110 i
67 // 0.9464056 − 0.1686845 i
68 //
69 //−−>z
70 // z =
71 //
72 // 1.
73 // 1.
74 // 1.
75 // 1.
76 // 1.
77 // 1.
78 // − 1 .
79 // − 1 .
80 // − 1 .
81 // − 1 .
82 // − 1 .
83 // − 1 .
84 //
85 //−−>g
86 // g =
87 //
88 // 0.0000002
89 //
66
Experiment: 12
1 // Note : D e t a i l s o f s c i l a b s o f t w a r e v e r s i o n and OS
v e r s i o n used :
2 //OS : Windows 7
3 // S c i l a b v e r s i o n : 5 . 4 . 1
4 // IPD Atom v e r s i o n : 8 . 3 . 1 − 2
5 // SIVP Atom v e r s i o n : 0 . 5 . 3 . 1 − 2
6 clc ;
7 clear all ;
8 close ;
9 s = poly (0 , ’ s ’ ) ;
10 // The p a r a m e t e r s 1 . A n g u l a r P o s i t i o n 2 . A n g u l a r
V e l o c i t y o f DC Motors
11 // a r e o b t a i n e d from MATLAB demos f i l e .
12 Angular_Position =(0.003127* s +0.9815) /( s ^2+3.929* s
+6.343 e -05) ;
13 Angular_velocity = (1.04* s +0.2756) /( s ^2+4.461* s
+1.096) ;
67
Figure 12.1: Exp12
68
14 model = [ Angular_Position , Angular_velocity ];
15 H1 = model (: ,1) ; // A n g u l a r P o s i t i o n
16 H2 = model (: ,2) ; // A n g u l a r v e l o c i t y
17 np =20; // number o f p o i n t s
18 t = 0:0.02:20;
19 ysd1 = csim ( ’ i m p u l s e ’ ,t , model (: ,1) ) ;
20 ysd2 = csim ( ’ i m p u l s e ’ ,t , model (: ,2) ) ;
21 subplot (2 ,1 ,1)
22 plot (t , ysd1 , ’ . −b ’ )
23 title ( ’ I m p u l s e R e s p o n s e − A n g u l a r P o s i t i o n ’ )
24 xgrid (1)
25 subplot (2 ,1 ,2)
26 plot (t , ysd2 , ’ . − r ’ )
27 title ( ’ I m p u l s e r e s p o n s e −A n g u l a r v e l o c i t y ’ )
28 xgrid (1)
29 disp ( model , ’ Model System E q u a t i o n s = ’ )
30 disp ( ysd1 , ’ I m p u l s e R e s p o s n e o f A n g u l a r P o s i t i o n = ’ )
31 disp ( ysd2 , ’ I m p u l s e R e s p o n s e o f A n g u l a r v e l o c i t y = ’ )
32
33 //RESULT
34 // Model System E q u a t i o n s =
35 //
36 // 0.9815 + 0.003127 s 0.2756 + 1.04 s
37 // −−−−−−−−−−−−−−−−−−−−−− −−−−−−−−−−−−−−−−−−
38 // 2 2
39 // 0.0000634 + 3.929 s + s 1.096 + 4.461 s + s
69
Experiment: 13
1 // Note : D e t a i l s o f s c i l a b s o f t w a r e v e r s i o n and OS
v e r s i o n used :
2 //OS : Windows 7
3 // S c i l a b v e r s i o n : 5 . 4 . 1
4 // IPD Atom v e r s i o n : 8 . 3 . 1 − 2
5 // SIVP Atom v e r s i o n : 0 . 5 . 3 . 1 − 2
6 // 3 . CIRCULAR CONVOLUTION OF TWO SEQUENCES
7 clc ;
8 close ;
9 clear all ;
10 a1 = input ( ’ 1 s t S e q u e n c e x : ’ )
11 b1 = input ( ’ 2 nd S e q u e n c e h : ’ )
12 ax = length ( a1 ) ;
13 bx = length ( b1 ) ;
14 n = max ( ax , bx ) ;
15 n3 = ax - bx ;
16 if ( n3 <=0)
70
Figure 13.1: Exp13
17 a1 =[ a1 , zeros (1 , - n3 ) ];
18 else
19 b1 =[ b1 , zeros (1 , n3 ) ];
20 end
21 for r = 1: n
22 y ( r ) =0;
23 for i =1: n
24 j =r - i +1;
25 if (j <=0)
26 j=j+n;
27 end
28 y ( r ) = y ( r ) + b1 ( j ) * a1 ( j ) ;
29 end
30 end
31 disp (y , ’ c i r c u l a r c o n v l o u t i o n r e s u l t ’ )
32
33 subplot (3 ,1 ,1) ;
34 plot2d3 ( ’ gnn ’ , a1 ) ;
35 xlabel ( ’ n ’ ) ;
71
36 ylabel ( ’ a ( n ) ’ ) ;
37 title ( ’ f i r s t s e q u e n c e ’ ) ;
38 subplot (3 ,1 ,2) ;
39 plot2d3 ( ’ gnn ’ , b1 ) ;
40 xlabel ( ’ n ’ ) ;
41 ylabel ( ’ b ( n ) ’ ) ;
42 title ( ’ s e c o n d s e q u e n c e ’ ) ;
43 subplot (3 ,1 ,3) ;
44 plot2d3 ( ’ gnn ’ ,y ) ;
45 xlabel ( ’ n ’ ) ;
46 ylabel ( ’ y ( n ) ’ ) ;
47 title ( ’ c i r c u l a r c o n v o l u t i o n s e q u e n c e ’ ) ;
48
49 //RESULT
50 // Example 1
51 // 1 s t S e q u e n c e x : [ 1 , 2 , 3 , 4 ]
52 // 2 nd S e q u e n c e h : [ 1 , 1 , 1 , 1 ]
53 //
54 // c i r c u l a r c o n v l o u t i o n r e s u l t
55 //
56 // 10. 10. 10. 10.
57 //
58 // Example 2
59 // 1 s t S e q u e n c e x : [ 1 , 2 , 3 , 4 ]
60 // 2 nd S e q u e n c e h : [ 1 , 1 , 1 ]
61 //
62 // c i r c u l a r c o n v l o u t i o n r e s u l t
63 //
64 // 6. 6. 6. 6.
72
Experiment: 14
1 // Note : D e t a i l s o f s c i l a b s o f t w a r e v e r s i o n and OS
v e r s i o n used :
2 //OS : Windows 7
3 // S c i l a b v e r s i o n : 5 . 4 . 1
4 // IPD Atom v e r s i o n : 8 . 3 . 1 − 2
5 // SIVP Atom v e r s i o n : 0 . 5 . 3 . 1 − 2
6 // 4 . program f o r l i n e a r c o n v o l u t i o n o f t o s e q u e n c e
7 clc ;
8 clear all ;
9 close ;
10 x = input ( ’ e n t e r t h e f i r s t s e q u e n c e ’ ) ;
11 y = input ( ’ e n t e r t h e s e c o n d s e q u e n c e ’ ) ;
12 m = length ( x ) ;
13 n = length ( y ) ;
14 p = m +n -1;
15 for i =1: p
16 q=i;
17 k =0;
18 for j =1: i
73
19 if q > m
20 q =q -1;
21 elseif j > n
22 k=k;
23 else k = x ( q ) * y ( j ) + k ;
24 q =q -1;
25 end
26 end
27 z(i)=k;
28 end
29 disp (z , ’ c o n v o l u t i o n o f two s e q u e n c e i s : ’ )
30
31 //RESULT
32 // e n t e r t h e f i r s t s e q u e n c e [ 1 , 2 , 3 ]
33 // e n t e r t h e s e c o n d s e q u e n c e [ 1 , 1 , 1 , 1 ]
34 //
35 // c o n v o l u t i o n o f two s e q u e n c e i s :
36 //
37 // 1.
38 // 3.
39 // 6.
40 // 6.
41 // 5.
42 // 3.
43 //
74
Appendix
75
Cameraman Image file
76
Rice
Image File
77
Hes-
tian Colour Image File
78
Lenna Image File
79