How on earth to graph discrete time signals?
52 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/733084/image.jpeg)
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?
0 个评论
采纳的回答
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')
figure(2);
stem(n, x, '-b', 'filled')
That sometimes makes more sense when plotting discrete values.
..
3 个评论
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)
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]
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!