Why do I receive Vectors must be the same length error in this code?

1 回表示 (過去 30 日間)
ADLINA AZWEEN JOHANIS
ADLINA AZWEEN JOHANIS 2022 年 1 月 23 日
コメント済み: Ive J 2022 年 1 月 23 日
t=-1:0.01:5;
f=(5*cos(pi*t)).*((t>=0)-(t>=1)); %input signal f(t)
h=1.5*((t>=0)-(t>=1.5)-1*((t>=2)-(t>=2.5))); % LTI system impulse response h(t)
t1=-1:5:length(y)
y= conv(f,h); %output signal y(t)
figure(1)
%plotting input signal f(t)
subplot(3,1,1)
plot(t,f)
%plotting impulse response of LTI h(t)
subplot(3,1,2)
plot(t,h)
%plotting output signal y(t)
subplot(3,1,3)
plot(t1,y)

回答 (1 件)

Ive J
Ive J 2022 年 1 月 23 日
編集済み: Ive J 2022 年 1 月 23 日
Error is very obvious: y and t1 don't have the same length. Try this
t1 = linspace(1, max(y), length(y));
plot(t1, y)
  2 件のコメント
ADLINA AZWEEN JOHANIS
ADLINA AZWEEN JOHANIS 2022 年 1 月 23 日
do you know if Iits normal for the amplitude of the convolution signal to be different from what we calculate manually.
Ive J
Ive J 2022 年 1 月 23 日
I'm not familiar with that, but conv(u, v) returns a vector of length numel(u) + numel(v) - 1

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by