Is there a way to find the impulse response of the given system without using a loop?
6 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
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.
0 个评论
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!!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!