Scilab Manual for
Digital Signal Processing
              by Mr Vijay P Sompur
              Electronics Engineering
       Visvesvraya Technological University1
                          Solutions provided by
                Mr. R.Senthilkumar- Assistant Professor
                         Electronics Engineering
              Institute of Road and Transport Technology
                              June 26, 2020
   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                                       4
1 Verification of Sampling theorem.                            6
2 Impulse response of a given system                          11
3 Linear Circular convolution of two given sequences          14
4 Autocorrelation of a given sequence and verification of its
  properties.                                                 18
5 Cross correlation of given sequences and verification of its
  properties.                                                  21
6 Solving a given difference equation.                        24
7 Computation of N point DFT of a given sequence and to
  plot magnitude and phase spectrum.                    26
8 Linear convolution of two sequences using DFT and IDFT.     30
9 Circular convolution of two given sequences using DFT and
  IDFT                                                      33
10 Design and implementation of FIR filter to meet given spec-
   ifications.                                                 35
11 Design and implementation of IIR filter to meet given spec-
   ifications.                                                 39
                                2
12 Circular convolution of two given sequences   49
                               3
List of Experiments
 Solution 1.1    Verification of Sampling Theorem . . . . . . . . .         6
 Solution 2.2    Program to find impulse response and Frequency
                 Response of a system . . . . . . . . . . . . . . . .      11
 Solution 3.1    Program to Compute the Convolution of Two Se-
                 quences . . . . . . . . . . . . . . . . . . . . . . .     14
 Solution 4.1    Program to Compute the Autocorrelation of a Se-
                 quence And verfication of Autocorrelation property        18
 Solution 5.1    Program to Compute the Crosscorrelation of a Se-
                 quence And verfication of crosscorrelation property       21
 Solution 6.1    Solving Difference Equation Direct Form II Real-
                 ization . . . . . . . . . . . . . . . . . . . . . . . .   24
 Solution 7.1    Program to find the spectral information of discrete
                 time signal Calculation of DFT and IDFT . . . .           26
 Solution 8.1    Linear Convolution using Circular Convolution DFT
                 IDFT method . . . . . . . . . . . . . . . . . . . .       30
 Solution 9.1    Circular Convolution using DFT IDFT method .              33
 Solution 10.1   To Design an Low Pass FIR Filter . . . . . . . . .        35
 Solution 11.1   To obtain Digital IIR Butterworth low pass filter
                 Frequency response . . . . . . . . . . . . . . . . .      39
 Solution 11.2   To obtain Digital IIR Chebyshev low pass filter Fre-
                 quency response . . . . . . . . . . . . . . . . . . .     43
 Solution 12.1   Program to perform circular convolution of two se-
                 quences . . . . . . . . . . . . . . . . . . . . . . .     49
                                    4
List of Figures
 1.1   Verification of Sampling Theorem . . . . . . . . . . . . . . .         9
 1.2   Verification of Sampling Theorem . . . . . . . . . . . . . . .        10
 2.1   Program to find impulse response and Frequency Response of
       a system . . . . . . . . . . . . . . . . . . . . . . . . . . . . .    12
 3.1   Program to Compute the Convolution of Two Sequences . .               15
 7.1   Program to find the spectral information of discrete time signal
       Calculation of DFT and IDFT . . . . . . . . . . . . . . . . .         27
 8.1   Linear Convolution using Circular Convolution DFT IDFT
       method . . . . . . . . . . . . . . . . . . . . . . . . . . . . .      31
 10.1 To Design an Low Pass FIR Filter . . . . . . . . . . . . . . .         36
 11.1 To obtain Digital IIR Butterworth low pass filter        Frequency
      response . . . . . . . . . . . . . . . . . . . . . . .   . . . . . .   40
 11.2 To obtain Digital IIR Chebyshev low pass filter          Frequency
      response . . . . . . . . . . . . . . . . . . . . . . .   . . . . . .   44
                                     5
     Experiment: 1
     Verification of Sampling
     theorem.
     Scilab code Solution 1.1 Verification of Sampling Theorem
 1   // C a p t i o n : V e r i f i c a t i o n o f S a m p l i n g Theorem
 2   // [ 1 ] . R i g h t S a m p l i n g [ 2 ] . Under S a m p l i n g [ 3 ] . Over
          Sampling
 3   clc ;
 4   close ;
 5   clear ;
 6   fm = input ( ’ E n t e r t h e i n p u t s i g n a l f r e q u e n c y : ’ ) ;
 7   k = input ( ’ E n t e r t h e number o f C y c l e s o f i n p u t s i g n a l :
           ’ );
 8   A = input ( ’ E n t e r t h e a m p l i t u d e o f i n p u t s i g n a l : ’ ) ;
 9   tm =0:1/( fm * fm ) : k / fm ;
10   x = A * cos (2* %pi * fm * tm ) ;
11   figure (1) ;
12   a = gca () ;
13   a . x_location = ” o r i g i n ” ;
14   a . y_location = ” o r i g i n ” ;
15   plot ( tm , x ) ;
16   title ( ’ ORIGINAL SIGNAL ’ ) ;
17   xlabel ( ’ Time ’ ) ;
                                             6
18   ylabel ( ’ A m p l i t u d e ’ ) ;
19   xgrid (1)
20   // S a m p l i n g Rate ( N y q u i s t Rate ) =2∗fm
21   fnyq =2* fm ;
22   // UNDER SAMPLING
23   fs =(3/4) * fnyq ;
24   n =0:1/ fs : k / fm ;
25   xn = A * cos (2* %pi * fm * n ) ;
26   figure (2) ;
27   a = gca () ;
28   a . x_location = ” o r i g i n ” ;
29   a . y_location = ” o r i g i n ” ;
30   plot2d3 ( ’ gnn ’ ,n , xn ) ;
31   plot (n , xn , ’ r ’ ) ;
32   title ( ’ Under S a m p l i n g ’ ) ;
33   xlabel ( ’ Time ’ ) ;
34   ylabel ( ’ A m p l i t u d e ’ ) ;
35   legend ( ’ Sampled S i g n a l ’ , ’ R e c o n s t r u c t e d S i g n a l ’ ) ;
36   xgrid (1)
37   //NYQUIST SAMPLING
38   fs = fnyq ;
39   n =0:1/ fs : k / fm ;
40   xn = A * cos (2* %pi * fm * n ) ;
41   figure (3) ;
42   a = gca () ;
43   a . x_location = ” o r i g i n ” ;
44   a . y_location = ” o r i g i n ” ;
45   plot2d3 ( ’ gnn ’ ,n , xn ) ;
46   plot (n , xn , ’ r ’ ) ;
47   title ( ’ N y q u i s t S a m p l i n g ’ ) ;
48   xlabel ( ’ Time ’ ) ;
49   ylabel ( ’ A m p l i t u d e ’ ) ;
50   legend ( ’ Sampled S i g n a l ’ , ’ R e c o n s t r u c t e d S i g n a l ’ ) ;
51   xgrid (1)
52   //OVER SAMPLING
53   fs = fnyq *10;
54   n =0:1/ fs : k / fm ;
55   xn = A * cos (2* %pi * fm * n ) ;
                                               7
