Digital Signal Processing using Matlab 5.3
     <<Home  Lab 3                 
   

Convolution                                                                                                                                

                                                                                                                                                  

Example 1                                                                                                                                  

 From the file menu, open a new m file.

 Type the following MATLAB program

 Save this file with extension m (eg. dsp1.m)

 Return to command window and type "dsp1" (name of the saved file) and enter

 Enter the requested data as

 a= [-2 0 1 -1 3]

 b= [1 2  0 -1]

 Solution                                                                                                                                    

     a = input('Type in the first sequence = ');

     b = input('Type in the second sequence = ');

     c = conv(a,b)

     M = length(c)-1;

     n=0:1:M;

     disp("Out put sequence = "); disp(c)

     stem(n,c)

     xlabel('Time Index n')

     ylabel('Amplitude')  

 Result                                                                                                                                       

Out put sequence = 

c = -2   -4   1   3    1     5     1    -3               

                

Convolution                                                                                                                                

                                                                                                                                                  

Exercise 1                                                                                                                                  

 Repeat example 1 with

a = [1 2 1 -1]

b = [1 2 3 1]

Result                                                                                                                                        

 Out put sequence = 

c = 1     4     8     8    3     -2    -1            

                     

Signal y[n] is expanding and z[n] is not expanding (and found symmetry in +ve and -ve direction).

Impulse response                                                                                                                        

                                                                                                                                                  

Example 2a                                                                                                                                 

 Find impulse response and step response of the following LTI system:

 y[n] + 0.7y[n-1] - 0.45y[n-2] - 0.6y[n-3] = 0.8x[n] - 0.44x[n-1] + 0.36x[n-2] + 0.02x[n-3]

 Solution                                                                                                                                    

p=[0.8 -0.44 0.36 0.02];

d=[1 0.7 -0.45 -0.6];

N=41;

x=[1 zeros(1 ,N-1)];

y=filter(p,d,x);

k=0:1:N-1;

stem(k,y)

xlabel('Time Index n')

ylabel('Amplitude')

Result                                                                                                                                        

              

Step response                                                                                                                             

                                                                                                                                                  

Example 2b                                                                                                                                

 To determine the step response replace in the above program the statement x=[1 zeros(1 ,N-1)] with x=[ones(1,N)].

 Solution                                                                                                                                    

     p=[0.8 -0.44 0.36 0.02];

d=[1 0.7 -0.45 -0.6];

N=41;

x=[ones(1,N)];

y=filter(p,d,x);

k=0:1:N-1;

stem(k,y)

xlabel('Time Index n')

ylabel('Amplitude')

Result                                                                                                                                        

               

Unit ramp response                                                                                                                     

                                                                                                                                                  

Exercise 2a                                                                                                                                 

 Determine and sketch unit ramp response of the system given in example 2, i.e.

y[n] + 0.7y[n-1] - 0.45y[n-2] - 0.6y[n-3] = 0.8x[n] - 0.44x[n-1] + 0.36x[n-2] + 0.02x[n-3]

 Solution                                                                                                                                    

     p=[0.8 -0.44 0.36 0.02];

d=[1 0.7 -0.45 -0.6];

n=0:1:7;

y=filter(p,d,n);

stem(n,y)

xlabel('Time Index n')

ylabel('Amplitude')

Result                                                                                                                                        

                      

Impulse & Step response                                                                                                            

                                                                                                                                                  

Exercise 2b                                                                                                                                

 Sketch the impulse and step response of the system described by the difference equation:

y[n] =  0.7y[n-1] - 0.1y[n-2] + 2x[n] - x[n-2]

 Solution                                                                                                                                    

     %Unit Response

p=[2 0 -1];

d=[1 -0.7 0.1];

N=41;

x=[1 zeros(1 ,N-1)];

y=filter(p,d,x);

k=0:1:N-1;

stem(k,y)

xlabel('Time Index n')

ylabel('Amplitude')

%Step Response

q=[2 0 -1];

e=[1 -0.7 0.1];

M=41;

xx=[ones(1 ,M)];

yy=filter(q,e,xx);

n=0:1:M-1;

figure,stem(n,yy)

xlabel('Time Index n')

ylabel('Amplitude')

Result                                                                                                                                        

Impulse response              

              

Step response 

              

Impulse  response                                                                                                                       

                                                                                                                                                  

Exercise 2c                                                                                                                                 

 Sketch the response of the system characterized by the impulse response h[n] = (1/2)nu[n] to the input signal.

            1  0<=n<=10

x[n] =

            0  otherwise

 Solution                                                                                                                                    

     n=0:1:10;

x = (1/2).^n;

m=ones(1,10);

y=conv(x,m)

l = length(y)-1;

n=0:1:l;

stem(n,y)

Result                                                                                                                                        

                 

 HELP                                                                                                                                       

 CONV                                                                                                                                     

 CONV Convolution and polynomial multiplication.
C = CONV(A, B) convolves vectors A and B. The resulting vector is length LENGTH(A)+LENGTH(B)-1.
If A and B are vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials.

 LENGTH                                                                                                                                  

  LENGTH Length of vector.
LENGTH(X) returns the length of vector X. It is equivalent to MAX(SIZE(X)) for non-empty arrays and 0 for empty ones.

 FILTER                                                                                                                                    

 FILTER One-dimensional digital filter.
Y = FILTER(B,A,X) filters the data in vector X with the filter described by vectors A and B to create the filtered data Y. The filter is a "Direct Form II Transposed" implementation of the standard difference equation:
a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
- a(2)*y(n-1) - ... - a(na+1)*y(n-na)

If a(1) is not equal to 1, FILTER normalizes the filter coefficients by a(1).

When X is a matrix, FILTER operates on the columns of X. When X is an N-D array, FILTER operates along the first non-singleton dimension.

[Y,Zf] = FILTER(B,A,X,Zi) gives access to initial and final conditions, Zi and Zf, of the delays. Zi is a vector of length MAX(LENGTH(A),LENGTH(B))-1 or an array of such vectors, one for each column of X.

 ONES                                                                                                                                      

 ONES Ones array.
ONES(N) is an N-by-N matrix of ones.
ONES(M,N) or ONES([M,N]) is an M-by-N matrix of ones.
ONES(M,N,P,...) or ONES([M N P ...]) is an M-by-N-by-P-by-... array of ones.
ONES(SIZE(A)) is the same size as A and all ones.

 ZEROS                                                                                                                                     

 ZEROS Zeros array.
ZEROS(N) is an N-by-N matrix of zeros.
ZEROS(M,N) or ZEROS([M,N]) is an M-by-N matrix of zeros.
ZEROS(M,N,P,...) or ZEROS([M N P ...]) is an M-by-N-by-P-by-... array of zeros.
ZEROS(SIZE(A)) is the same size as A and all zeros.


DSP Lab 1   DSP Lab2   DSP Lab 3   DSP Lab4   DSP Lab 5   DSP Lab 6   DSP Lab7  DSP Lab8  DSP Lab9  DSP Lab10    Other material


   
 
                                                                                                                   <<Home
  
Ziauddin Siddiqui, B02ME CSN 07, Mehran University Of Engineering & Technology
Jamshoro, Sindh.
Email. [email protected]

1