How on earth to graph discrete time signals?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alex Miller
am 8 Sep. 2021
Bearbeitet: Paul
am 8 Sep. 2021
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 Kommentare
Akzeptierte Antwort
Star Strider
am 8 Sep. 2021
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 Kommentare
Paul
am 8 Sep. 2021
Bearbeitet: Paul
am 8 Sep. 2021
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu String Parsing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!