56 figure (4) ;
57 a = gca () ;
58 a . x_location = ” o r i g i n ” ;
59 a . y_location = ” o r i g i n ” ;
60 plot2d3 ( ’ gnn ’ ,n , xn ) ;
61 plot (n , xn , ’ r ’ ) ;
62 title ( ’ Over S a m p l i n g ’ ) ;
63 xlabel ( ’ Time ’ ) ;
64 ylabel ( ’ A m p l i t u d e ’ ) ;
65 legend ( ’ Sampled S i g n a l ’ , ’ R e c o n s t r u c t e d S i g n a l ’ ) ;
66 xgrid (1)
67 // R e s u l t
68 // E n t e r t h e i n p u t s i g n a l f r e q u e n c y : 1 0 0
69 //
70 // E n t e r t h e number o f C y c l e s o f i n p u t s i g n a l : 2
71 //
72 // E n t e r t h e a m p l i t u d e o f i n p u t s i g n a l : 2
                                              8
Figure 1.1: Verification of Sampling Theorem
                     9
Figure 1.2: Verification of Sampling Theorem
                    10
     Experiment: 2
     Impulse response of a given
     system
     Scilab code Solution 2.2 Program to find impulse response and Frequency
     Response of a system
1    // C a p t i o n : Program t o f i n d i m p u l s e r e s p o n s e and
2    // F r e q u e n c y R e s p o n s e o f a s y s t e m
3    // y [ n ] = a ∗ y [ n−1]+x [ n ]
4    // Assume y [ n ] = h [ n ] , x [ n ]= d e l t a [ n ]= u n i t i m p u l s e
         response
 5   // a = 0 . 9
 6   // h [ n ] = 0 . 9 ∗ h [ n−1]+ d e l t a [ n ]
 7   clc ;
 8   clear ;
 9   close ;
10   a = 0.9; // c o n s t a n t a = 0 . 9 l e s s t h a n 1
11   h0 = 1;
12   h1 = a ; // f i r s t two v a l u e s o f i m p u l s e r e s p o n s e
13   h = [ h0 , h1 , zeros (1 ,100) ];
14   for i = 1:100
15      h ( i +2) = (( a ) ^( i +1) ) * h ( i +1) ; // i m p u l s e r e s p o n s e
                                               11
Figure 2.1: Program to find impulse response and Frequency Response of a
system
                                  12
16   end
17   [ HW , W ] = frmag (h ,512) ; // f r e q u e n c y r e s p o n s e
18   figure (1)
19   subplot (2 ,1 ,1)
20   a = gca () ;
21   a . x_location = ’ o r i g i n ’ ;
22   a . y_location = ’ o r i g i n ’ ;
23   plot ([1: length ( h ) ] ,h , ’ r ’ ) ;
24   xlabel ( ’ D i s c r e t e Time I n d e x n−−−−> ’ ) ;
25   ylabel ( ’ I m p u l s e R e s p o n s e h [ n]−−−−−> ’ ) ;
26   title ( ’ I m p u l s e R e s p o n s e o f f i r s t o r d e r r e c u r s i v e
          system ’ )
27   xgrid (1)
28   subplot (2 ,1 ,2)
29   a = gca () ;
30   a . x_location = ’ o r i g i n ’ ;
31   a . y_location = ’ o r i g i n ’ ;
32   plot ([ mtlb_fliplr ( -2* %pi * W ) ,2* %pi * W (2: $ ) ] ,[
          mtlb_fliplr ( abs ( HW ) ) , abs ( HW (2: $ ) ) ])
33   xlabel ( ’ D i s c r e t e F r e q u e n c y i n d e x W−−−−−−> ’ )
34   ylabel ( ’ Magnitude R e s p o n s e | H(W)|−−−−−−> ’ )
35   title ( ’ F r e q u e n c y R e s p o n s e o f a c a u s a l , s t a b l e , LTI
          I s t Order R e c u r s i v e System ’ ) ;
36   xgrid (1)
                                              13
     Experiment: 3
     Linear Circular convolution of
     two given sequences
     Scilab code Solution 3.1 Program to Compute the Convolution of Two
     Sequences
 1   // C a p t i o n : Program t o Compute t h e C o n v o l u t i o n o f Two
           Sequences
 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 l o w e r i n d e x o f i n p u t s e q u e n c e
         := ’ )
 8   hx = lx +m -1;
 9   n = lx :1: hx ;
10   h = input ( ’ E n t e r i m p u l s e r e s p o n s e s e q u e n c e := ’ )
11   l = length ( h ) ;
12   lh = input ( ’ E n t e r t h e l o w e r i n d e x o f i m p u l s e
         r e s p o n s e := ’ )
13   hh = lh +l -1;
                                            14
Figure 3.1: Program to Compute the Convolution of Two Sequences
                              15
14   g = lh :1: hh ;
15   nx = lx + lh ;
16   nh = nx + m +l -2;
17   y = convol (x , h )
18   r = nx : nh ;
19   figure (1)
20   subplot (3 ,1 ,1)
21   a = gca () ;
22   a . x_location = ” o r i g i n ” ;
23   a . y_location = ” o r i g i n ” ;
24   plot2d3 ( ’ gnn ’ ,n , x )
25   xlabel ( ’ n===> ’ )
26   ylabel ( ’ Amplitude −−> ’ )
27   title ( ’ I n p u t S e q u e n c e x [ n ] ’ )
28   subplot (3 ,1 ,2)
29   a = gca () ;
30   a . x_location = ” o r i g i n ” ;
31   a . y_location = ” o r i g i n ” ;
32   plot2d3 ( ’ gnn ’ ,g , h )
33   xlabel ( ’ n===> ’ )
34   ylabel ( ’ Amplitude −−−> ’ )
35   title ( ’ I m p u l s e R e s p o n s e S e q u e n c e h [ n ]= ’ )
36   subplot (3 ,1 ,3)
37   a = gca () ;
38   a . x_location = ” o r i g i n ” ;
39   a . y_location = ” o r i g i n ” ;
40   plot2d3 ( ’ gnn ’ ,r , y )
41   xlabel ( ’ n===> ’ )
42   ylabel ( ’ Amplitude −−−> ’ )
43   title ( ’ Output R e s p o n s e S e q u e n c e y [ n ]= ’ )
44   // Example
45   // E n t e r t h e i n p u t S e q u e n c e : = [ 1 , 2 , 3 , 1 ]
46   //
47   // E n t e r t h e l o w e r i n d e x o f i n p u t s e q u e n c e :=0
48   //
49   // E n t e r i m p u l s e r e s p o n s e s e q u e n c e : = [ 1 , 2 , 1 , − 1 ]
50   //
51   // E n t e r t h e l o w e r i n d e x o f i m p u l s e r e s p o n s e :=−1
                                                 16
