Scilab Manual and Filter Design Codes, Study Guides, Projects, Research of Computer science

Information on downloading the Scilab Manual and codes for generating discrete signals, performing linear and circular convolution, designing FIR and IIR filters using various techniques, and sampling and verification of sampling. It includes Scilab code snippets for each experiment.

Typology: Study Guides, Projects, Research

2019/2020

Uploaded on 02/18/2020

mmk123
mmk123 🇮🇳

4 documents

1 / 47

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Scilab Manual for
Digital Signal Processing
by Prof R.Senthilkumar, Assistant Professor
Electronics Engineering
Institute of Road and Transport Technology1
Solutions provided by
Mr. R.Senthilkumar- Assistant Professor
Electronics Engineering
Institute of Road and Transport Technology
July 28, 2018
1Funded 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
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f

Partial preview of the text

Download Scilab Manual and Filter Design Codes and more Study Guides, Projects, Research Computer science in PDF only on Docsity!

Scilab Manual for

Digital Signal Processing

by Prof R.Senthilkumar, Assistant Professor

Electronics Engineering

Institute of Road and Transport Technology

Solutions provided by

Mr. R.Senthilkumar- Assistant Professor

Electronics Engineering

Institute of Road and Transport Technology

July 28, 2018

(^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

  • List of Scilab Solutions
  • 1 Generation of Discrete Signals
  • 2 Linear and Circular Convolution of two sequences
  • 3 Circular convolution using FFT
  • 4 Linear Convolution using Circular Convolution
  • 5 Calculation of FFT and IFFT of a sequence
  • 6 Time and Frequency Response of LTI systems
  • 7 Sampling, Verification of Sampling and Effect of aliasing
  • 8 Design of FIR Filters Window Design
  • 9 Design of FIR Filters Frequency Sampling
  • 10 Design of IIR Filters- Butterworth
  • 11 Design of IIR Filters Chebyshev
  • 12 Decimation by polyphase decomposition
  • 13 Periodogram based Spectral Estimation
  • Solution 1.1 Unit Sample Sequence List of Experiments
  • Solution 1.2 Unit Step Sequence
  • Solution 1.3 Discrete Ramp Sequence
  • Solution 1.4 Exponentially Decreasing Signal
  • Solution 1.5 Exponentially Increasing Signal
  • Solution 2.1 Program for Linear Convolution
  • Solution 2.2 Program to find the Cicrcular Convolution
  • method Solution 3.1 Performing Circular COnvolution Using DFT IDFT
  • volution Solution 4.1 Performing Linear Convolution using Circular Con-
  • Solution 5.5 Performing FFT and IFFT of a discrete sequence
  • Solution 6.1 Time and Frequency Response
  • Solution 7.1 Sampling and Reconstruction of a Signal
  • Solution 8.1 Program to Design FIR Low Pass Filter
  • Solution 8.2 rogram to Design FIR High Pass Filter
  • Solution 8.3 Program to Design FIR Band Pass Filter
  • Solution 8.4 Program to Design FIR Band Reject Filter
  • pling Technique Solution 9.1 Design of FIR LPF Filter using Frequecny Sam-
  • Solution 10.1 Digital IIR First Order Butterworth LPF Filter
  • Solution 10.2 HPF Using Digital Filter Transformation
  • Solution 10.3 BPF using Digital Transformation
  • Solution 10.4 BSF using Digital Transformation
  • Solution 11.1 To Design the Digtial Chebyshev IIR Filter
  • Solution 12.1 Design of Ployphase Decimator
  • Solution 13.1 Periodogram Estimate of Given Discrete Sequence
  • AP 1 sinc function

Experiment: 1

Generation of Discrete Signals

Scilab code Solution 1.1 Unit Sample Sequence

1 // C a p t i o n : U n i t Sample S e q u e n c e 2 clear ; 3 clc ; 4 close ; 5 L = 4; // U p p e r l i m i t 6 n = -L : L; 7 x = [ zeros (1 , L ) ,1 , zeros (1 , L ) ]; 8 b = gca () ; 9 b. y_location = ” m i d d l e ” ; 10 plot2d3 ( ’ gnn ’ ,n , x ) 11 a = gce () ; 12 a. children (1). thickness =4; 13 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 S e q u e n c e ’ , ’ n ’ , ’ x [ n ] ’ ) ;

Scilab code Solution 1.2 Unit Step Sequence

1 // C a p t i o n : U n i t S t e p S e q u e n c e

Scilab code Solution 1.4 Exponentially Decreasing Signal

1 // C a p t i o n : E x p o n e n t i a l l y D e c r e a s i n g S i g n a l 2 clear ; 3 clc ; 4 close ; 5 a =0.5; 6 n = 0:10; 7 x = ( a ) ^n ; 8 a = gca () ; 9 a. x_location = ” o r i g i n ” ; 10 a. y_location = ” o r i g i n ” ; 11 plot2d3 ( ’ gnn ’ ,n , x ) 12 a. thickness = 2; 13 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 l y D e c r e a s i n g S i g n a l ’ , ’ n ’ , ’ x [ n ] ’ ) ;

Scilab code Solution 1.5 Exponentially Increasing Signal

1 // C a p t i o n : 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 2 clear ; 3 clc ; 4 close ; 5 a =1.5; 6 n =1:10; 7 x = ( a ) ^n ; 8 a = gca () ; 9 a. thickness = 2; 10 plot2d3 ( ’ gnn ’ ,n , x ) 11 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 l y I n c r e a s i n g S i g n a l ’ , ’ n ’ , ’ x [ n ] ’ ) ;

Experiment: 2

Linear and Circular

Convolution of two sequences

Scilab code Solution 2.1 Program for Linear Convolution

1 // C a p t i o n : Program f o r L i n e a r C o n v o l u t i o n 2 clc ; 3 clear all ; 4 close ; 5 x = input ( ’ e n t e r x s e q ’ ) ; 6 h = input ( ’ e n t e r h s e q ’ ) ; 7 m = length ( x ) ; 8 n = length ( h ) ; 9 // Method 1 U s i n g D i r e c t C o n v o l u t i o n Sum Formula 10 for i = 1: n +m - 11 conv_sum = 0; 12 for j = 1: i 13 if ((( i - j +1) <= n ) &( j <= m ) ) 14 conv_sum = conv_sum + x ( j ) * h (i - j +1) ; 15 end ; 16 y ( i ) = conv_sum ; 17 end ; 18 end ; 19 disp (y ’, ’ C o n v o l u t i o n Sum u s i n g D i r e c t Formula Method

Scilab code Solution 2.2 Program to find the Cicrcular Convolution

1 // C a p t i o n : Program t o f i n d t h e C i c r c u l a r C o n v o l u t i o n o f g i v e n 2 // d i s c r e t e s e q u e n c e s u s i n g M a t r i x method 3 4 clear ; 5 clc ; 6 x1 = [2 ,1 ,2 ,1]; // F i r s t s e q u e n c e 7 x2 = [1 ,2 ,3 ,4]; // Se c o n d s e q u e n c e 8 m = length ( x1 ) ; // l e n g t h o f f i r s t s e q u e n c e 9 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 10 //To make l e n g t h o f x1 and x2 a r e Equal 11 if ( m >n ) 12 for i = n +1: m 13 x2 ( i ) = 0; 14 end 15 elseif (n > m ) 16 for i = m +1: n 17 x1 ( i) = 0; 18 end 19 end 20 N = length ( x1 ) ; 21 x3 = zeros (1 , N ) ; // 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 22 a (1) = x2 (1) ; 23 for j = 2: N 24 a ( j ) = x2 (N - j +2) ; 25 end 26 for i =1: N 27 x3 (1) = x3 (1) + x1 (i ) * a ( i ) ; 28 end 29 X (1 ,:) = a ; 30 // 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 31 for k = 2: N

32 for j =2: N 33 x2 ( j) = a (j -1) ; 34 end 35 x2 (1) = a ( N ) ; 36 X (k ,:) = x2 ; 37 for i = 1: N 38 a ( i ) = x2 ( i ) ; 39 x3 ( k) = x3 ( k ) + x1 ( i ) * a ( i ) ; 40 end 41 end 42 disp (X , ’ C i r c u l a r C o n v o l u t i o n M a t r i x x2 [ n ]= ’ ) 43 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 ] = ’ ) 44 // R e s u l t 45 // C i r c u l a r C o n v o l u t i o n M a t r i x x2 [ n ]= 46 // 47 // 1. 4. 3. 2. 48 // 2. 1. 4. 3. 49 // 3. 2. 1. 4. 50 // 4. 3. 2. 1. 51 // 52 // 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 ] = 53 // 54 // 1 4. 1 6. 1 4. 1 6.

