Convolution of two Gaussian functions without conv
Ältere Kommentare anzeigen
I am attempting to perform the convolution of two Gaussian functions, x and h, without using conv and then comparing that with the convolution solved by the built-in conv. I'm stuck setting the parameter for z and the x-axis for the two plots. Below is what I have come up with. Any help would be appreciated!
c1 = 1;
s1 = 1;
c2 = 1;
s2 = 1;
z = %%????
x = exp(-(z-c1).^2/(2*s1.^2));
h = exp(-(z-c2).^2/(2*s2.^2));
y = my_convolution(x, h);
figure;
plot(???,y)
comp = conv(x, h, 'same');
figure;
plot(???,comp)
function y = my_convolution(x, h)
M = length(x);
N = length(h);
X = [x, zeros(1, N)];
H = [h, zeros(1, M)];
for i = 1 : M + N -1
y(i) = 0;
for j = 1:M
if (j < i + 1)
y(i) = y(i) + X(j)*H(i - j + 1);
else
end
end
end
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Correlation and Convolution finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

