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

22 ビュー (過去 30 日間)
sharad kale
sharad kale 2014 年 4 月 29 日
コメント済み: Paul 2024 年 6 月 10 日
plz include steps so that i will be able to do it properly.
  1 件のコメント
José-Luis
José-Luis 2014 年 4 月 29 日
And why should anyone do YOUR work? Do you have any specific question?

サインインしてコメントする。

回答 (1 件)

Kautuk Raj
Kautuk Raj 2023 年 6 月 2 日
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 件のコメント
Paul
Paul 2024 年 6 月 10 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDigital Filtering についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by