Dear all,
I have this piece of code I wrote to plot two signals – x(t) and h(t) – alongside their time range then find the convolution of the two signals.
It works fine with a step size of 1. Howerver, when I try to change the step size – to have better graphs, I get an error in the vectors dimensions. Hence, I can't plot the graphs.
fs = 1; % Sampling rate - step size
x = [2*((-2:1)+2).^2 18*1.^(2:3) -9*((4:5)-5)]; % x(t) function
tx1 = -2; tx2 = 5; tx = tx1:fs:tx2; % time for function x
h = [3*(0:2) -6*((3:4)-3)]; % h(t) function
th1 = 0; th2 = 4; th = th1:fs:th2; % time for function h
figure(1)subplot(2,1,1); plot(tx,x); title('x(t)');subplot(2,1,2); plot(th,h); title('h(t)');t = ((tx1+th1):fs:(tx2+th2)); % time for function yc (conv)
yc = conv(x,h); % Continuous convolution
figure(2)subplot(2,1,1); stem(yc); xlabel('--->n'); ylabel('y(n)'); title('Discrete Convolution');subplot(2,1,2); plot(t,yc); xlabel('t'); ylabel('y(t)'); title('Continuous Convolution');
When I change fs to 0.1, I get this error. Is there a way to solve this issue?
Error using plotVectors must be the same length.
Thanks in advance for your answers.
Best Answer