20 // R e s u l t 21 // DFT o f x1 [ n ] i s X1 ( k )= 22 // 23 // 6. 0 2. 0 24 // 25 // DFT o f x1 [ n ] i s X2 ( k )= 26 // 27 // 1 0. − 2. + 2. i − 2. − 2. − 2. i 28 // 29 // DFT o f x3 [ n ] i s X3 ( k )= 30 // 31 // 6 0. 0 − 4. 0 32 // 33 // 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 ]= 34 // 35 // 1 4. 1 6. 1 4. 1 6.

Experiment: 4

Linear Convolution using

Circular Convolution

Scilab code Solution 4.1 Performing Linear Convolution using Circular Convolution

1 // C a p t i o n : P e r f o r m i n g 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 C o n v o l u t i o n 2 3 clear ; 4 clc ; 5 close ; 6 h = [1 ,2 ,3]; // I m p u l s e R e s p o n s e o f LTI System 7 x = [1 ,2 ,2 ,1]; // I n p u t R e s p o n s e o f LTI System 8 N1 = length ( x ) ; 9 N2 = length ( h ) ; 10 N = N1 + N2 - 11 disp (N , ’ Length o f Output R e s p o n s e y ( n ) ’ ) 12 // Padding z e r o s t o Make Length o f ’ h ’ and ’ x ’ 13 // Equal t o l e n g t h o f o u t p u t r e s p o n s e ’ y ’ 14 h1 = [h , zeros (1 ,N - N2 ) ]; 15 x1 = [x , zeros (1 ,N - N1 ) ]; 16 // Computing FFT 17 H = fft (h1 , -1) ;

