When I try to plot the convolution, i get an error stating that the vectors must be the same length.
조회 수: 5 (최근 30일)
이전 댓글 표시
close all
clear
clc
t=0:0.01:8;
% Input Signals
x=exp(-t).*(cos(3*t)-sin(3*t)).* heaviside(t); % Signal X(t). Not that the heavyside function was used rather than the function "us"
y=2*rectpuls(t-1,4); % Signal Y
z=exp(-1.5*t);
w=ur(t)-2*ur(t-1)+ur(t-2);
v=0.75*heaviside(t+0.5)+0.75*heaviside(t-0.5)-1.5*heaviside(t-3.5);
% Convolution
c1=conv(x,z);
c2=conv(y,c1);
c3=conv(w,x);
c4=conv(v,c3);
% Results
plot(t,c1)
댓글 수: 0
답변 (2개)
Walter Roberson
2018년 3월 29일
conv() does not preserve sizes by default. You need to use one of the options such as 'same'
댓글 수: 0
Abraham Boayue
2018년 3월 29일
The length of the output signal that results from the convolution of two input signals is equal to the sum of the lengths of the two input signals minus one. y = conv (x, h); Ny = Nx + Nh - 1; Use this segment of code to fix the problem with your code.
Nc1 = length(x)+length(z)-1;
tc1 = t(1):(t(end)-t(1))/(Nc1-1):t(end);
plot(tc1,c1,'linewidth',1.5,'color','m')
a = title('convolution of x and z');
Nc1 = length(x)+length(z)-1;
tc1 = t(1):(t(end)-t(1))/(Nc1-1):t(end);
plot(tc1,c1,'linewidth',1.5,'color','m')
a = title('convolution of x and z');
set(a,'fontsize',15);
a = xlabel('tc1');
set(a,'fontsize',15);
a = ylabel('c1');
set(a,'fontsize',15);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!