52   //
53   //
54   //−−>y
55   // y =
56   //
57   //     1.   4.   8.   8.    3.   − 2.   − 1.
58   //
                            17
     Experiment: 4
     Autocorrelation of a given
     sequence and verification of its
     properties.
     Scilab code Solution 4.1 Program to Compute the Autocorrelation of a
     Sequence And verfication of Autocorrelation property
 1   // C a p t i o n : Program t o Compute t h e A u t o c o r r e l a t i o n o f
          a Sequence
 2   //And v e r f i c a t i o n o f A u t o c o r r e l a t i o n p r o p e r t y
 3   clc ;
 4   clear ;
 5   close ;
 6   x = input ( ’ E n t e r t h e i n p u t S e q u e n c e := ’ ) ;
 7   m = length ( x ) ;
 8   lx = input ( ’ E n t e r t h e l o w e r i n d e x o f i n p u t s e q u e n c e
         := ’ )
 9   hx = lx +m -1;
10   n = lx :1: hx ;
11   x_fold = x ( $ : -1:1) ;
12   nx = lx + lx ;
13   nh = nx + m +m -2;
14   r = nx : nh ;
                                            18
15 Rxx = convol (x , x_fold ) ;
16 disp ( Rxx , ’ Auto C o r r e l a t i o n Rxx [ n ] : = ’ )
17 // P r o p e r t y 1 : A u t o c o r r e l a t i o n o f a s e q u e n c e h a s e v e n
           symmetry
18 // Rxx [ n ] = Rxx[−n ]
19 Rxx_flip = Rxx ([ $ : -1:1]) ;
20 if Rxx_flip == Rxx then
21      disp ( ’ P r o p e r t y 1 : Auto C o r r e l a t i o n h a s Even
              Symmetry ’ ) ;
22         disp ( Rxx_flip , ’ Auto C o r r e l a t i o n t i m e r e v e r s e d
              Rxx[−n ] : = ’ ) ;
23 end
24 // P r o p e r t y 2 : C e n t e r v a l u e Rxx [ 0 ] =    t o t a l power o f
         the sequence
25 Tot_Px = sum ( x .^2) ;
26 Mid = ceil ( length ( Rxx ) /2) ;
27 if Tot_Px == Rxx ( Mid ) then
28     disp ( ’ P r o p e r t y 2 : Rxx [ 0 ] = c e n t e r v a l u e=max .      v a l u e=
                T o t a l power o f i /p s e q u e n c e ’ ) ;
29 end
30 subplot (2 ,1 ,1)
31 plot2d3 ( ’ gnn ’ ,n , x )
32 xlabel ( ’ n===> ’ )
33 ylabel ( ’ Amplitude −−> ’ )
34 title ( ’ I n p u t S e q u e n c e x [ n ] ’ )
35 subplot (2 ,1 ,2)
36 plot2d3 ( ’ gnn ’ ,r , Rxx )
37 xlabel ( ’ n===> ’ )
38 ylabel ( ’ Amplitude −−> ’ )
39 title ( ’ Auto c o r r e l a t i o n S e q u e n c e Rxx [ n ] ’ )
40 // Example
41 // E n t e r t h e i n p u t S e q u e n c e : = [ 2 , − 1 , 3 , 4 , 1 ]
42 //
43 // E n t e r t h e l o w e r i n d e x o f i n p u t s e q u e n c e :=−2
44 //
45 // Auto C o r r e l a t i o n Rxx [ n ] : =
46 //
47 //         2.      7.         5.         11.           31.           11.  5.
                                               19
         7.        2.
48 //
49 // P r o p e r t y 1 : Auto C o r r e l a t i o n h a s Even Symmetry
50 //
51 // Auto C o r r e l a t i o n t i m e r e v e r s e d Rxx[−n ] : =
52 //
53 //       2.        7.        5.          11.         31.      11.        5.
      7.         2.
54 //
55 // P r o p e r t y 2 : Rxx [ 0 ] = c e n t e r v a l u e=max . v a l u e=T o t a l
      power o f i / p s e q u e n c e
                                             20
     Experiment: 5
     Cross correlation of given
     sequences and verification of its
     properties.
     Scilab code Solution 5.1 Program to Compute the Crosscorrelation of a
     Sequence And verfication of crosscorrelation property
 1   // C a p t i o n : Program t o Compute t h e C r o s s c o r r e l a t i o n
         of a Sequence
 2   //And v e r f i c a t i o n o f c r o s s c o r r e l a t i o n p r o p e r t y
 3   clc ;
 4   clear ;
 5   close ;
 6   x = input ( ’ E n t e r t h e F i r s t i n p u t S e q u e n c e := ’ ) ;
 7   y = input ( ’ E n t e r t h e s e c o n d i n p u t S e q u e n c e := ’ )
 8   mx = length ( x ) ;
 9   my = length ( y ) ;
10   lx = input ( ’ E n t e r t h e l o w e r i n d e x o f f i r s t i n p u t
         s e q u e n c e := ’ )
11   ly = input ( ’ E n t e r t h e l o w e r i n d e x o f s e c o n d i n p u t
         s e q u e n c e := ’ )
12   hx = lx + mx -1;
13   n = lx :1: hx ;
                                             21
14   x_fold = x ( $ : -1:1) ;
15   y_fold = y ( $ : -1:1) ;
16   nx = lx + ly ;
17   ny = nx + mx + my -2;
18   r = nx : ny ;
19   Rxy = convol (x , y_fold ) ;
20   Ryx = convol ( x_fold , y ) ;
21   disp ( Rxy , ’ C r o s s C o r r e l a t i o n Rxy [ n ] : = ’ )
22   count =1;
23   // P r o p e r t y 1 : c r o s s c o r r e l a t i o n o f a s e q u e n c e h a s
         Antisymmetry
