Write a MATLAB program to sketch the following discrete-time signals in the time range of –10 ≤ n ≤ 10. Please label all the graph axes clearly. If the sequence is complex, plot the magnitude and angle separately. i) x(n) = u(n) – u(n – 3)

375 vues (au cours des 30 derniers jours)
n=-10:10;
u(1:21)=ones(1,21); %creates a unit step sequence for u(n)
%how to write a delayed version of sequence i.e for u(n-3) ?

Réponses (4)

Aliya Patel
Aliya Patel le 23 Nov 2018
Modifié(e) : DGM le 4 Nov 2023
t = (-10:1:10)'; %%Can change the interval time by replacing 1 with 0.1
step1 = t>=0; %% For u[n]
step2 = t>=3; %%For u[n-3]
x = step1-step2;
plot(t,x) %%scatter can be used instead of plot
xlabel('time');
ylabel('amplitude');
title('x(n)=u(n)-u(n-3)');
  2 commentaires
Satadru Mukherjee
Satadru Mukherjee le 21 Mar 2020
This is wrong , your code is not taking care of the time index :-/
DGM
DGM le 4 Nov 2023
Modifié(e) : DGM le 4 Nov 2023
Indexing looks fine, but representing this using plot() is visually misleading. I suspect that motivation is why Aliya suggested scatter(), though I think stem() would probably be better.

Connectez-vous pour commenter.


Satadru Mukherjee
Satadru Mukherjee le 21 Mar 2020
Modifié(e) : Satadru Mukherjee le 21 Mar 2020
n1=-10:10;
x=(n1>=0);
n2=n1+3;
y=x;
u=min(min(n1),min(n2));
t=max(max(n1),max(n2));
r=u:1:t;
z1=[];
temp=1;
for i=1:length(r)
if(r(i)<min(n1) || r(i)>max(n1))
z1=[z1 0];
else
z1=[z1 x(temp)];
temp=temp+1;
end
end
z2=[];
temp=1;
for i=1:length(r)
if(r(i)<min(n2) || r(i)>max(n2))
z2=[z2 0];
else
z2=[z2 y(temp)];
temp=temp+1;
end
end
z=z1-z2;
subplot(3,1,1);
stem(r,z1);
xlabel('Time sample');
ylabel('Amplitude');
title('First signal');
subplot(3,1,2);
stem(r,z2);
xlabel('Time sample');
ylabel('Amplitude');
title('Second signal');
subplot(3,1,3);
stem(r,z);
xlabel('Time sample');
ylabel('Amplitude');
title('Signal after Subtraction');
  3 commentaires
Walter Roberson
Walter Roberson le 16 Mai 2020
It appends x(temp) to the end of z1. They wrote the code using that technique because people tend to learn the [] concatenation before they gain the experience to initialize an array to full size and write at a particular in the array.
Bhargav Jyoti Saikia
Bhargav Jyoti Saikia le 27 Mar 2021
Thank you very much. This program gave a clear idea as to how to implement these functions. Took little time to understand but after little debugging got the idea. There might be easier way or easier to understand simple method to achieve the same functionality.

Connectez-vous pour commenter.


Roman Mia
Roman Mia le 22 Fév 2023
n=-10:10;
u=[zeros(1,13), ones(1, 8)];
stem(n,u);

Jyothi
Jyothi le 24 Avr 2024 à 17:20
DGM a ajouté un drapeau à réponse

import numpy as np import matplotlib.pyplot as plt

  1. Define the range of n n = np.arange(0, 11)
  1. Calculate the exponential signal signal = np.exp(-0.1 * n)
  1. Plot the signal plt.stem(n, signal, use_line_collection=True) plt.xlabel('n') plt.ylabel('e^(-0.1n)') plt.title('Discrete Exponential Signal e^(-0.1n)') plt.grid(True) plt.show()
  1 commentaire
Walter Roberson
Walter Roberson le 24 Avr 2024 à 21:50
This appears to be python code, but MATLAB was being asked about rather than Python.
The python code does not appear to answer the question that was asked.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by