Convolution of two Gaussian functions without conv
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Correlation and Convolution dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

