When I try to plot the convolution, i get an error stating that the vectors must be the same length.
7 次查看(过去 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!