- You evaluate x(t) only at a single point t=Ts. You're supposed to evaluate at many sampling times, t, spaced apart by Ts.
- You haven't summed over n.
- You will make life easier on yourself (and on us, and on your graders) if you define T, Ts, and t in your code the same way as the homework exercise defines them. Instead, your code changes T to t.
Help with plotting triangular wave
3 ビュー (過去 30 日間)
古いコメントを表示
Hi guys. I am struggling with a homework question.
*A triangular wave with period T may be written as: 1/(2n+1)^2 * cos((2n+1)*w0*t) (this is a series, n starts at 0 and goes on until infinity). where w0 = 2pi/T. This wave form is sampled, with a sampling time of TS = T/200, to yield the sampled signal x(n).
Use MATLAB to demonstrate how the series converges to the triangular wave.
Generate a plot(properly labelled) with 6, 10 and 30 terms for a value of T = 2.*
The code i inputted into matlab is
t=2; Ts=t/200; w=(2*pi)/t; n=0:9999; x=((2*n+1).^-2).*(cos((2*n+1)*w*Ts)); plot(x)
When i plot this it doesn't give a triangular wave. I must have done something wrong or missed a detail. Any help would be appreciated.
Thank you very much
0 件のコメント
回答 (1 件)
Matt J
2012 年 12 月 29 日
編集済み: Matt J
2012 年 12 月 29 日
6 件のコメント
Image Analyst
2013 年 1 月 1 日
Try it like this:
n=0;
T=2;
Ts=T/200;
t=-T/2 : Ts : T/2;
w=(2*pi)/T;
s = 0;
figure;
maxTerms = 6; % also use 10 and 30
for n = 0 : maxTerms - 1
s = s + ((2*n+1)^-2) * (cos((2*n+1)*w*t));
end
% Make wave start at 0
s = s - s(1);
plot(t,s)
grid on;
hold on;
maxTerms = 10;
for n = 0 : maxTerms - 1
s = s + ((2*n+1)^-2) * (cos((2*n+1)*w*t));
end
% Make wave start at 0
s = s - s(1);
plot(t,s)
maxTerms = 30;
for n = 0 : maxTerms - 1
s = s + ((2*n+1)^-2) * (cos((2*n+1)*w*t));
end
% Make wave start at 0
s = s - s(1);
plot(t,s)
Matt J
2013 年 1 月 1 日
編集済み: Matt J
2013 年 1 月 1 日
Using this code i do get a triangular wave but when i plot for n=10,30 terms the graph doesn't really change much.
Looks fine to me. The difference between nmax=10 and nmax=30 is subtle, but I still do see a noticeable sharpening of the triangle. At some point, i.e., as convergence occurs, it is supposed to stop changing. visibly
参考
カテゴリ
Help Center および File Exchange で Pie Charts についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!