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

3 vues (au cours des 30 derniers jours)
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

Réponses (2)

Ram Sreekar
Ram Sreekar le 26 Juin 2023
Modifié(e) : Ram Sreekar le 26 Juin 2023
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 le 26 Juin 2023
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!!

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by