24   // Rxy [ n ] = Ryx[−n ]
25   Ryx_flip = Ryx ([ $ : -1:1]) ;
26   for i = 1: length ( Rxy )
27         if ( ceil ( Ryx_flip ( i ) ) == ceil ( Rxy ( i ) ) ) then
28               count = count +1;
29         end
30   end
31   if ( count == length ( Rxy ) ) then
32         disp ( ’ P r o p e r t y 1 : C r o s s C o r r e l a t i o n h a s
                 AntiSymmetry : Rxy [ n ]=Ryx[−n ] ’ ) ;
33   end
34   // P r o p e r t y 2 :% V e r i f i c a t i o n o f Energy P r o p e r t y o f
         Rxy
35   Ex = sum ( x .^2) ;
36   Ey = sum ( y .^2) ;
37   E = sqrt ( Ex * Ey ) ;
38   Mid = ceil ( length ( Rxy ) /2) ;
39   if ( E >= Rxy ( Mid ) ) then
40         disp ( ’ P r o p e r t y 2 : Energy P r o p e r t y o f C r o s s
                 Correlation verified ’)
41   end
42   subplot (2 ,1 ,1)
43   plot2d3 ( ’ gnn ’ ,n , x )
44   xlabel ( ’ n===> ’ )
45   ylabel ( ’ Amplitude −−> ’ )
46   title ( ’ I n p u t S e q u e n c e x [ n ] ’ )
47   subplot (2 ,1 ,2)
                                               22
48 plot2d3 ( ’ gnn ’ ,r , Rxy )
49 xlabel ( ’ n===> ’ )
50 ylabel ( ’ Amplitude −−> ’ )
51 title ( ’ C r o s s c o r r e l a t i o n S e q u e n c e Rxy [ n ] ’ )
52 // Example
53 // E n t e r t h e F i r s t i n p u t S e q u e n c e : = [ 1 , 2 , 1 , 1 ]
54 // E n t e r t h e s e c o n d i n p u t S e q u e n c e : = [ 1 , 1 , 2 , 1 ]
55 // E n t e r t h e l o w e r i n d e x o f f i r s t i n p u t s e q u e n c e :=0
56 // E n t e r t h e l o w e r i n d e x o f s e c o n d i n p u t s e q u e n c e :=0
57 // C r o s s C o r r e l a t i o n Rxy [ n ] : =
58 //           1.        4.         6.         6.        5.        2.          1.
59 // P r o p e r t y 1 : C r o s s C o r r e l a t i o n h a s AntiSymmetry : Rxy
       [ n ]=Ryx[−n ]
60 //
61 // P r o p e r t y 2 : Energy P r o p e r t y o f C r o s s C o r r e l a t i o n
       verified
                                             23
     Experiment: 6
     Solving a given difference
     equation.
     Scilab code Solution 6.1 Solving Difference Equation Direct Form II Re-
     alization
 1 // C a p t i o n : S o l v i n g D i f f e r e n c e E q u a t i o n
 2 // D i r e c t Form−I I R e a l i z a t i o n
 3 // F i n d i n g o u t t h e Output R e s p o n s e o f t h e          f i r s t order
 4 // s y s t e m ( F i l t e r )
 5 clc ;
 6 clear ;
 7 close ;
 8 x =
        [1 ,1/2 ,1/4 ,1/8 ,1/16 ,1/32 ,1/64 ,1/128 ,1/256 ,1/512];
 9   b = [3 , -4/3]; // n u m e r a t o r p o l y n o m i a l s
10   a = [1 , -1/3]; // d e n o m i n a t o r p o l y n o m i a l s
11   p = length ( a ) -1;
12   q = length ( b ) -1;
13   pq = max (p , q ) ;
14   a = a (2: p +1) ;
15   w = zeros (1 , pq ) ;
16   for i = 1: length ( x )
17     wnew = x ( i ) - sum ( w (1: p ) .* a ) ;
                                               24
18    w = [ wnew , w ];
19    y ( i ) = sum ( w (1: q +1) .* b ) ;
20 end
21 disp (y , ’ Output R e s p o n s e y [ n ]= ’ ) ;
22 // R e s u l t
23 // Output R e s p o n s e y [ n ]=
24 //        3.
25 //        1.1666667
26 //        0.4722222
27 //        0.1990741
28 //        0.0871914
29 //        0.0394805
30 //        0.0183685
31 //        0.0087270
32 //        0.0042111
33 //        0.0020547
                                          25
     Experiment: 7
     Computation of N point DFT
     of a given sequence and to plot
     magnitude and phase spectrum.
     Scilab code Solution 7.1 Program to find the spectral information of dis-
     crete time signal Calculation of DFT and IDFT
 1   // C a p t i o n : Program t o f i n d t h e s p e c t r a l i n f o r m a t i o n
         o f d i s c r e t e time     signal
 2   // C a l c u l a t i o n o f DFT and IDFT
 3   // P l o t t i n g Magnitude and Phase Spectrum
 4   clc ;
 5   close ;
 6   clear ;
 7   xn = input ( ’ E n t e r t h e r e a l i n p u t d i s c r e t e s e q u e n c e x
         [ n ]= ’ ) ;
 8   N = length ( xn ) ;
 9   XK = zeros (1 , N ) ;
10   IXK = zeros (1 , N ) ;
11   // Code b l o c k t o f i n d t h e DFT o f t h e S e q u e n c e
12   for K = 0: N -1
                                             26
     Figure 7.1: Program to find the spectral information of discrete time signal
     Calculation of DFT and IDFT
13         for n = 0: N -1
14             XK ( K +1) = XK ( K +1) + xn ( n +1) * exp ( - %i *2* %pi * K * n /
                   N);
15         end
16   end
17   [ phase , db ] = phasemag ( XK )
18   disp ( XK , ’ D i s c r e t e F o u r i e r T r a n s f o r m X( k )= ’ )
19   disp ( abs ( XK ) , ’ Magnitude S p e c t r a l S a m p l e s= ’ )
20   disp ( phase , ’ Phase S p e c t r a l S a m p l e s= ’ )
21   n = 0: N -1;
22   K = 0: N -1;
23   figure (1)
24   subplot (2 ,2 ,1)
25   a = gca () ;
26   a . x_location = ” o r i g i n ” ;
27   a . y_location = ” o r i g i n ” ;
28   plot2d3 ( ’ gnn ’ ,n , xn )
29   xlabel ( ’ Time I n d e x n−−−−> ’ )
                                                27
