Afka
Afka

Reputation: 33

Matlab convolutions (Dimension Mismatch Error)

I have to use matlab to find the convolution over the range 0 <= n <= 20.

x[n] = δ[n] + δ[n-2] and h[n] = 2*(3^n)u[n]

I have tried to do this and i was met with a "X is not the same length as Y" when trying to plot it and have tried to correct it. Could someone let me know if this is correct?

 n = [0:20];
 x =[1 0 1];
 h= 2*3.^n;
 y = conv(x,h);
 ysize = size(y,2)
 z = [0:(ysize-1)];
 ysize = size (y,2);
 p = stem(z ,y ,'r' ,'filled');
 set (p, 'LineWidth', 2, 'MarkerSize', 4);
 title ('y[n] = x[n] * h[n]');
 xlabel ('n');
 ylabel ('y[n]');

Upvotes: 3

Views: 72

Answers (1)

Hassan Saqib
Hassan Saqib

Reputation: 2787

I have tested your code. And it is giving the following output (no error of size) Code is perfect.enter image description here

I calculated the convolution online that results the same. Your code is perfect.

enter image description here

Upvotes: 1

Related Questions