How to make convolution code without using conv

41 views (last 30 days)
건중 박
건중 박 on 18 May 2021
Edited: Matt J on 18 May 2021
I want to make convolution without using 'conv'. The code in below is that I did, and right side of a attached pic is result that I should make.
clc
clear
close all
t= -5:0.001:5;
x= (t>=0)&(t<=1);
h= (t>-2)&(t<0);
X=[x,zeros(1,length(t))];
H=[h,zeros(1,length(t))];
for i=1:length(t)
Y(i)=0;
for j=1:numel(t)
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
figure;
subplot(3,1,1);
plot(t,x);
xlabel('t');
ylabel('x(t)');
xlim([-5 5]);
ylim([-0.5 1.5]);
grid on;
subplot(3,1,2);
plot(t,h);
xlabel('t');
ylabel('h(t)');
xlim([-5 5]);
ylim([-0.5 1.5]);
grid on;
subplot(3,1,3);
plot(t,Y);
xlabel('t');
ylabel('y(t)');
xlim([-5 5]);
ylim([0 1000]);
grid on;

Answers (0)

Categories

Find more on Sparse Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!