When I try to plot the convolution, i get an error stating that the vectors must be the same length.

6 Ansichten (letzte 30 Tage)
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)

Antworten (2)

Walter Roberson
Walter Roberson am 29 Mär. 2018
conv() does not preserve sizes by default. You need to use one of the options such as 'same'

Abraham Boayue
Abraham Boayue am 29 Mär. 2018
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);

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by