Experiment: 5

Calculation of FFT and IFFT

of a sequence

Scilab code Solution 5.5 Performing FFT and IFFT of a discrete sequence

1 // C a p t i o n : P e r f o r m i n g FFT and IFFT o f a d i s c r e t e s e q u e n c e 2 clear ; 3 clc ; 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 x = [1 ,2 ,3 ,4]; 8 // Computing DFT 9 X = fft (x , -1) ; 10 disp (X , ’FFT o f x [ n ] i s X( k )= ’ ) 11 x = abs ( fft (X ,1) ) 12 disp (x , ’ IFFT o f X( k ) i s x [ n ]= ’ ) 13 // P l o t t i n g t h e s p e c t r u m o f D i s c r e t e S e q u e n c e 14 subplot (2 ,1 ,1) 15 a = gca () ; 16 a. data_bounds =[0 ,0;5 ,10]; 17 plot2d3 ( ’ gnn ’ ,0: length ( x ) -1 , x ) 18 b = gce () ;

19 b. children (1). thickness =3; 20 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 S e q u e n c e ’ , ’ n ’ , ’ x [ n ] ’ ) ; 21 subplot (2 ,1 ,2) 22 a = gce () ; 23 a. data_bounds =[0 ,0;5 ,10]; 24 plot2d3 ( ’ gnn ’ ,0: length ( X ) -1 , abs ( X ) ) 25 b = gce () ; 26 b. children (1). thickness =3; 27 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 Spectrum ’ , ’ k ’ , ’X( k ) ’ ) ; 28 // R e s u l t 29 //FFT o f x [ n ] i s X( k )= 30 // 31 // 1 0. − 2. + 2. i − 2. − 2. − 2. i 32 // 33 // IFFT o f X( k ) i s x [ n ]= 34 // 35 // 1. 2. 3. 4.

18 ylabel ( ’ h ( t ) ’ ) 19 title ( ’ I m p u l s e R e p s o n s e o f I s t Order L i n e a r C o n s t a n t C o e f f. D i f f e r e n t i a l Equ. ’ ) 20 // 21 // [ 2 ]. F i n d i n g F r e q u e n c y r e s p o n s e u s i n g C o n t i n u o u s Time F o u r i e r T r a n s f o r m 22 Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz 23 K = 4; 24 k = 0:( K /1000) : K ; 25 W = k * Wmax / K ; 26 HW = ht * exp ( - sqrt ( -1) t ’ W ) * Dt ; 27 HW_Mag = abs ( HW ) ; 28 W = [ - mtlb_fliplr (W ) , W (2:1001) ]; // Omega from − Wmax t o Wmax 29 HW_Mag = [ mtlb_fliplr ( HW_Mag ) , HW_Mag (2:1001) ]; 30 [ HW_Phase , db ] = phasemag ( HW ) ; 31 HW_Phase = [ - mtlb_fliplr ( HW_Phase ) , HW_Phase (2:1001) ]; 32 figure (2) 33 // P l o t t i n g Magnitude R e s p o n s e 34 subplot (2 ,1 ,1) ; 35 a = gca () ; 36 a. y_location = ” o r i g i n ” ; 37 plot (W , HW_Mag ) ; 38 xlabel ( ’ F r e q u e n c y i n R a d i a n s / S e c o n d s −−−> W’ ) ; 39 ylabel ( ’ a b s (H(jW) ) ’ ) 40 title ( ’ Magnitude R e s p o n s e ’ ) 41 // P l o t t i n g Phase Reponse 42 subplot (2 ,1 ,2) ; 43 a = gca () ; 44 a. y_location = ” o r i g i n ” ; 45 a. x_location = ” o r i g i n ” ; 46 plot (W , HW_Phase * %pi /180) ; 47 xlabel ( ’ F r e q u e n c y i n R a d i a n s / S e c o n d s −−−> W’ ) ; 48 ylabel ( ’ <H (jW) ’ )

49 title ( ’ Phase R e s p o n s e i n R a d i a n s ’ )