How on earth to graph discrete time signals?

7 次查看(过去 30 天)
I'm trying to plot this discrete time function in MATLAB. I missed the last several of my classes due to sickness and as such have quite literally no idea what I'm doing. This is as far as I've gotten-
n = -5:1:5;
x = ((1 / 7) ^ -n) * heaviside(-n) + ((2 / 3) ^ n) * heaviside(n) + ((3/5) ^ n) * heaviside(n);
figure(1);
plot(t,y, '-b')
axis( [-1 10 0 1]);
This has been slowly cobbled together from other forum posts, and as such I don't understand it and it doesn't work. I'm pretty quickly running out of things to try. Any help?

采纳的回答

Star Strider
Star Strider 2021-9-8
The only problems were in not using element-wise operations (use the ‘dot operator’ with the exponentiation an d multiplication operators), and presenting the correct arguments to plot. With those corrections (the only ones I made to the posted code), the original code works. See Array vs. Matrix Operations to understand about element-wise operations.
n = -5:1:5;
x = ((1 / 7) .^ -n) .* heaviside(-n) + ((2 / 3) .^ n) .* heaviside(n) + ((3/5) .^ n) .* heaviside(n);
figure(1);
plot(n, x, '-b')
Another way to plot this is to use the stem fucntion —
figure(2);
stem(n, x, '-b', 'filled')
That sometimes makes more sense when plotting discrete values.
..
  3 个评论
Star Strider
Star Strider 2021-9-8
Thank you!
(For the record, I’m a physician. That’s what we do!)
.
Paul
Paul 2021-9-8
编辑:Paul 2021-9-8
One needs to be careful using the heaviside() function for discrete time problems. Unless the sympref is changed from the default, we see that
heaviside(0)
ans = 0.5000
Consequently, the code returns 1.5 at n=0.
n = -5:1:5;
x = ((1 / 7) .^ -n) .* heaviside(-n) + ((2 / 3) .^ n) .* heaviside(n) + ((3/5) .^ n) .* heaviside(n);
[n;x]
ans = 2×11
-5.0000 -4.0000 -3.0000 -2.0000 -1.0000 0 1.0000 2.0000 3.0000 4.0000 5.0000 0.0001 0.0004 0.0029 0.0204 0.1429 1.5000 1.2667 0.8044 0.5123 0.3271 0.2094
However, it's possible, perhaps even likely, that @Alex Miller's course uses the typical convention (at least in signals and controls) that u[0] = 1, in which case the result should be x[0] = 3. In either case, beware of using the heaviside() function for discrete time problems; make sure that heavisde(0) is consistent with the definition of the unit step function in the problem statement.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by