ploting discrete singnal using heaviside

17 ビュー (過去 30 日間)
irtaza anwar
irtaza anwar 2015 年 4 月 12 日
コメント済み: Star Strider 2015 年 4 月 12 日
n = -5 : 5;
y = heaviside(n); stem(n, y) axis([-5 5 -1 2])
i am writing this code but it gives 0.5 on 0 and for n>0 gives 1

採用された回答

Star Strider
Star Strider 2015 年 4 月 12 日
That is the definition of the heaviside function.
From the documentation:
  • heaviside(x) returns the value 0 for x < 0, 1 for x > 0, and 1/2 for x = 0.
  2 件のコメント
irtaza anwar
irtaza anwar 2015 年 4 月 12 日
so how to plot unit step discrete graph for n=-5:5
Star Strider
Star Strider 2015 年 4 月 12 日
I thought you just did that in the code you posted:
n = -5 : 5;
y = heaviside(n);
stem(n, y)
axis([-5 5 -1 2])
That produces the plot I would expect.
You can define the unit step function as:
x = [-5 : 5];
unit_step = @(x) (x >= 0);
figure(2)
stem(x, unit_step(x))
That is not the definition of the Heaviside function, but is an acceptable definition for the unit step function. Use the one that is most appropriate for your needs.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by