Convolution of rect pulses with impulses

13 views (last 30 days)
Hakan Durak
Hakan Durak on 24 Jun 2021
Edited: Arthi Sathyamurthi on 27 Jul 2021
Hello friends i want to implement this scheme below but seems like i do something wrong cause i get wrong output.
can you help me what do i do wrong.
thanks in advance
Ts is 1, tau is 0.5s.
Ts=1;
fs=1/Ts;
fsample=100;
Tsample=1/fsample;
t=-5: Tsample :5; % time vector
y=zeros(size(t));
y(1:fsample/fs:end)=1;
h=heaviside(t+0.25)-heaviside(t-0.25);
s=conv(y,h);
plot(linspace(-5,5,length(s)),s)
x=exp(-t).*heaviside(t);
v=s*x;
plot(linspace(0,5,length(v)),v)

Answers (1)

Arthi Sathyamurthi
Arthi Sathyamurthi on 27 Jul 2021
Edited: Arthi Sathyamurthi on 27 Jul 2021
The error “Incorrect dimensions for matrix multiplication” obtained from simulating your code occurs when the two matrices have dimensions that cannot be multiplied. Click on this link to know more about the error.
Use the following code to resolve your error and to obtain the output as intended. Replace the last 3 lines of your code with the following code
x=exp(-t).*heaviside(t);
ts = -5: Tsample/2 :5; % time vector with equal number of data points as the variable s
x_interpolated = interp1(t,x,ts); % Interpolate x to have equal number of data points as s
plot(x_interpolated);
v=s.*x_interpolated; % The .* ensures each bit is multiplied correspondingly
plot(linspace(0,5,length(v)),v);

Community Treasure Hunt

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

Start Hunting!