30   ylabel ( ’ A m p l i t u d e xn−−−−> ’ )
31   title ( ’ D i s c r e t e I n p u t S e q u e n c e ’ )
32   subplot (2 ,2 ,2)
33   a = gca () ;
34   a . x_location = ” o r i g i n ” ;
35   a . y_location = ” o r i g i n ” ;
36   plot2d3 ( ’ gnn ’ ,K , abs ( XK ) )
37   xlabel ( ’ F r e q u e n c y Sample I n d e x K−−−−> ’ )
38   ylabel ( ’ | X(K)|−−−−> ’ )
39   title ( ’ Magnitude Spectrum ’ )
40   subplot (2 ,2 ,3)
41   a = gca () ;
42   a . x_location = ” o r i g i n ” ;
43   a . y_location = ” o r i g i n ” ;
44   plot2d3 ( ’ gnn ’ ,K , phase )
45   xlabel ( ’ F r e q u e n c y Sample I n d e x K−−−−> ’ )
46   ylabel ( ’<X(K) i n r a d i a n s −−−−> ’ )
47   title ( ’ Phase Spectrum ’ )
48   // Code b l o c k t o f i n d t h e IDFT o f t h e s e q u e n c e
49   for n = 0: N -1
50         for K = 0: N -1
51                IXK ( n +1) = IXK ( n +1) + XK ( K +1) * exp ( %i *2* %pi * K * n
                       /N);
52         end
53   end
54   IXK = IXK / N ;
55   ixn = real ( IXK ) ;
56   subplot (2 ,2 ,4)
57   a = gca () ;
58   a . x_location = ” o r i g i n ” ;
59   a . y_location = ” o r i g i n ” ;
60   plot2d3 ( ’ gnn ’ ,[0: N -1] , ixn )
61   xlabel ( ’ D i s c r e t e Time I n d e x n −−−−> ’ )
62   ylabel ( ’ A m p l i t u d e x [ n]−−−−> ’ )
63   title ( ’ IDFT s e q u e n c e ’ )
64   // Example
65   //
66   // E n t e r t h e r e a l i n p u t d i s c r e t e s e q u e n c e x [ n
                                           28
        ]=[1 ,2 ,3 ,4]
67   //
68   // D i s c r e t e F o u r i e r T r a n s f o r m X( k )=
69   //
70   //       1 0 . − 2 . + 2 . i − 2 . − 9 . 7 9 7D−16 i − 2 . − 2 . i
71   //
72   // Magnitude S p e c t r a l S a m p l e s=
73   //
74   //       10.        2.8284271                 2.       2.8284271
75   //
76   // Phase S p e c t r a l S a m p l e s=
77   //
78   //       0.        135.          180.             225.
79   //
                                     29
     Experiment: 8
     Linear convolution of two
     sequences using DFT and
     IDFT.
     Scilab code Solution 8.1 Linear Convolution using Circular Convolution
     DFT IDFT method
 1   // C a p t i o n : L i n e a r C o n v o l u t i o n u s i n g C i r c u l a r
         Convolution
 2   //DFT−IDFT method
 3   clc ;
 4   clear ;
 5   close ;
 6   x = input ( ’ E n t e r t h e i n p u t d i s c r e t e s e q u e n c e := ’ )
 7   h = input ( ’ E n t e r t h e i m p u l s e d i s c r e t e s e q u e n c e := ’ )
 8   N1 = length ( x ) ;
 9   N2 = length ( h ) ;
10   N = N1 + N2 -1; // L i n e a r C o n v o l u t i o n r e s u l t l e n g t h
11   h = [h , zeros (1 ,N - N2 ) ];
12   x = [x , zeros (1 ,N - N1 ) ];
13   // Computing DFT−IDFT
                                              30
Figure 8.1: Linear Convolution using Circular Convolution DFT IDFT
method
                                31
14   XK = dft (x , -1) ; //N p o i n t DFT o f i / p s e q u e n c e
15   HK = dft (h , -1) ; //N p o i n t DFT o f i m p u l s e s e q u e n c e
16   // M u l t i p l i c a t i o n o f 2 DFT’ s
17   YK = XK .* HK ;
18   // L i n e a r C o n v o l u t i o n r e s u l t
19   yn = dft ( YK ,1) ; //IDFT o f Y(K) ( o / p s e q u e n c e )
20   disp ( real ( yn ) , ’ L i n e a r C o n v o l u t i o n r e s u l t y [ n ] : = ’ )
21   // Example
22   // E n t e r t h e i n p u t d i s c r e t e s e q u e n c e := [ 1 , 2 , 3 ]
23   // E n t e r t h e i m p u l s e d i s c r e t e s e q u e n c e : = [ 1 , 2 , 2 , 1 ]
24   // L i n e a r C o n v o l u t i o n r e s u l t y [ n ] : =
25   //
26   //         1.
27   //         4.
28   //         9.
29   //         11.
30   //         8.
31   //         3.
                                                 32
     Experiment: 9
     Circular convolution of two
     given sequences using DFT and
     IDFT
     Scilab code Solution 9.1 Circular Convolution using DFT IDFT method
 1   // C a p t i o n : C i r c u l a r C o n v o l u t i o n u s i n g DFT−IDFT
         method
 2   clc ;
 3   clear ;
 4   close ;
 5   L = 4; // Length o f t h e s e q u e n c e
 6   N = 4; //N−p o i n t DFT
 7   x1 = input ( ’ E n t e r t h e f i r s t d i s c r e t e s e q u e n c e : x1 [ n ]=
         ’)
 8   x2 = input ( ’ E n t e r t h e s e c o n d d i s c r e t e s e q u e n c e : x2 [ n
         ]= ’ )
 9   // Computing DFT
10   X1K = dft ( x1 , -1) ;
11   X2K = dft ( x2 , -1) ;
12   // M u l t i p l i c a t i o n o f 2 DFT’ s
13   X3K = X1K .* X2K ;
14   x3 = dft ( X3K ,1) ; //IDFT o f X3 (K)
                                              33
15 x3 = real ( x3 ) ;
16 disp ( x3 , ’ C i r c u l a r C o n v o l u t i o n r e s u l t : x3 [ n ]= ’ ) ;
17 // Example
18 // E n t e r t h e f i r s t d i s c r e t e s e q u e n c e : x1 [ n ]= [ 2 , 1 , 2 , 1 ]
19 // E n t e r t h e s e c o n d d i s c r e t e s e q u e n c e : x2 [ n ]=
         [1 ,2 ,3 ,4]
20   //
21   // C i r c u l a r C o n v o l u t i o n r e s u l t : x3 [ n ]=
22   //
23   //       14.
24   //       16.
25   //       14.
26   //       16.
                                                 34
     Experiment: 10
     Design and implementation of
     FIR filter to meet given
     specifications.
     Scilab code Solution 10.1 To Design an Low Pass FIR Filter
 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   clc ;
 3   clear ;
 4   close ;
 5   wp = input ( ’ E n t e r t h e p a s s band e d g e ( r a d )= ’ ) ;
 6   ws = input ( ’ E n t e r t h e s t o p band e d g e ( r a d )= ’ ) ;
 7   ks = input ( ’ E n t e r t h e s t o p band a t t e n u a t i o n ( dB )= ’ ) ;
 8   // I f 43<Ks<54 c h o o s e hamming window .
 9   //To s e l e c t N, o r d e r o f f i l t e r .
