Borrar filtros
Borrar filtros

how do i plot the following signal in matlab? x(n)=4u(n)​-u(n-1)-u(​n-2)-2u(n-​3)

28 visualizaciones (últimos 30 días)
sharad kale
sharad kale el 29 de Abr. de 2014
Comentada: Paul el 10 de Jun. de 2024
plz include steps so that i will be able to do it properly.

Respuestas (1)

Kautuk Raj
Kautuk Raj el 2 de Jun. de 2023
To plot the signal x(n) = 4u(n) - u(n-1) - u(n-2) - 2u(n-3) in MATLAB, we can first define the signal as a function of n, and then use the stem function to create a stem plot of the signal. The MATLAB code for doing this:
% Define the signal x(n)
n = 0:10;
x = 4*heaviside(n) - heaviside(n-1) - heaviside(n-2) - 2*heaviside(n-3);
% Create a stem plot of the signal
stem(n, x);
% Add axis labels and a title to the plot
xlabel('n');
ylabel('x(n)');
title('Plot of x(n) = 4u(n) - u(n-1) - u(n-2) - 2u(n-3)');
The obtained plot looks like:
  1 comentario
Paul
Paul el 10 de Jun. de 2024
This answer is incorrect if using the standard definition of the discrete time unit step u[n] where u[0] = 1 because with the default sympref we have
heaviside(0)
ans = 0.5000
which is why the plot shows, for example, y[0] = 2 instead of the correct answer y[0] = 4.
Either change the sympref or define the discrete-time unit step as an anonymous function
u = @(n) double(n>=0);
n = 0:10;
x = 4*u(n) - u(n-1) - u(n-2) - 2*u(n-3);
% Create a stem plot of the signal
stem(n, x);
axis padded

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by