PLotting noisy signal matlab

8 ビュー (過去 30 日間)
T
T 2012 年 10 月 24 日
Suppose the sampling interval is pi/100.
t = 0:pi/100:40;
x = cos(pi/10*t)+0.5*randn(size(t));
plot(t,x)Then you know where pi/2, 3pi/4 etc are.
t(50) is pi/2 and x(50) is the signal value at t=pi/2
plot(t,x); hold on plot(t(50),x(50),'r^','markerfacecolor',[0 0 0],'markersize',10); plot(t(75),x(75),'r^','markerfacecolor',[0 0 0],'markersize',10); and so on.
Suppose t was a vector and for each element is the one that I want to plot, so for instance, t(1), t(2),..., and so on. How would you do this?

採用された回答

Wayne King
Wayne King 2012 年 10 月 24 日
編集済み: Wayne King 2012 年 10 月 24 日
What do you mean suppose t was a vector?
t = 0:pi/100:40;
x = cos(pi/10*t)+0.5*randn(size(t));
plot(t,x)
t is a vector in the above. So is x and you are plotting the vector x as a function of the vector t.
  1 件のコメント
T
T 2012 年 10 月 24 日
What if t(1) = 0.4, t(5) = 0.5, t(6)=0.6, ....and so on. If I only wanted to plot x at t(1), t(5),.... ,, how would you do this?
x(t(1)) won't give me that result.

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

その他の回答 (2 件)

Wayne King
Wayne King 2012 年 10 月 24 日
編集済み: Wayne King 2012 年 10 月 24 日
You can subset your vector, for example:
t = 0:.01:1-0.01;
x = cos(2*pi*10*t);
plot(t,x)
Now the spacing in my t vector is 0.01 seconds. What if I wanted to only plot at time intervals of 0.1 seconds? Since the sine wave has a frequency of 10 Hz, I'll get a constant function.
tnew = t(1:10:end);
xnew = x(1:10:end);
plot(tnew,xnew)
  1 件のコメント
T
T 2012 年 10 月 24 日
Sorry, I should have been less ideal. What if t(1) = 0.5235, t(2) = 0.6743, t(3)=.756 and so on?

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


Richard Zapor
Richard Zapor 2012 年 10 月 24 日
編集済み: Richard Zapor 2012 年 10 月 24 日
If you want a specific set of points a third vector can be created, v=[1 4 9 12]; The plot(t(v),x(v)) will only use the subset points.
If you desire time values not part of the original data set then use interp1. xi=[.5235 .6743 .756]; yi=interp1(t,x,xi);plot(xi,yi)
For markers: plot(t,x); hold on; plot(t(5:10:100),x(5:10:100),'r^','markerfacecolor',[0 0 0],'markersize',10);

カテゴリ

Help Center および File ExchangeConfigure Simulation Conditions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by