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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by