Convolution of rect pulses with impulses

조회 수: 12 (최근 30일)
Hakan Durak
Hakan Durak 2021년 6월 24일
편집: Arthi Sathyamurthi 2021년 7월 27일
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)

답변 (1개)

Arthi Sathyamurthi
Arthi Sathyamurthi 2021년 7월 27일
편집: Arthi Sathyamurthi 2021년 7월 27일
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);

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by