Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
83 views

Lab 6: Convolution Dee, Furc Lab 6: Convolution

This document discusses different methods of convolution including continuous-time (CT) convolution and discrete-time (DT) convolution. It provides MATLAB code examples to calculate convolution and plot the results. Specifically, it shows CT convolution using numerical convolution to calculate y(t)=h(t)*x(t). It then demonstrates various DT convolution examples, including shifting the inputs, calculating convolution where one input is a ramp function, and convolving signals where one is an unit impulse.

Uploaded by

saran gul
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Lab 6: Convolution Dee, Furc Lab 6: Convolution

This document discusses different methods of convolution including continuous-time (CT) convolution and discrete-time (DT) convolution. It provides MATLAB code examples to calculate convolution and plot the results. Specifically, it shows CT convolution using numerical convolution to calculate y(t)=h(t)*x(t). It then demonstrates various DT convolution examples, including shifting the inputs, calculating convolution where one input is a ramp function, and convolving signals where one is an unit impulse.

Uploaded by

saran gul
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab 6: Convolution DEE, FURC

Lab 6: Convolution

3.1) CT-Convolution

%numerical convolution for y(t)=h(t)*x(t)

%x(t)=tu(t)
%h(t)=e^-t*u(t)
t=0:0.01:1
h=exp(-t)
x=t
y=0.01*conv(h,x)
plot(t,y(1:101),'o')
axis([0,1,0,0.4])
xlabel('time,seconds')
ylabel('y(n)')
title('CT-convolution')
grid

Another method is as below:

t=0:0.01:1
t1=1
h=exp(-t).*stepfun(t,0)
%we can omit the step function here since the t0=0
x=t.*stepfun(t,0)
y=0.01*conv(h,x)
length_output=length(x)+length(h)-1
k=linspace(0,2*t1,length_output)
plot(k,y)
axis([0,1,0,0.4])

Page 1
Lab 6: Convolution DEE, FURC

3.2) DT-Convolution

3.2.1) Tutorial question 2.1

x[ n]   [n]  2 [ n  1]   [ n  3]
h[ n]  2 [ n  1]  2 [ n  1]

a) y1[n]=x[n]*h[n]

% from n=-3 to n=3


%so the length is 3-(-3)+1 = 7 points
x = [0 0 0 1 2 0 -1];
h = [0 0 2 0 2 0 0];

y1 = conv(h,x);
t = -6:1:6; %-3*2 :1 :3*2
figure(1);
subplot(2,1,1)
stem(t,y1);
xlabel('n')
ylabel('y1')
grid;

b) y2[n]=x[n+2]*h[n]

%shift x by 2 to the left


x = [0 1 2 0 -1 0 0];
h = [0 0 2 0 2 0 0];

y2 = conv(h,x);
t = -6:1:6;
subplot(2,2,3)
stem(t,y2);
xlabel('n')
ylabel('y2')
grid;

c) y3[n]=x[n]*h[n+2]

%shift h by 2 to the left


x = [0 0 0 1 2 0 -1];
h = [2 0 2 0 0 0 0];

y3 = conv(h,x);
t = -6:1:6;
subplot(2,2,4)
stem(t,y3);
xlabel('n')
ylabel('y3')
grid;

Page 2
Lab 6: Convolution DEE, FURC

3.2.2) Tutorial question 2.4


1 3n8
x[n] 
0 otherwise

1 4  n  15
h[n] 
0 otherwise

%convolution for y(n)


t1 = 3:1:15;
x = [1 1 1 1 1 1 0 0 0 0 0 0 0];
figure(1);
subplot(2,2,1)
stem(t1,x);
xlabel('n');
ylabel('x[n]');
title('input');
grid
h = [0 1 1 1 1 1 1 1 1 1 1 1 1];
subplot(2,2,2)
stem(t1,h);
xlabel('n');
ylabel('h[n]');
title('impulse response');
grid
y = conv(x,h);
t = 6:1:30;
subplot(2,1,2)
stem(t,y);
xlabel('n');
ylabel('y[n]');
title('convolution');
text(20,5,'y[n]=x[n]*h[n]')
grid;

Page 3
Lab 6: Convolution DEE, FURC

Page 4
Lab 6: Convolution DEE, FURC

3.4) Ramp-Function

%d(t)=2.5[(t-4)u(t-4)-2(t-6)u(t-6)+(t-8)u(t-8)]
t = 0:1:10
x1= t-4
u1=stepfun(t,4)
d1=x1.*u1
x2= t-6
u2=stepfun(t,6)
d2=x2.*u2
x3= t-8
u3=stepfun(t,8)
d3=x3.*u3
d=2.5*(d1-2*d2+d3)
figure(1)
plot(t,d)
axis([0,10,-2,8])
grid

Page 5
Lab 6: Convolution DEE, FURC

3.5)DT-convolution

%h[n]=(4^n)u(2-n)
%x[n]=((-1/2)^n)u(n-4)
%y[n]=conv(h,x)
n=-10:10
x1=(-1/2).^n
u1=stepfun(n,4) %can also use u1=(n-4)>=0
x=x1.*u1
h1=(4).^n
u2=stepfun(2,n) %can also use u2=(2-n)>=0
h=h1.*u2
y=conv(x,h)
length_output=length(x)+length(h)-1
k=linspace(2*-10,2*10,length_output)
figure(1)
clf
subplot(2,2,1)
stem(n,h,'filled')
xlabel('n')
ylabel('h[n]')
title('unit impulse')
grid
subplot(2,2,2)
stem(n,x,'filled')
xlabel('n')
ylabel('x[n]')
title('input')
grid
subplot(2,1,2)
stem(k,y)
xlabel('n')
ylabel('y[n]')
title('output')
grid

Page 6

You might also like