-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvolution.m
executable file
·56 lines (47 loc) · 1.01 KB
/
convolution.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
% Program to convolute x[n] with h[n] where x[n] = h[n] = u(n)-u(n-6)
clc; clear all
% u(n) UNIT Step Function
n = -5:0.01:15;
u = zeros(size(n));
u (n > 0) = 1;
figure('Name','Convolution','NumberTitle','off','Color','w')
subplot(2,2,1)
plot(n,u,'b'),grid on, grid minor
title('u(n)')
xlabel('Time')
ylabel('Amplitude')
% u(n-6) Unit Step function delayed 6 sec.
u6 = zeros(size(n));
u6 (n > 6) = 1;
subplot(2,2,2)
plot(n,u6,'r'),grid on, grid minor
title('u(n-6)')
xlabel('Time')
ylabel('Amplitude')
% x(n) = u(n) - u(n-6)
xn = u - u6;
hn = xn;
subplot(2,2,3)
plot(n,xn),grid on, grid minor
title('x[n] = h[n]')
xlabel('Time')
ylabel('Amplitude')
p = length(xn);
q = length(hn);
k = p+q-1;
N = linspace(-5,15,k);
conv = zeros(1,k);
for i=1:k
for j=1:p
if (i-j+1 < q && i-j+1 > 0)
conv(i) = conv(i) + xn(j)*hn(i-j+1);
end
end
end
%conv = conv(xn,hn);
subplot(2,2,4)
plot(N,conv,'b'),grid on, grid minor
title('x[n]*h[n]')
xlabel('Time')
ylabel('Amplitude')
print('-clipboard','-dbitmap')