10   N = (2* %pi *4) ./( ws - wp ) ; // k=4 f o r Hamming window .
11   N = ceil ( N ) ; //To round− o f f N t o t h e n e x t i n t e g e r .
12   wc =( wp +( ws - wp ) /2) ./ %pi
13   // To o b t a i n FIR f i l t e r I m p u l s e R e s p o n s e ’ wft ’
14   //And FIR F i l t e r F r e q u e n c y r e s p o n s e ’ wfm ’
15   [ wft , wfm , fr ]= wfir ( ’ l p ’ ,N +1 ,[ wc /2 ,0] , ’hm ’ ,[0 ,0]) ;
                                           35
Figure 10.1: To Design an Low Pass FIR Filter
                     36
16   figure (1)
17   a = gca () ;
18   a . x_location = ” o r i g i n ” ;
19   a . y_location = ” o r i g i n ” ;
20   a . data_bounds = [0 , -150;1 ,50];
21   plot (2* fr ,20* log10 ( wfm ) , ’ r ’ )
22   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−−−> ’ )
23   ylabel ( ’ F r e q u e n c y R e s p o n s e i n dB H( jw )= ’ )
24   title ( ’ F r e q u e n c y R e s p o n s e o f FIR LPF ’ )
25   xgrid (1)
26   // R e s u l t
27   // E n t e r t h e p a s s band e d g e ( r a d )= 0 . 3 ∗ %pi
28   // E n t e r t h e s t o p band e d g e ( r a d )= 0 . 4 5 ∗ %pi
29   // E n t e r t h e s t o p band a t t e n u a t i o n ( dB )= 50
30   //N =               54.
31   //−−>wc
32   // wc =               0.375
33   //−−>d i s p ( wft , ’ I m p u l s e R e s p o n s e o f FIR LPF= ’)
34   // I m p u l s e R e s p o n s e o f FIR LPF=
35   //        column 1 t o 7
36   //        0.0003609 − 0.0007195 − 0.0010869                              1 . 5 7 5D
          −18           0.0016485           0.0015927 − 0.0010883
37   //        column 8 t o 14
38   // − 0 . 0 0 3 5 7 0 3 − 0 . 0 0 1 7 0 0 9             0.0038764
          0 . 0 0 6 1 8 9 6 − 5 . 9 6 5D−18 − 0 . 0 0 9 0 2 0 8 − 0 . 0 0 8 2 5 1 6
39   //        column 15 t o 21
40   //          0.0053105           0.0164428              0.0074408 −
          0.0162551 − 0.0251602                      1 . 1 9 1D−17       0.0359480
41   //        column 22 t o 28
42   //        0.0334760 − 0.0225187 − 0.0756838 −
          0.0394776             0.1111441            0.2931653           0.375
43   //        column 29 t o 35
44   //        0.2931653            0.1111441 − 0.0394776 −
          0.0756838 − 0.0225187                      0.0334760           0.0359480
45   //        column 36 t o 42
46   //        1 . 1 9 1D−17 − 0 . 0 2 5 1 6 0 2 − 0 . 0 1 6 2 5 5 1
          0.0074408             0.0164428            0.0053105 − 0.0082516
47   //        column 43 t o 49
                                              37
48   // − 0 . 0 0 9 0 2 0 8 − 5 . 9 6 5D−18       0.0061896
      0.0038764 − 0.0017009 − 0.0035703 − 0.0010883
       column 50 t o 55
49 //    0.0015927          0.0016485         1 . 5 7 5D−18 −
      0.0010869 − 0.0007195                0.0003609
                                38
     Experiment: 11
     Design and implementation of
     IIR filter to meet given
     specifications.
     Scilab code Solution 11.1 To obtain Digital IIR Butterworth low pass
     filter Frequency response
1    // C a p t i o n : To o b t a i n      D i g i t a l I I R B u t t e r w o r t h low
         pass f i l t e r
2    // F r e q u e n c y r e s p o n s e
3    clc ;
4    clear ;
5    close ;
6    fp = input ( ’ E n t e r t h e         p a s s band e d g e ( Hz ) = ’ ) ;
7    fs = input ( ’ E n t e r t h e         s t o p band e d g e ( Hz ) = ’ ) ;
8    kp = input ( ’ E n t e r t h e         p a s s band a t t e n u a t i o n ( dB ) = ’ )
         ;
9    ks = input ( ’ E n t e r t h e         s t o p band a t t e n u a t i o n ( dB ) = ’ )
         ;
10   Fs = input ( ’ E n t e r t h e         sampling rate            samples / sec = ’ )
         ;
                                                   39
Figure 11.1: To obtain Digital IIR Butterworth low pass filter Frequency
response
                                  40
11   d1 = 10^( kp /20) ;
12   d2 = 10^( ks /20) ;
13   d = sqrt ((1/( d2 ^2) ) -1) ;
14   E = sqrt ((1/( d1 ^2) ) -1) ;
15   // D i g i t a l f i l t e r s p e c i f i c a t i o n s ( r a d / s a m p l e s )
16   wp =2* %pi * fp *1/ Fs ;
17   ws =2* %pi * fs *1/ Fs ;
18   disp ( wp , ’ D i g i t a l P a s s band e d g e f r e q i n r a d / s a m p l e s
         wp= ’ )
19   disp ( ws , ’ D i g i t a l S t o p band e d g e f r e q i n r a d / s a m p l e s
         ws= ’ )
20   // Pre w a r p i n g
21   op =2* Fs * tan ( wp /2) ;
22   os =2* Fs * tan ( ws /2) ;
23   disp ( op , ’ Analog P a s s Band Edge Freq . i n r a d / s e c op= ’
         )
24   disp ( os , ’ Analog S t o p band Edge Freq . i n r a d / s e c o s= ’
         )
25   N = log10 ( d / E ) / log10 ( os / op ) ;
26   oc = op /(( E ^2) ^(1/(2* N ) ) ) ;
27   N = ceil ( N ) ; // r o u n d e d t o n e a r e s t i n t e g e r
28   disp (N , ’ I I R F i l t e r o r d e r N = ’ ) ;
29   disp ( oc , ’ C u t o f f F r e q u e n c y i n r a d / s e c o n d s OC = ’ )
30   [ pols , gn ] = zpbutt (N , oc ) ;
31   disp ( gn , ’ Gain o f Analog I I R B u t t e r w o r t h LPF Gain = ’ )
32   disp ( pols , ’ P o l e s o f Analog I I R B u t t e r w o r t h LPF P o l e s
          =’)
