フィルターのクリア

Is there a way to find the impulse response of the given system without using a loop?

2 ビュー (過去 30 日間)
Akash knrs
Akash knrs 2023 年 6 月 26 日
回答済み: Mahesh Chilla 2023 年 6 月 26 日
Is it possible to modify this code so that it would work without using any loop for the given system.
%y[n] = 1/3(x[n]-x[n-3])
y = zeros(1,21);
for i = 1:1:21
if i <= 3
y(i) = x(i)*(1/3);
else
y(i) = (x(i)-x(i-3))*(1/3);
end
end

回答 (2 件)

Ram Sreekar
Ram Sreekar 2023 年 6 月 26 日
編集済み: Ram Sreekar 2023 年 6 月 26 日
Hi Akash knrs,
It is possible to calculate y without using a loop. You can refer to the example code given below.
% Consider,
x = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21];
y = zeros(1,21);
y(1:3) = x(1:3) * (1/3);
y(4:end) = (x(4:end) - x(1:end-3)) * (1/3);
Hope this helps you resolve your query.

Mahesh Chilla
Mahesh Chilla 2023 年 6 月 26 日
Hi Akash!
Assuming that the array "x" is the unit impulse. To solve this, you can create an array of "x" which is shifted by 3 units to the right.
The following code will solve this
n = 1:21 ; %defining an interval
x = (n==0) ; % unit impulse
x3 = (n==3) ; % unit impulse shifted by 3 units to the right
y = (x-x3)/3 ;
To learn more about the functions used in the code, refer the MATLAB's documentation.
  • https://www.mathworks.com/help/signal/gs/impulse-step-and-ramp-functions.html
Hope this helps,
Thank you!!

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by