Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Am I implementing the convolutional integral correctly?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello all,
Actually, I am trying to calculate the convolutional integral of two functions using the following code:
close all;
clear all;
clc;
%set time vector
t = linspace(0,85,16384);
T0=60;
alpha=1;
beta=0.1;
%construct the first part of the convolution
for i=1:size(t,2)
if(t(i)<=T0)
y(i)=alpha/1.5;
else
y(i)=(alpha+beta*(t(i)-T0))/1.5;
end
end
%plot the first function of the convolution
figure;
plot(t,y,'linewidth',2);
ylim([-1 3.5]);
set(gca,'fontsize',14,'fontweight','bold');
grid on;
xlabel('t');
ylabel('y(t)');
title('First function of the convolution');
%second part of the convolution
for i=1:size(t,2)
f2(i) = 0.08787*exp(-((t(i)-63.08)/1.593).^2);
end
%plot the second function of the convolution
figure;
plot(t,f2,'linewidth',2);
legend('f2')
xlim([50 85]);
set(gca,'fontsize',14,'fontweight','bold');
grid on;
xlabel('t');
ylabel('f2(t)');
title('Second function of the convolution');
%compute the convolution using matlab function
z2 = median(diff(t))*conv(y,f2,'same');
%plot the matlab convolution
figure;
plot(t,z2,'linewidth',3);
legend('f2*y')
grid on;
xlabel('t');
ylabel('y_*f');
title('Result of the convolution');
hold on;
The first and second part of my convolutional integral are as follows:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/275335/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/275336/image.jpeg)
and the result of the convolution is as follows:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/275337/image.jpeg)
But the strange point is that both of my functions (y and f2) are constant until t=60 but the result of the convolution starts from t=20. I don't know what's wrong with my implementation. Does anyone have any idea regarding my code? Am I implementing the convolutional integral correctly?
댓글 수: 0
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!