33   HS = poly ( gn , ’ s ’ , ’ c o e f f ’ ) / real ( poly ( pols , ’ s ’ ) ) ;
34   disp ( HS , ’ T r a n s f e r f u n c t i o n o f Ananlog I I R
         B u t t e r w o r t h LPF H( S )= ’ )
35   z = poly (0 , ’ z ’ )
36   Hz = horner ( HS ,(2* Fs *( z -1) /( z +1) ) )
37   num = coeff ( Hz (2) )
38   den = coeff ( Hz (3) )
39   Hz (2) = Hz (2) ./ den (3) ;
40   Hz (3) = Hz (3) ./ den (3) ;
41   disp ( Hz , ’ T r a n s f e r f u n c t i o n o f D i g i t l a I I R
         B u t t e r w o r t h LPF H( Z )= ’ )
                                             41
42 [ Hw , w ] = frmag ( Hz ,256) ;
43 figure (1)
44 plot (2* w * %pi ,20* log10 ( abs ( Hw ) ) ) ;
45 xlabel ( ’ D i g i t a l F r e q u e n c y w−−−> ’ )
46 ylabel ( ’ Magnitude i n dB 20 l o g | H(w) |= ’ )
47 title ( ’ Magnitude R e s p o n s e o f I I R LPF ’ )
48 xgrid (1)
49 // R e s u l t
50 // E n t e r t h e p a s s band e d g e ( Hz ) = 1 5 0 0
51 //
52 // E n t e r t h e s t o p band e d g e ( Hz ) = 2 0 0 0
53 //
54 // E n t e r t h e p a s s band a t t e n u a t i o n ( dB ) = −1
55 //
56 // E n t e r t h e s t o p band a t t e n u a t i o n ( dB ) = −3
57 //
58 // E n t e r t h e s a m p l i n g r a t e  samples / s e c = 8000
59 //
60 // D i g i t a l P a s s band e d g e f r e q i n r a d / s a m p l e s wp=
61 //
62 //         1.1780972
63 //
64 // D i g i t a l S t o p band e d g e f r e q i n r a d / s a m p l e s ws=
65 //
66 //         1.5707963
67 //
68 // Analog P a s s Band Edge Freq . i n r a d / s e c op=
69 //
70 //         10690.858
71 //
72 // Analog S t o p band Edge Freq . i n r a d / s e c o s=
73 //
74 //         16000.
75 //
76 // I I R F i l t e r o r d e r N =
77 //
78 //         2.
79 //
                                          42
 80   // C u t o f f F r e q u e n c y i n r a d / s e c o n d s OC =
 81   //
 82   //       16022.769
 83   //
 84   // Gain o f Analog I I R B u t t e r w o r t h LPF Gain =
 85   //
 86   //       2 . 5 6 7D+08
 87   //
 88   // P o l e s o f Analog I I R B u t t e r w o r t h LPF P o l e s =
 89   //
 90   // − 1 1 3 2 9 . 8 0 9 + 1 1 3 2 9 . 8 0 9 i − 1 1 3 2 9 . 8 0 9 −
         11329.809 i
 91   //
 92   // T r a n s f e r f u n c t i o n o f Ananlog I I R B u t t e r w o r t h LPF
         H( S )=
 93   //
 94   //                     2 . 5 6 7D+08
 95   //     −−−−−−−−−−−−−−−−−−−−−−−−−
 96   //                                                     2
 97   //       2 . 5 6 7D+08 + 2 2 6 5 9 . 6 1 8 s + s
 98   //
 99   // T r a n s f e r f u n c t i o n o f D i g i t l a I I R B u t t e r w o r t h LPF
         H( Z )=
100   //
101   //                                                                   2
102   //       0.2933099 + 0.5866197 z + 0.2933099 z
103   //     −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
104   //                                                          2
105   //               0.1715734 + 0.0016661 z + z
106   //
      Scilab code Solution 11.2 To obtain Digital IIR Chebyshev low pass filter
      Frequency response
                                               43
Figure 11.2: To obtain Digital IIR Chebyshev low pass filter Frequency re-
sponse
                                   44
1    // C a p t i o n : To o b t a i n D i g i t a l I I R Chebyshev low p a s s
         filter
2    // F r e q u e n c y r e s p o n s e
3    clc ;
4    clear ;
5    close ;
6    fp = input ( ’ E n t e r t h e p a s s band e d g e ( Hz ) = ’ ) ;
7    fs = input ( ’ E n t e r t h e s t o p band e d g e ( Hz ) = ’ ) ;
8    kp = input ( ’ E n t e r t h e p a s s band a t t e n u a t i o n ( dB ) = ’ )
         ;
9    ks = input ( ’ E n t e r t h e s t o p band a t t e n u a t i o n ( dB ) = ’ )
         ;
10   Fs = input ( ’ E n t e r t h e s a m p l i n g r a t e             samples / sec = ’ )
         ;
11   d1 = 10^( kp /20) ;
12   d2 = 10^( ks /20) ;
13   d = sqrt ((1/( d2 ^2) ) -1) ;
14   E = sqrt ((1/( d1 ^2) ) -1) ;
15   // D i g i t a l f i l t e r s p e c i f i c a t i o n s ( r a d / s a m p l e s )
16   wp =2* %pi * fp *1/ Fs ;
17   ws =2* %pi * fs *1/ Fs ;
18   disp ( wp , ’ D i g i t a l P a s s band e d g e f r e q i n r a d / s a m p l e s
         wp= ’ )
19   disp ( ws , ’ D i g i t a l S t o p band e d g e f r e q i n r a d / s a m p l e s
         ws= ’ )
20   // Pre w a r p i n g
21   op =2* Fs * tan ( wp /2) ;
22   os =2* Fs * tan ( ws /2) ;
23   disp ( op , ’ Analog P a s s Band Edge Freq . i n r a d / s e c op= ’
         )
24   disp ( os , ’ Analog S t o p band Edge Freq . i n r a d / s e c o s= ’
         )
25   N = acosh ( d / E ) / acosh ( os / op ) ;
26   oc = op /(( E ^2) ^(1/(2* N ) ) ) ;
27   N = ceil ( N ) ; // r o u n d e d t o n e a r e s t i n t e g e r
28   disp (N , ’ I I R F i l t e r o r d e r N = ’ ) ;
29   disp ( oc , ’ C u t o f f F r e q u e n c y i n r a d / s e c o n d s OC = ’ )
30   [ pols , gn ] = zpch1 (N ,E , op ) ;
                                               45
31   disp ( gn , ’ Gain o f Analog I I R Chebyshev Type−I LPF
         Gain = ’ )
32   disp ( pols , ’ P o l e s o f Analog I I R Chebyshev Type−I LPF
         Poles =’)
33   HS = poly ( gn , ’ s ’ , ’ c o e f f ’ ) / real ( poly ( pols , ’ s ’ ) ) ;
34   disp ( HS , ’ T r a n s f e r f u n c t i o n o f Ananlog I I R Chebyshev
         Type−I LPF H( S )= ’ )
35   z = poly (0 , ’ z ’ )
36   Hz = horner ( HS ,(2* Fs *( z -1) /( z +1) ) )
37   num = coeff ( Hz (2) )
38   den = coeff ( Hz (3) )
39   Hz (2) = Hz (2) ./ den (3) ;
40   Hz (3) = Hz (3) ./ den (3) ;
41   disp ( Hz , ’ T r a n s f e r f u n c t i o n o f D i g i t l a I I R Chebyshev
         LPF H( Z )= ’ )
42   [ Hw , w ] = frmag ( Hz ,256) ;
43   figure (1)
44   plot (2* w * %pi ,20* log10 ( abs ( Hw ) ) ) ;
45   xlabel ( ’ D i g i t a l F r e q u e n c y w−−−> ’ )
46   ylabel ( ’ Magnitude i n dB 20 l o g | H(w) |= ’ )
47   title ( ’ Magnitude R e s p o n s e o f I I R LPF ’ )
48   xgrid (1)
49   // R e s u l t
50   // E n t e r t h e p a s s band e d g e ( Hz ) = 1 5 0 0
51   //
52   // E n t e r t h e s t o p band e d g e ( Hz ) = 2 0 0 0
53   //
54   // E n t e r t h e p a s s band a t t e n u a t i o n ( dB ) = −1
55   //
56   // E n t e r t h e s t o p band a t t e n u a t i o n ( dB ) = −3
57   //
58   // E n t e r t h e s a m p l i n g r a t e    samples / s e c = 8000
59   //
60   // D i g i t a l P a s s band e d g e f r e q i n r a d / s a m p l e s wp=
61   //
62   //         1.1780972
63   //
64   // D i g i t a l S t o p band e d g e f r e q i n r a d / s a m p l e s ws=
                                            46
 65   //
 66   //        1.5707963
 67   //
 68   // Analog P a s s Band Edge Freq . i n r a d / s e c op=
 69   //
 70   //        10690.858
 71   //
 72   // Analog S t o p band Edge Freq . i n r a d / s e c o s=
 73   //
 74   //        16000.
 75   //
 76   // I I R F i l t e r o r d e r N =
 77   //
 78   //        2.
 79   //
 80   // C u t o f f F r e q u e n c y i n r a d / s e c o n d s OC =
 81   //
 82   //        17642.912
 83   //
 84   // Gain o f Analog I I R Chebyshev Type−I LPF Gain =
 85   //
 86   //        1 . 1 2 3D+08
 87   //
 88   // P o l e s o f Analog I I R Chebyshev Type−I LPF P o l e s =
 89   //
 90   // − 5 8 6 7 . 8 6 1 + 9 5 6 9 . 6 9 2 7 i − 5 8 6 7 . 8 6 1 − 9 5 6 9 . 6 9 2 7 i
 91   //
 92   // T r a n s f e r f u n c t i o n o f Ananlog I I R Chebyshev Type−I
           LPF H( S )=
 93   //
 94   //                       1 . 1 2 3D+08
 95   //       −−−−−−−−−−−−−−−−−−−−−−−−−
 96   //                                                       2
 97   //        1 . 2 6 0D+08 + 1 1 7 3 5 . 7 2 2 s + s
 98   //
 99   // T r a n s f e r f u n c t i o n o f D i g i t l a I I R Chebyshev LPF H(
         Z )=
100   //
                                              47
101   //                                       2
102   //   0.1971055 + 0.3942111 z + 0.1971055 z
103   //   −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
104   //                                   2
105   //       0.3409008 − 0.4562766 z + z
                               48
     Experiment: 12
     Circular convolution of two
     given sequences
     Scilab code Solution 12.1 Program to perform circular convolution of two
     sequences
 1   // C a p t i o n : Program t o p e r f o r m c i r c u l a r c o n v o l u t i o n
         o f two s e q u e n c e s
 2   clc ;
 3   clear ;
 4   close ;
 5   x1 = input ( ’ E n t e r t h e f i r s t d i s c r e t e s e q u e n c e := ’ )
 6   x2 = input ( ’ E n t e r t h e s e c o n d d i s c r e t e s e q u e n c e := ’ )
 7   m = length ( x1 ) ; // l e n g t h o f f i r s t s e q u e n c e
 8   n = length ( x2 ) ; // l e n g t h o f s e c o n d s e q u e n c e
 9   //To make l e n g t h o f x1 and x2 a r e e q u a l
10   if (m > n )
11         for i = n +1: m
12                  x2 ( i ) =0;
13         end
14   elseif (n > m )
15         for i = m +1: n
16                  x1 ( i ) =0;
17         end
                                              49
18 end
19 N = length ( x1 ) ;
20 x3 = zeros (1 , N ) ; // c i r c u l a r           convolution result
          i n i t i a l i z e d to zero
21   a (1) = x2 (1) ;
22   for j = 2: N
23          a ( j ) = x2 (N - j +2) ;
24   end
25   for i = 1: N
26          x3 (1) = x3 (1) + x1 ( i ) * a ( i ) ;
27   end
28   X (1 ,:) = a ;
29   // C a l c u l a t i o n o f c i r c u l a r c o n v o l u t i o n
30   for k =2: N
31          for j = 2: N
32                   x2 ( j ) = a (j -1) ;
33          end
34   x2 (1) = a ( N ) ;
35   X (k ,:) = x2 ;
36          for i = 1: N
37                   a ( i ) = x2 ( i ) ;
38                   x3 ( k ) = x3 ( k ) + x1 ( i ) * a ( i ) ;
39          end
40   end
41   disp ( x3 , ’ C i r c u l a r C o n v o l u t i o n R e s u l t x3 [ n ]= ’ )
42   // Example
43   // E n t e r t h e f i r s t d i s c r e t e s e q u e n c e := [ 2 , 1 , 2 , 1 ]
44   // E n t e r t h e s e c o n d d i s c r e t e s e q u e n c e := [ 1 , 2 , 3 , 4 ]
45   // C i r c u l a r C o n v o l u t i o n R e s u l t x3 [ n ]=
46   //          14.           16.        14.        16.
47   //
                                                 50